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
@@ -149,6 +149,7 @@ benchmarks_instance_pallet! {
remove_other_vote {
let caller = funded_account::<T, I>("caller", 0);
let voter = funded_account::<T, I>("caller", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
whitelist_account!(caller);
let old_account_vote = account_vote::<T, I>(100u32.into());
@@ -167,7 +168,7 @@ benchmarks_instance_pallet! {
let index = polls[0];
assert!(T::Polls::end_ongoing(index, false).is_ok());
}: _(RawOrigin::Signed(caller.clone()), voter.clone(), class.clone(), index)
}: _(RawOrigin::Signed(caller.clone()), voter_lookup, class.clone(), index)
verify {
assert_matches!(
VotingFor::<T, I>::get(&voter, &class),
@@ -182,6 +183,7 @@ benchmarks_instance_pallet! {
let class = T::Polls::max_ongoing().0;
let polls = &all_polls[&class];
let voter = funded_account::<T, I>("voter", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
let caller = funded_account::<T, I>("caller", 0);
whitelist_account!(caller);
@@ -197,7 +199,7 @@ benchmarks_instance_pallet! {
Voting::Casting(Casting { votes, .. }) if votes.len() == r as usize
);
}: _(RawOrigin::Signed(caller.clone()), class.clone(), voter, Conviction::Locked1x, delegated_balance)
}: _(RawOrigin::Signed(caller.clone()), class.clone(), voter_lookup, Conviction::Locked1x, delegated_balance)
verify {
assert_matches!(VotingFor::<T, I>::get(&caller, &class), Voting::Delegating(_));
}
@@ -209,6 +211,7 @@ benchmarks_instance_pallet! {
let class = T::Polls::max_ongoing().0;
let polls = &all_polls[&class];
let voter = funded_account::<T, I>("voter", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
let caller = funded_account::<T, I>("caller", 0);
whitelist_account!(caller);
@@ -218,7 +221,7 @@ benchmarks_instance_pallet! {
ConvictionVoting::<T, I>::delegate(
RawOrigin::Signed(caller.clone()).into(),
class.clone(),
voter.clone(),
voter_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
@@ -239,6 +242,7 @@ benchmarks_instance_pallet! {
unlock {
let caller = funded_account::<T, I>("caller", 0);
let caller_lookup = T::Lookup::unlookup(caller.clone());
whitelist_account!(caller);
let normal_account_vote = account_vote::<T, I>(T::Currency::free_balance(&caller) - 100u32.into());
let big_account_vote = account_vote::<T, I>(T::Currency::free_balance(&caller));
@@ -266,7 +270,7 @@ benchmarks_instance_pallet! {
ConvictionVoting::<T, I>::remove_vote(RawOrigin::Signed(caller.clone()).into(), Some(class.clone()), polls[0])?;
// We can now unlock on `class` from 200 to 100...
}: _(RawOrigin::Signed(caller.clone()), class, caller.clone())
}: _(RawOrigin::Signed(caller.clone()), class, caller_lookup)
verify {
assert_eq!(orig_usable, <T::Currency as fungible::Inspect<T::AccountId>>::reducible_balance(&caller, false));
}
+8 -4
View File
@@ -36,7 +36,7 @@ use frame_support::{
},
};
use sp_runtime::{
traits::{AtLeast32BitUnsigned, Saturating, Zero},
traits::{AtLeast32BitUnsigned, Saturating, StaticLookup, Zero},
ArithmeticError, Perbill,
};
use sp_std::prelude::*;
@@ -62,6 +62,7 @@ pub mod benchmarking;
const CONVICTION_VOTING_ID: LockIdentifier = *b"pyconvot";
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type BalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type VotingOf<T, I = ()> = Voting<
@@ -245,11 +246,12 @@ pub mod pallet {
pub fn delegate(
origin: OriginFor<T>,
class: ClassOf<T, I>,
to: T::AccountId,
to: AccountIdLookupOf<T>,
conviction: Conviction,
balance: BalanceOf<T, I>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
let votes = Self::try_delegate(who, class, to, conviction, balance)?;
Ok(Some(T::WeightInfo::delegate(votes)).into())
@@ -294,9 +296,10 @@ pub mod pallet {
pub fn unlock(
origin: OriginFor<T>,
class: ClassOf<T, I>,
target: T::AccountId,
target: AccountIdLookupOf<T>,
) -> DispatchResult {
ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
Self::update_lock(&class, &target);
Ok(())
}
@@ -359,11 +362,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_other_vote())]
pub fn remove_other_vote(
origin: OriginFor<T>,
target: T::AccountId,
target: AccountIdLookupOf<T>,
class: ClassOf<T, I>,
index: PollIndexOf<T, I>,
) -> 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, Some(class), scope)?;
Ok(())