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:
Doordashcon
2022-08-18 10:30:46 +01:00
committed by GitHub
parent 511e5c9651
commit d46f6f0d34
50 changed files with 465 additions and 309 deletions
+21 -10
View File
@@ -45,7 +45,7 @@ use frame_system::{self as system};
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{Dispatchable, Hash, Saturating, TrailingZeroInput, Zero},
traits::{Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero},
DispatchResult,
};
use sp_std::prelude::*;
@@ -58,6 +58,8 @@ type CallHashOf<T> = <<T as Config>::CallHasher as Hash>::Output;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
/// The parameters under which a particular account has a proxy relationship with some other
/// account.
#[derive(
@@ -204,11 +206,12 @@ pub mod pallet {
})]
pub fn proxy(
origin: OriginFor<T>,
real: T::AccountId,
real: AccountIdLookupOf<T>,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Config>::Call>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let real = T::Lookup::lookup(real)?;
let def = Self::find_proxy(&real, &who, force_proxy_type)?;
ensure!(def.delay.is_zero(), Error::<T>::Unannounced);
@@ -233,11 +236,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::add_proxy(T::MaxProxies::get()))]
pub fn add_proxy(
origin: OriginFor<T>,
delegate: T::AccountId,
delegate: AccountIdLookupOf<T>,
proxy_type: T::ProxyType,
delay: T::BlockNumber,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
Self::add_proxy_delegate(&who, delegate, proxy_type, delay)
}
@@ -255,11 +259,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_proxy(T::MaxProxies::get()))]
pub fn remove_proxy(
origin: OriginFor<T>,
delegate: T::AccountId,
delegate: AccountIdLookupOf<T>,
proxy_type: T::ProxyType,
delay: T::BlockNumber,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
Self::remove_proxy_delegate(&who, delegate, proxy_type, delay)
}
@@ -359,13 +364,14 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::kill_anonymous(T::MaxProxies::get()))]
pub fn kill_anonymous(
origin: OriginFor<T>,
spawner: T::AccountId,
spawner: AccountIdLookupOf<T>,
proxy_type: T::ProxyType,
index: u16,
#[pallet::compact] height: T::BlockNumber,
#[pallet::compact] ext_index: u32,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let spawner = T::Lookup::lookup(spawner)?;
let when = (height, ext_index);
let proxy = Self::anonymous_account(&spawner, &proxy_type, index, Some(when));
@@ -401,10 +407,11 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::announce(T::MaxPending::get(), T::MaxProxies::get()))]
pub fn announce(
origin: OriginFor<T>,
real: T::AccountId,
real: AccountIdLookupOf<T>,
call_hash: CallHashOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let real = T::Lookup::lookup(real)?;
Proxies::<T>::get(&real)
.0
.into_iter()
@@ -458,10 +465,11 @@ pub mod pallet {
))]
pub fn remove_announcement(
origin: OriginFor<T>,
real: T::AccountId,
real: AccountIdLookupOf<T>,
call_hash: CallHashOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let real = T::Lookup::lookup(real)?;
Self::edit_announcements(&who, |ann| ann.real != real || ann.call_hash != call_hash)?;
Ok(())
@@ -489,10 +497,11 @@ pub mod pallet {
))]
pub fn reject_announcement(
origin: OriginFor<T>,
delegate: T::AccountId,
delegate: AccountIdLookupOf<T>,
call_hash: CallHashOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
Self::edit_announcements(&delegate, |ann| {
ann.real != who || ann.call_hash != call_hash
})?;
@@ -527,12 +536,14 @@ pub mod pallet {
})]
pub fn proxy_announced(
origin: OriginFor<T>,
delegate: T::AccountId,
real: T::AccountId,
delegate: AccountIdLookupOf<T>,
real: AccountIdLookupOf<T>,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Config>::Call>,
) -> DispatchResult {
ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
let real = T::Lookup::lookup(real)?;
let def = Self::find_proxy(&real, &delegate, force_proxy_type)?;
let call_hash = T::CallHasher::hash_of(&call);