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
+11 -11
View File
@@ -42,7 +42,7 @@ fn add_locks<T: Config>(who: &T::AccountId, n: u8) {
}
fn add_vesting_schedules<T: Config>(
target: <T::Lookup as StaticLookup>::Source,
target: AccountIdLookupOf<T>,
n: u32,
) -> Result<BalanceOf<T>, &'static str> {
let min_transfer = T::MinVestedTransfer::get();
@@ -52,7 +52,7 @@ fn add_vesting_schedules<T: Config>(
let starting_block = 1u32;
let source: T::AccountId = account("source", 0, SEED);
let source_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(source.clone());
let source_lookup = T::Lookup::unlookup(source.clone());
T::Currency::make_free_balance_be(&source, BalanceOf::<T>::max_value());
System::<T>::set_block_number(T::BlockNumber::zero());
@@ -81,7 +81,7 @@ benchmarks! {
let s in 1 .. T::MAX_VESTING_SCHEDULES;
let caller: T::AccountId = whitelisted_caller();
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance());
add_locks::<T>(&caller, l as u8);
@@ -109,7 +109,7 @@ benchmarks! {
let s in 1 .. T::MAX_VESTING_SCHEDULES;
let caller: T::AccountId = whitelisted_caller();
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance());
add_locks::<T>(&caller, l as u8);
@@ -137,7 +137,7 @@ benchmarks! {
let s in 1 .. T::MAX_VESTING_SCHEDULES;
let other: T::AccountId = account("other", 0, SEED);
let other_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(other.clone());
let other_lookup = T::Lookup::unlookup(other.clone());
add_locks::<T>(&other, l as u8);
let expected_balance = add_vesting_schedules::<T>(other_lookup.clone(), s)?;
@@ -166,7 +166,7 @@ benchmarks! {
let s in 1 .. T::MAX_VESTING_SCHEDULES;
let other: T::AccountId = account("other", 0, SEED);
let other_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(other.clone());
let other_lookup = T::Lookup::unlookup(other.clone());
add_locks::<T>(&other, l as u8);
add_vesting_schedules::<T>(other_lookup.clone(), s)?;
@@ -198,7 +198,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let target: T::AccountId = account("target", 0, SEED);
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
let target_lookup = T::Lookup::unlookup(target.clone());
// Give target existing locks
add_locks::<T>(&target, l as u8);
// Add one vesting schedules.
@@ -232,11 +232,11 @@ benchmarks! {
let s in 0 .. T::MAX_VESTING_SCHEDULES - 1;
let source: T::AccountId = account("source", 0, SEED);
let source_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(source.clone());
let source_lookup = T::Lookup::unlookup(source.clone());
T::Currency::make_free_balance_be(&source, BalanceOf::<T>::max_value());
let target: T::AccountId = account("target", 0, SEED);
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
let target_lookup = T::Lookup::unlookup(target.clone());
// Give target existing locks
add_locks::<T>(&target, l as u8);
// Add one less than max vesting schedules
@@ -270,7 +270,7 @@ benchmarks! {
let s in 2 .. T::MAX_VESTING_SCHEDULES;
let caller: T::AccountId = account("caller", 0, SEED);
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_lookup = T::Lookup::unlookup(caller.clone());
// Give target existing locks.
add_locks::<T>(&caller, l as u8);
// Add max vesting schedules.
@@ -320,7 +320,7 @@ benchmarks! {
let test_dest: T::AccountId = account("test_dest", 0, SEED);
let caller: T::AccountId = account("caller", 0, SEED);
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_lookup = T::Lookup::unlookup(caller.clone());
// Give target other locks.
add_locks::<T>(&caller, l as u8);
// Add max vesting schedules.
+7 -9
View File
@@ -84,6 +84,7 @@ type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type MaxLocksOf<T> =
<<T as Config>::Currency as LockableCurrency<<T as frame_system::Config>::AccountId>>::MaxLocks;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
const VESTING_ID: LockIdentifier = *b"vesting ";
@@ -321,10 +322,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::vest_other_locked(MaxLocksOf::<T>::get(), T::MAX_VESTING_SCHEDULES)
.max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::<T>::get(), T::MAX_VESTING_SCHEDULES))
)]
pub fn vest_other(
origin: OriginFor<T>,
target: <T::Lookup as StaticLookup>::Source,
) -> DispatchResult {
pub fn vest_other(origin: OriginFor<T>, target: AccountIdLookupOf<T>) -> DispatchResult {
ensure_signed(origin)?;
let who = T::Lookup::lookup(target)?;
Self::do_vest(who)
@@ -352,7 +350,7 @@ pub mod pallet {
)]
pub fn vested_transfer(
origin: OriginFor<T>,
target: <T::Lookup as StaticLookup>::Source,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
@@ -383,8 +381,8 @@ pub mod pallet {
)]
pub fn force_vested_transfer(
origin: OriginFor<T>,
source: <T::Lookup as StaticLookup>::Source,
target: <T::Lookup as StaticLookup>::Source,
source: AccountIdLookupOf<T>,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
) -> DispatchResult {
ensure_root(origin)?;
@@ -494,8 +492,8 @@ impl<T: Config> Pallet<T> {
// Execute a vested transfer from `source` to `target` with the given `schedule`.
fn do_vested_transfer(
source: <T::Lookup as StaticLookup>::Source,
target: <T::Lookup as StaticLookup>::Source,
source: AccountIdLookupOf<T>,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
) -> DispatchResult {
// Validate user inputs.