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 -11
View File
@@ -51,6 +51,7 @@ fn add_announcements<T: Config>(
maybe_real: Option<T::AccountId>,
) -> Result<(), &'static str> {
let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED));
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
let real = if let Some(real) = maybe_real {
real
@@ -59,16 +60,17 @@ fn add_announcements<T: Config>(
T::Currency::make_free_balance_be(&real, BalanceOf::<T>::max_value() / 2u32.into());
Proxy::<T>::add_proxy(
RawOrigin::Signed(real.clone()).into(),
caller.clone(),
caller_lookup,
T::ProxyType::default(),
T::BlockNumber::zero(),
)?;
real
};
let real_lookup = T::Lookup::unlookup(real);
for _ in 0..n {
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
real_lookup.clone(),
T::CallHasher::hash_of(&("add_announcement", n)),
)?;
}
@@ -83,8 +85,9 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real);
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
}: _(RawOrigin::Signed(caller), real_lookup, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
@@ -95,17 +98,19 @@ benchmarks! {
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("anonymous", 0, SEED);
let delegate: T::AccountId = account("target", p - 1, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
T::Currency::make_free_balance_be(&delegate, BalanceOf::<T>::max_value() / 2u32.into());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real);
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
Proxy::<T>::announce(
RawOrigin::Signed(delegate.clone()).into(),
real.clone(),
real_lookup.clone(),
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(a, Some(delegate.clone()), None)?;
}: _(RawOrigin::Signed(caller), delegate, real, Some(T::ProxyType::default()), Box::new(call))
}: _(RawOrigin::Signed(caller), delegate_lookup, real_lookup, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
@@ -118,14 +123,15 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real);
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
real_lookup.clone(),
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(a, Some(caller.clone()), None)?;
}: _(RawOrigin::Signed(caller.clone()), real, T::CallHasher::hash_of(&call))
}: _(RawOrigin::Signed(caller.clone()), real_lookup, T::CallHasher::hash_of(&call))
verify {
let (announcements, _) = Announcements::<T>::get(&caller);
assert_eq!(announcements.len() as u32, a);
@@ -136,17 +142,19 @@ benchmarks! {
let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::<T>(p, None)?;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real.clone());
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
real_lookup,
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(a, Some(caller.clone()), None)?;
}: _(RawOrigin::Signed(real), caller.clone(), T::CallHasher::hash_of(&call))
}: _(RawOrigin::Signed(real), caller_lookup, T::CallHasher::hash_of(&call))
verify {
let (announcements, _) = Announcements::<T>::get(&caller);
assert_eq!(announcements.len() as u32, a);
@@ -160,10 +168,11 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value() / 2u32.into());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real.clone());
add_announcements::<T>(a, Some(caller.clone()), None)?;
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
}: _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash)
verify {
assert_last_event::<T>(Event::Announced { real, proxy: caller, call_hash }.into());
}
@@ -228,6 +237,7 @@ benchmarks! {
let p in 0 .. (T::MaxProxies::get() - 2);
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
Pallet::<T>::anonymous(
RawOrigin::Signed(whitelisted_caller()).into(),
@@ -241,7 +251,7 @@ benchmarks! {
add_proxies::<T>(p, Some(anon.clone()))?;
ensure!(Proxies::<T>::contains_key(&anon), "anon proxy not created");
}: _(RawOrigin::Signed(anon.clone()), caller.clone(), T::ProxyType::default(), 0, height, ext_index)
}: _(RawOrigin::Signed(anon.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index)
verify {
assert!(!Proxies::<T>::contains_key(&anon));
}
+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);