mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Replace T::AccountId with <T::Lookup as StaticLookup>::Source (#11670)
* initial * update * update * update * cargo fmt * update * update benchmarks * AccountIdLookupOf<T> * cargo fmt * fix conflits * cargo fmt * update Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -106,22 +106,25 @@ benchmarks! {
|
||||
as_recovered {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let recovered_account: T::AccountId = account("recovered_account", 0, SEED);
|
||||
let recovered_account_lookup = T::Lookup::unlookup(recovered_account.clone());
|
||||
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
|
||||
|
||||
Proxy::<T>::insert(&caller, &recovered_account);
|
||||
}: _(
|
||||
RawOrigin::Signed(caller),
|
||||
recovered_account,
|
||||
recovered_account_lookup,
|
||||
Box::new(call)
|
||||
)
|
||||
|
||||
set_recovered {
|
||||
let lost: T::AccountId = whitelisted_caller();
|
||||
let lost_lookup = T::Lookup::unlookup(lost.clone());
|
||||
let rescuer: T::AccountId = whitelisted_caller();
|
||||
let rescuer_lookup = T::Lookup::unlookup(rescuer.clone());
|
||||
}: _(
|
||||
RawOrigin::Root,
|
||||
lost.clone(),
|
||||
rescuer.clone()
|
||||
lost_lookup,
|
||||
rescuer_lookup
|
||||
) verify {
|
||||
assert_last_event::<T>(
|
||||
Event::AccountRecovered {
|
||||
@@ -153,11 +156,12 @@ benchmarks! {
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let lost_account: T::AccountId = account("lost_account", 0, SEED);
|
||||
let lost_account_lookup = T::Lookup::unlookup(lost_account.clone());
|
||||
|
||||
insert_recovery_account::<T>(&caller, &lost_account);
|
||||
}: _(
|
||||
RawOrigin::Signed(caller.clone()),
|
||||
lost_account.clone()
|
||||
lost_account_lookup
|
||||
) verify {
|
||||
assert_last_event::<T>(
|
||||
Event::RecoveryInitiated {
|
||||
@@ -172,7 +176,10 @@ benchmarks! {
|
||||
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let lost_account: T::AccountId = account("lost_account", 0, SEED);
|
||||
let lost_account_lookup = T::Lookup::unlookup(lost_account.clone());
|
||||
let rescuer_account: T::AccountId = account("rescuer_account", 0, SEED);
|
||||
let rescuer_account_lookup = T::Lookup::unlookup(rescuer_account.clone());
|
||||
|
||||
|
||||
// Create friends
|
||||
let friends = add_caller_and_generate_friends::<T>(caller.clone(), n);
|
||||
@@ -206,8 +213,8 @@ benchmarks! {
|
||||
|
||||
}: _(
|
||||
RawOrigin::Signed(caller.clone()),
|
||||
lost_account.clone(),
|
||||
rescuer_account.clone()
|
||||
lost_account_lookup,
|
||||
rescuer_account_lookup
|
||||
) verify {
|
||||
assert_last_event::<T>(
|
||||
Event::RecoveryVouched {
|
||||
@@ -223,6 +230,7 @@ benchmarks! {
|
||||
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let lost_account: T::AccountId = account("lost_account", 0, SEED);
|
||||
let lost_account_lookup = T::Lookup::unlookup(lost_account.clone());
|
||||
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -257,7 +265,7 @@ benchmarks! {
|
||||
<ActiveRecoveries<T>>::insert(&lost_account, &caller, recovery_status);
|
||||
}: _(
|
||||
RawOrigin::Signed(caller.clone()),
|
||||
lost_account.clone()
|
||||
lost_account_lookup
|
||||
) verify {
|
||||
assert_last_event::<T>(
|
||||
Event::AccountRecovered {
|
||||
@@ -270,6 +278,7 @@ benchmarks! {
|
||||
close_recovery {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let rescuer_account: T::AccountId = account("rescuer_account", 0, SEED);
|
||||
let rescuer_account_lookup = T::Lookup::unlookup(rescuer_account.clone());
|
||||
|
||||
let n in 1 .. T::MaxFriends::get();
|
||||
|
||||
@@ -307,7 +316,7 @@ benchmarks! {
|
||||
<ActiveRecoveries<T>>::insert(&caller, &rescuer_account, recovery_status);
|
||||
}: _(
|
||||
RawOrigin::Signed(caller.clone()),
|
||||
rescuer_account.clone()
|
||||
rescuer_account_lookup
|
||||
) verify {
|
||||
assert_last_event::<T>(
|
||||
Event::RecoveryClosed {
|
||||
@@ -356,6 +365,7 @@ benchmarks! {
|
||||
cancel_recovered {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let account: T::AccountId = account("account", 0, SEED);
|
||||
let account_lookup = T::Lookup::unlookup(account.clone());
|
||||
|
||||
frame_system::Pallet::<T>::inc_providers(&caller);
|
||||
|
||||
@@ -364,7 +374,7 @@ benchmarks! {
|
||||
Proxy::<T>::insert(&caller, &account);
|
||||
}: _(
|
||||
RawOrigin::Signed(caller),
|
||||
account
|
||||
account_lookup
|
||||
)
|
||||
|
||||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion};
|
||||
use sp_runtime::traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use frame_support::{
|
||||
@@ -182,6 +182,7 @@ type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
type FriendsOf<T> = BoundedVec<<T as frame_system::Config>::AccountId, <T as Config>::MaxFriends>;
|
||||
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
|
||||
|
||||
/// An active recovery process.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
@@ -382,10 +383,11 @@ pub mod pallet {
|
||||
)})]
|
||||
pub fn as_recovered(
|
||||
origin: OriginFor<T>,
|
||||
account: T::AccountId,
|
||||
account: AccountIdLookupOf<T>,
|
||||
call: Box<<T as Config>::Call>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check `who` is allowed to make a call on behalf of `account`
|
||||
let target = Self::proxy(&who).ok_or(Error::<T>::NotAllowed)?;
|
||||
ensure!(target == account, Error::<T>::NotAllowed);
|
||||
@@ -405,10 +407,12 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::set_recovered())]
|
||||
pub fn set_recovered(
|
||||
origin: OriginFor<T>,
|
||||
lost: T::AccountId,
|
||||
rescuer: T::AccountId,
|
||||
lost: AccountIdLookupOf<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
let lost = T::Lookup::lookup(lost)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Create the recovery storage item.
|
||||
<Proxy<T>>::insert(&rescuer, &lost);
|
||||
Self::deposit_event(Event::<T>::AccountRecovered {
|
||||
@@ -486,8 +490,12 @@ pub mod pallet {
|
||||
/// - `account`: The lost account that you want to recover. This account needs to be
|
||||
/// recoverable (i.e. have a recovery configuration).
|
||||
#[pallet::weight(T::WeightInfo::initiate_recovery())]
|
||||
pub fn initiate_recovery(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn initiate_recovery(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check that the account is recoverable
|
||||
ensure!(<Recoverable<T>>::contains_key(&account), Error::<T>::NotRecoverable);
|
||||
// Check that the recovery process has not already been started
|
||||
@@ -528,10 +536,12 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::vouch_recovery(T::MaxFriends::get()))]
|
||||
pub fn vouch_recovery(
|
||||
origin: OriginFor<T>,
|
||||
lost: T::AccountId,
|
||||
rescuer: T::AccountId,
|
||||
lost: AccountIdLookupOf<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let lost = T::Lookup::lookup(lost)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Get the recovery configuration for the lost account.
|
||||
let recovery_config = Self::recovery_config(&lost).ok_or(Error::<T>::NotRecoverable)?;
|
||||
// Get the active recovery process for the rescuer.
|
||||
@@ -567,8 +577,12 @@ pub mod pallet {
|
||||
/// - `account`: The lost account that you want to claim has been successfully recovered by
|
||||
/// you.
|
||||
#[pallet::weight(T::WeightInfo::claim_recovery(T::MaxFriends::get()))]
|
||||
pub fn claim_recovery(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn claim_recovery(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Get the recovery configuration for the lost account
|
||||
let recovery_config =
|
||||
Self::recovery_config(&account).ok_or(Error::<T>::NotRecoverable)?;
|
||||
@@ -610,8 +624,12 @@ pub mod pallet {
|
||||
/// Parameters:
|
||||
/// - `rescuer`: The account trying to rescue this recoverable account.
|
||||
#[pallet::weight(T::WeightInfo::close_recovery(T::MaxFriends::get()))]
|
||||
pub fn close_recovery(origin: OriginFor<T>, rescuer: T::AccountId) -> DispatchResult {
|
||||
pub fn close_recovery(
|
||||
origin: OriginFor<T>,
|
||||
rescuer: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let rescuer = T::Lookup::lookup(rescuer)?;
|
||||
// Take the active recovery process started by the rescuer for this account.
|
||||
let active_recovery =
|
||||
<ActiveRecoveries<T>>::take(&who, &rescuer).ok_or(Error::<T>::NotStarted)?;
|
||||
@@ -665,8 +683,12 @@ pub mod pallet {
|
||||
/// Parameters:
|
||||
/// - `account`: The recovered account you are able to call on-behalf-of.
|
||||
#[pallet::weight(T::WeightInfo::cancel_recovered())]
|
||||
pub fn cancel_recovered(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
|
||||
pub fn cancel_recovered(
|
||||
origin: OriginFor<T>,
|
||||
account: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let account = T::Lookup::lookup(account)?;
|
||||
// Check `who` is allowed to make a call on behalf of `account`
|
||||
ensure!(Self::proxy(&who) == Some(account), Error::<T>::NotAllowed);
|
||||
Proxy::<T>::remove(&who);
|
||||
|
||||
Reference in New Issue
Block a user