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
+12 -6
View File
@@ -483,9 +483,10 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
// Caller will initially delegate to `old_delegate`
let old_delegate: T::AccountId = funded_account::<T>("old_delegate", r);
let old_delegate_lookup = T::Lookup::unlookup(old_delegate.clone());
Democracy::<T>::delegate(
RawOrigin::Signed(caller.clone()).into(),
old_delegate.clone(),
old_delegate_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
@@ -497,6 +498,7 @@ benchmarks! {
assert_eq!(balance, delegated_balance, "delegation balance didn't work");
// Caller will now switch to `new_delegate`
let new_delegate: T::AccountId = funded_account::<T>("new_delegate", r);
let new_delegate_lookup = T::Lookup::unlookup(new_delegate.clone());
let account_vote = account_vote::<T>(initial_balance);
// We need to create existing direct votes for the `new_delegate`
for i in 0..r {
@@ -509,7 +511,7 @@ benchmarks! {
};
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), new_delegate.clone(), Conviction::Locked1x, delegated_balance)
}: _(RawOrigin::Signed(caller.clone()), new_delegate_lookup, Conviction::Locked1x, delegated_balance)
verify {
let (target, balance) = match VotingOf::<T>::get(&caller) {
Voting::Delegating { target, balance, .. } => (target, balance),
@@ -533,9 +535,10 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
// Caller will delegate
let the_delegate: T::AccountId = funded_account::<T>("delegate", r);
let the_delegate_lookup = T::Lookup::unlookup(the_delegate.clone());
Democracy::<T>::delegate(
RawOrigin::Signed(caller.clone()).into(),
the_delegate.clone(),
the_delegate_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
@@ -642,6 +645,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;
let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
// Populate votes so things are locked
let base_balance: BalanceOf<T> = 100u32.into();
let small_vote = account_vote::<T>(base_balance);
@@ -654,7 +658,7 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: unlock(RawOrigin::Signed(caller), locker.clone())
}: unlock(RawOrigin::Signed(caller), locker_lookup)
verify {
// Note that we may want to add a `get_lock` api to actually verify
let voting = VotingOf::<T>::get(&locker);
@@ -666,6 +670,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;
let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
// Populate votes so things are locked
let base_balance: BalanceOf<T> = 100u32.into();
let small_vote = account_vote::<T>(base_balance);
@@ -692,7 +697,7 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: unlock(RawOrigin::Signed(caller), locker.clone())
}: unlock(RawOrigin::Signed(caller), locker_lookup)
verify {
let votes = match VotingOf::<T>::get(&locker) {
Voting::Direct { votes, .. } => votes,
@@ -738,6 +743,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;
let caller = funded_account::<T>("caller", r);
let caller_lookup = T::Lookup::unlookup(caller.clone());
let account_vote = account_vote::<T>(100u32.into());
for i in 0 .. r {
@@ -753,7 +759,7 @@ benchmarks! {
let referendum_index = r - 1;
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index)
}: _(RawOrigin::Signed(caller.clone()), caller_lookup, referendum_index)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
+8 -4
View File
@@ -165,7 +165,7 @@ use frame_support::{
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Bounded, Dispatchable, Hash, Saturating, Zero},
traits::{Bounded, Dispatchable, Hash, Saturating, StaticLookup, Zero},
ArithmeticError, DispatchError, DispatchResult, RuntimeDebug,
};
use sp_std::prelude::*;
@@ -206,6 +206,7 @@ type BalanceOf<T> =
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum PreimageStatus<AccountId, Balance, BlockNumber> {
@@ -944,11 +945,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::delegate(T::MaxVotes::get()))]
pub fn delegate(
origin: OriginFor<T>,
to: T::AccountId,
to: AccountIdLookupOf<T>,
conviction: Conviction,
balance: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
let votes = Self::try_delegate(who, to, conviction, balance)?;
Ok(Some(T::WeightInfo::delegate(votes)).into())
@@ -1127,8 +1129,9 @@ pub mod pallet {
T::WeightInfo::unlock_set(T::MaxVotes::get())
.max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))
)]
pub fn unlock(origin: OriginFor<T>, target: T::AccountId) -> DispatchResult {
pub fn unlock(origin: OriginFor<T>, target: AccountIdLookupOf<T>) -> DispatchResult {
ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
Self::update_lock(&target);
Ok(())
}
@@ -1184,10 +1187,11 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_other_vote(T::MaxVotes::get()))]
pub fn remove_other_vote(
origin: OriginFor<T>,
target: T::AccountId,
target: AccountIdLookupOf<T>,
index: ReferendumIndex,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired };
Self::try_remove_vote(&target, index, scope)?;
Ok(())