mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 02:21:04 +00:00
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:
@@ -57,6 +57,8 @@ frame_benchmarking::benchmarks_instance_pallet! {
|
||||
let dest_head: T::AccountId = account("dest_head", 0, 0);
|
||||
assert_ok!(List::<T, _>::insert(dest_head.clone(), dest_bag_thresh));
|
||||
|
||||
let origin_middle_lookup = T::Lookup::unlookup(origin_middle.clone());
|
||||
|
||||
// the bags are in the expected state after initial setup.
|
||||
assert_eq!(
|
||||
List::<T, _>::get_bags(),
|
||||
@@ -69,7 +71,7 @@ frame_benchmarking::benchmarks_instance_pallet! {
|
||||
let caller = whitelisted_caller();
|
||||
// update the weight of `origin_middle` to guarantee it will be rebagged into the destination.
|
||||
T::ScoreProvider::set_score_of(&origin_middle, dest_bag_thresh);
|
||||
}: rebag(SystemOrigin::Signed(caller), origin_middle.clone())
|
||||
}: rebag(SystemOrigin::Signed(caller), origin_middle_lookup.clone())
|
||||
verify {
|
||||
// check the bags have updated as expected.
|
||||
assert_eq!(
|
||||
@@ -114,6 +116,8 @@ frame_benchmarking::benchmarks_instance_pallet! {
|
||||
let dest_head: T::AccountId = account("dest_head", 0, 0);
|
||||
assert_ok!(List::<T, _>::insert(dest_head.clone(), dest_bag_thresh));
|
||||
|
||||
let origin_tail_lookup = T::Lookup::unlookup(origin_tail.clone());
|
||||
|
||||
// the bags are in the expected state after initial setup.
|
||||
assert_eq!(
|
||||
List::<T, _>::get_bags(),
|
||||
@@ -126,7 +130,7 @@ frame_benchmarking::benchmarks_instance_pallet! {
|
||||
let caller = whitelisted_caller();
|
||||
// update the weight of `origin_tail` to guarantee it will be rebagged into the destination.
|
||||
T::ScoreProvider::set_score_of(&origin_tail, dest_bag_thresh);
|
||||
}: rebag(SystemOrigin::Signed(caller), origin_tail.clone())
|
||||
}: rebag(SystemOrigin::Signed(caller), origin_tail_lookup.clone())
|
||||
verify {
|
||||
// check the bags have updated as expected.
|
||||
assert_eq!(
|
||||
@@ -166,13 +170,15 @@ frame_benchmarking::benchmarks_instance_pallet! {
|
||||
T::ScoreProvider::set_score_of(&lighter, bag_thresh - One::one());
|
||||
T::ScoreProvider::set_score_of(&heavier, bag_thresh);
|
||||
|
||||
let lighter_lookup = T::Lookup::unlookup(lighter.clone());
|
||||
|
||||
assert_eq!(
|
||||
List::<T, _>::iter().map(|n| n.id().clone()).collect::<Vec<_>>(),
|
||||
vec![lighter.clone(), heavier_prev.clone(), heavier.clone(), heavier_next.clone()]
|
||||
);
|
||||
|
||||
whitelist_account!(heavier);
|
||||
}: _(SystemOrigin::Signed(heavier.clone()), lighter.clone())
|
||||
}: _(SystemOrigin::Signed(heavier.clone()), lighter_lookup.clone())
|
||||
verify {
|
||||
assert_eq!(
|
||||
List::<T, _>::iter().map(|n| n.id().clone()).collect::<Vec<_>>(),
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
use codec::FullCodec;
|
||||
use frame_election_provider_support::{ScoreProvider, SortedListProvider};
|
||||
use frame_system::ensure_signed;
|
||||
use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded};
|
||||
use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, StaticLookup};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
#[cfg(any(feature = "runtime-benchmarks", test))]
|
||||
@@ -90,6 +90,8 @@ macro_rules! log {
|
||||
};
|
||||
}
|
||||
|
||||
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
@@ -222,8 +224,9 @@ pub mod pallet {
|
||||
///
|
||||
/// If `dislocated` does not exists, it returns an error.
|
||||
#[pallet::weight(T::WeightInfo::rebag_non_terminal().max(T::WeightInfo::rebag_terminal()))]
|
||||
pub fn rebag(origin: OriginFor<T>, dislocated: T::AccountId) -> DispatchResult {
|
||||
pub fn rebag(origin: OriginFor<T>, dislocated: AccountIdLookupOf<T>) -> DispatchResult {
|
||||
ensure_signed(origin)?;
|
||||
let dislocated = T::Lookup::lookup(dislocated)?;
|
||||
let current_score = T::ScoreProvider::score(&dislocated);
|
||||
let _ = Pallet::<T, I>::do_rebag(&dislocated, current_score)
|
||||
.map_err::<Error<T, I>, _>(Into::into)?;
|
||||
@@ -239,8 +242,12 @@ pub mod pallet {
|
||||
/// - both nodes are within the same bag,
|
||||
/// - and `origin` has a greater `Score` than `lighter`.
|
||||
#[pallet::weight(T::WeightInfo::put_in_front_of())]
|
||||
pub fn put_in_front_of(origin: OriginFor<T>, lighter: T::AccountId) -> DispatchResult {
|
||||
pub fn put_in_front_of(
|
||||
origin: OriginFor<T>,
|
||||
lighter: AccountIdLookupOf<T>,
|
||||
) -> DispatchResult {
|
||||
let heavier = ensure_signed(origin)?;
|
||||
let lighter = T::Lookup::lookup(lighter)?;
|
||||
List::<T, I>::put_in_front_of(&lighter, &heavier)
|
||||
.map_err::<Error<T, I>, _>(Into::into)
|
||||
.map_err::<DispatchError, _>(Into::into)
|
||||
|
||||
Reference in New Issue
Block a user