Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 22b678f

Browse files
Doordashconggwpez
andauthored
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>
1 parent e7aa858 commit 22b678f

File tree

50 files changed

+465
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+465
-309
lines changed

frame/alliance/src/benchmarking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ benchmarks_instance_pallet! {
662662
assert!(!Alliance::<T, I>::is_member(&outsider));
663663
assert_eq!(DepositOf::<T, I>::get(&outsider), None);
664664

665-
let outsider_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(outsider.clone());
665+
let outsider_lookup = T::Lookup::unlookup(outsider.clone());
666666
}: _(SystemOrigin::Signed(founder1.clone()), outsider_lookup)
667667
verify {
668668
assert!(Alliance::<T, I>::is_member_of(&outsider, MemberRole::Ally)); // outsider is now an ally
@@ -681,7 +681,7 @@ benchmarks_instance_pallet! {
681681
let ally1 = ally::<T, I>(1);
682682
assert!(Alliance::<T, I>::is_ally(&ally1));
683683

684-
let ally1_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(ally1.clone());
684+
let ally1_lookup = T::Lookup::unlookup(ally1.clone());
685685
let call = Call::<T, I>::elevate_ally { ally: ally1_lookup };
686686
let origin = T::MembershipManager::successful_origin();
687687
}: { call.dispatch_bypass_filter(origin)? }
@@ -720,7 +720,7 @@ benchmarks_instance_pallet! {
720720

721721
assert_eq!(DepositOf::<T, I>::get(&fellow2), Some(T::AllyDeposit::get()));
722722

723-
let fellow2_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(fellow2.clone());
723+
let fellow2_lookup = T::Lookup::unlookup(fellow2.clone());
724724
let call = Call::<T, I>::kick_member { who: fellow2_lookup };
725725
let origin = T::MembershipManager::successful_origin();
726726
}: { call.dispatch_bypass_filter(origin)? }

frame/alliance/src/lib.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ pub enum UnscrupulousItem<AccountId, Url> {
210210
type UnscrupulousItemOf<T, I> =
211211
UnscrupulousItem<<T as frame_system::Config>::AccountId, UrlOf<T, I>>;
212212

213+
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
214+
213215
#[frame_support::pallet]
214216
pub mod pallet {
215217
use super::*;
@@ -744,10 +746,7 @@ pub mod pallet {
744746
/// A founder or fellow can nominate someone to join the alliance as an Ally.
745747
/// There is no deposit required to the nominator or nominee.
746748
#[pallet::weight(T::WeightInfo::nominate_ally())]
747-
pub fn nominate_ally(
748-
origin: OriginFor<T>,
749-
who: <T::Lookup as StaticLookup>::Source,
750-
) -> DispatchResult {
749+
pub fn nominate_ally(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
751750
let nominator = ensure_signed(origin)?;
752751
ensure!(Self::has_voting_rights(&nominator), Error::<T, I>::NoVotingRights);
753752
let who = T::Lookup::lookup(who)?;
@@ -771,10 +770,7 @@ pub mod pallet {
771770

772771
/// Elevate an ally to fellow.
773772
#[pallet::weight(T::WeightInfo::elevate_ally())]
774-
pub fn elevate_ally(
775-
origin: OriginFor<T>,
776-
ally: <T::Lookup as StaticLookup>::Source,
777-
) -> DispatchResult {
773+
pub fn elevate_ally(origin: OriginFor<T>, ally: AccountIdLookupOf<T>) -> DispatchResult {
778774
T::MembershipManager::ensure_origin(origin)?;
779775
let ally = T::Lookup::lookup(ally)?;
780776
ensure!(Self::is_ally(&ally), Error::<T, I>::NotAlly);
@@ -807,10 +803,7 @@ pub mod pallet {
807803

808804
/// Kick a member from the alliance and slash its deposit.
809805
#[pallet::weight(T::WeightInfo::kick_member())]
810-
pub fn kick_member(
811-
origin: OriginFor<T>,
812-
who: <T::Lookup as StaticLookup>::Source,
813-
) -> DispatchResult {
806+
pub fn kick_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
814807
T::MembershipManager::ensure_origin(origin)?;
815808
let member = T::Lookup::lookup(who)?;
816809

frame/assets/src/benchmarking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const SEED: u32 = 0;
3737

3838
fn create_default_asset<T: Config<I>, I: 'static>(
3939
is_sufficient: bool,
40-
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
40+
) -> (T::AccountId, AccountIdLookupOf<T>) {
4141
let caller: T::AccountId = whitelisted_caller();
4242
let caller_lookup = T::Lookup::unlookup(caller.clone());
4343
let root = SystemOrigin::Root.into();
@@ -55,7 +55,7 @@ fn create_default_asset<T: Config<I>, I: 'static>(
5555
fn create_default_minted_asset<T: Config<I>, I: 'static>(
5656
is_sufficient: bool,
5757
amount: T::Balance,
58-
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
58+
) -> (T::AccountId, AccountIdLookupOf<T>) {
5959
let (caller, caller_lookup) = create_default_asset::<T, I>(is_sufficient);
6060
if !is_sufficient {
6161
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance());

frame/assets/src/lib.rs

+26-24
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ use frame_system::Config as SystemConfig;
164164
pub use pallet::*;
165165
pub use weights::WeightInfo;
166166

167+
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
168+
167169
#[frame_support::pallet]
168170
pub mod pallet {
169171
use super::*;
@@ -501,7 +503,7 @@ pub mod pallet {
501503
pub fn create(
502504
origin: OriginFor<T>,
503505
#[pallet::compact] id: T::AssetId,
504-
admin: <T::Lookup as StaticLookup>::Source,
506+
admin: AccountIdLookupOf<T>,
505507
min_balance: T::Balance,
506508
) -> DispatchResult {
507509
let owner = ensure_signed(origin)?;
@@ -557,7 +559,7 @@ pub mod pallet {
557559
pub fn force_create(
558560
origin: OriginFor<T>,
559561
#[pallet::compact] id: T::AssetId,
560-
owner: <T::Lookup as StaticLookup>::Source,
562+
owner: AccountIdLookupOf<T>,
561563
is_sufficient: bool,
562564
#[pallet::compact] min_balance: T::Balance,
563565
) -> DispatchResult {
@@ -623,7 +625,7 @@ pub mod pallet {
623625
pub fn mint(
624626
origin: OriginFor<T>,
625627
#[pallet::compact] id: T::AssetId,
626-
beneficiary: <T::Lookup as StaticLookup>::Source,
628+
beneficiary: AccountIdLookupOf<T>,
627629
#[pallet::compact] amount: T::Balance,
628630
) -> DispatchResult {
629631
let origin = ensure_signed(origin)?;
@@ -651,7 +653,7 @@ pub mod pallet {
651653
pub fn burn(
652654
origin: OriginFor<T>,
653655
#[pallet::compact] id: T::AssetId,
654-
who: <T::Lookup as StaticLookup>::Source,
656+
who: AccountIdLookupOf<T>,
655657
#[pallet::compact] amount: T::Balance,
656658
) -> DispatchResult {
657659
let origin = ensure_signed(origin)?;
@@ -684,7 +686,7 @@ pub mod pallet {
684686
pub fn transfer(
685687
origin: OriginFor<T>,
686688
#[pallet::compact] id: T::AssetId,
687-
target: <T::Lookup as StaticLookup>::Source,
689+
target: AccountIdLookupOf<T>,
688690
#[pallet::compact] amount: T::Balance,
689691
) -> DispatchResult {
690692
let origin = ensure_signed(origin)?;
@@ -716,7 +718,7 @@ pub mod pallet {
716718
pub fn transfer_keep_alive(
717719
origin: OriginFor<T>,
718720
#[pallet::compact] id: T::AssetId,
719-
target: <T::Lookup as StaticLookup>::Source,
721+
target: AccountIdLookupOf<T>,
720722
#[pallet::compact] amount: T::Balance,
721723
) -> DispatchResult {
722724
let source = ensure_signed(origin)?;
@@ -749,8 +751,8 @@ pub mod pallet {
749751
pub fn force_transfer(
750752
origin: OriginFor<T>,
751753
#[pallet::compact] id: T::AssetId,
752-
source: <T::Lookup as StaticLookup>::Source,
753-
dest: <T::Lookup as StaticLookup>::Source,
754+
source: AccountIdLookupOf<T>,
755+
dest: AccountIdLookupOf<T>,
754756
#[pallet::compact] amount: T::Balance,
755757
) -> DispatchResult {
756758
let origin = ensure_signed(origin)?;
@@ -775,7 +777,7 @@ pub mod pallet {
775777
pub fn freeze(
776778
origin: OriginFor<T>,
777779
#[pallet::compact] id: T::AssetId,
778-
who: <T::Lookup as StaticLookup>::Source,
780+
who: AccountIdLookupOf<T>,
779781
) -> DispatchResult {
780782
let origin = ensure_signed(origin)?;
781783

@@ -806,7 +808,7 @@ pub mod pallet {
806808
pub fn thaw(
807809
origin: OriginFor<T>,
808810
#[pallet::compact] id: T::AssetId,
809-
who: <T::Lookup as StaticLookup>::Source,
811+
who: AccountIdLookupOf<T>,
810812
) -> DispatchResult {
811813
let origin = ensure_signed(origin)?;
812814

@@ -891,7 +893,7 @@ pub mod pallet {
891893
pub fn transfer_ownership(
892894
origin: OriginFor<T>,
893895
#[pallet::compact] id: T::AssetId,
894-
owner: <T::Lookup as StaticLookup>::Source,
896+
owner: AccountIdLookupOf<T>,
895897
) -> DispatchResult {
896898
let origin = ensure_signed(origin)?;
897899
let owner = T::Lookup::lookup(owner)?;
@@ -932,9 +934,9 @@ pub mod pallet {
932934
pub fn set_team(
933935
origin: OriginFor<T>,
934936
#[pallet::compact] id: T::AssetId,
935-
issuer: <T::Lookup as StaticLookup>::Source,
936-
admin: <T::Lookup as StaticLookup>::Source,
937-
freezer: <T::Lookup as StaticLookup>::Source,
937+
issuer: AccountIdLookupOf<T>,
938+
admin: AccountIdLookupOf<T>,
939+
freezer: AccountIdLookupOf<T>,
938940
) -> DispatchResult {
939941
let origin = ensure_signed(origin)?;
940942
let issuer = T::Lookup::lookup(issuer)?;
@@ -1117,10 +1119,10 @@ pub mod pallet {
11171119
pub fn force_asset_status(
11181120
origin: OriginFor<T>,
11191121
#[pallet::compact] id: T::AssetId,
1120-
owner: <T::Lookup as StaticLookup>::Source,
1121-
issuer: <T::Lookup as StaticLookup>::Source,
1122-
admin: <T::Lookup as StaticLookup>::Source,
1123-
freezer: <T::Lookup as StaticLookup>::Source,
1122+
owner: AccountIdLookupOf<T>,
1123+
issuer: AccountIdLookupOf<T>,
1124+
admin: AccountIdLookupOf<T>,
1125+
freezer: AccountIdLookupOf<T>,
11241126
#[pallet::compact] min_balance: T::Balance,
11251127
is_sufficient: bool,
11261128
is_frozen: bool,
@@ -1167,7 +1169,7 @@ pub mod pallet {
11671169
pub fn approve_transfer(
11681170
origin: OriginFor<T>,
11691171
#[pallet::compact] id: T::AssetId,
1170-
delegate: <T::Lookup as StaticLookup>::Source,
1172+
delegate: AccountIdLookupOf<T>,
11711173
#[pallet::compact] amount: T::Balance,
11721174
) -> DispatchResult {
11731175
let owner = ensure_signed(origin)?;
@@ -1192,7 +1194,7 @@ pub mod pallet {
11921194
pub fn cancel_approval(
11931195
origin: OriginFor<T>,
11941196
#[pallet::compact] id: T::AssetId,
1195-
delegate: <T::Lookup as StaticLookup>::Source,
1197+
delegate: AccountIdLookupOf<T>,
11961198
) -> DispatchResult {
11971199
let owner = ensure_signed(origin)?;
11981200
let delegate = T::Lookup::lookup(delegate)?;
@@ -1225,8 +1227,8 @@ pub mod pallet {
12251227
pub fn force_cancel_approval(
12261228
origin: OriginFor<T>,
12271229
#[pallet::compact] id: T::AssetId,
1228-
owner: <T::Lookup as StaticLookup>::Source,
1229-
delegate: <T::Lookup as StaticLookup>::Source,
1230+
owner: AccountIdLookupOf<T>,
1231+
delegate: AccountIdLookupOf<T>,
12301232
) -> DispatchResult {
12311233
let mut d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
12321234
T::ForceOrigin::try_origin(origin)
@@ -1272,8 +1274,8 @@ pub mod pallet {
12721274
pub fn transfer_approved(
12731275
origin: OriginFor<T>,
12741276
#[pallet::compact] id: T::AssetId,
1275-
owner: <T::Lookup as StaticLookup>::Source,
1276-
destination: <T::Lookup as StaticLookup>::Source,
1277+
owner: AccountIdLookupOf<T>,
1278+
destination: AccountIdLookupOf<T>,
12771279
#[pallet::compact] amount: T::Balance,
12781280
) -> DispatchResult {
12791281
let delegate = ensure_signed(origin)?;

frame/bags-list/src/benchmarks.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ frame_benchmarking::benchmarks_instance_pallet! {
5757
let dest_head: T::AccountId = account("dest_head", 0, 0);
5858
assert_ok!(List::<T, _>::insert(dest_head.clone(), dest_bag_thresh));
5959

60+
let origin_middle_lookup = T::Lookup::unlookup(origin_middle.clone());
61+
6062
// the bags are in the expected state after initial setup.
6163
assert_eq!(
6264
List::<T, _>::get_bags(),
@@ -69,7 +71,7 @@ frame_benchmarking::benchmarks_instance_pallet! {
6971
let caller = whitelisted_caller();
7072
// update the weight of `origin_middle` to guarantee it will be rebagged into the destination.
7173
T::ScoreProvider::set_score_of(&origin_middle, dest_bag_thresh);
72-
}: rebag(SystemOrigin::Signed(caller), origin_middle.clone())
74+
}: rebag(SystemOrigin::Signed(caller), origin_middle_lookup.clone())
7375
verify {
7476
// check the bags have updated as expected.
7577
assert_eq!(
@@ -114,6 +116,8 @@ frame_benchmarking::benchmarks_instance_pallet! {
114116
let dest_head: T::AccountId = account("dest_head", 0, 0);
115117
assert_ok!(List::<T, _>::insert(dest_head.clone(), dest_bag_thresh));
116118

119+
let origin_tail_lookup = T::Lookup::unlookup(origin_tail.clone());
120+
117121
// the bags are in the expected state after initial setup.
118122
assert_eq!(
119123
List::<T, _>::get_bags(),
@@ -126,7 +130,7 @@ frame_benchmarking::benchmarks_instance_pallet! {
126130
let caller = whitelisted_caller();
127131
// update the weight of `origin_tail` to guarantee it will be rebagged into the destination.
128132
T::ScoreProvider::set_score_of(&origin_tail, dest_bag_thresh);
129-
}: rebag(SystemOrigin::Signed(caller), origin_tail.clone())
133+
}: rebag(SystemOrigin::Signed(caller), origin_tail_lookup.clone())
130134
verify {
131135
// check the bags have updated as expected.
132136
assert_eq!(
@@ -166,13 +170,15 @@ frame_benchmarking::benchmarks_instance_pallet! {
166170
T::ScoreProvider::set_score_of(&lighter, bag_thresh - One::one());
167171
T::ScoreProvider::set_score_of(&heavier, bag_thresh);
168172

173+
let lighter_lookup = T::Lookup::unlookup(lighter.clone());
174+
169175
assert_eq!(
170176
List::<T, _>::iter().map(|n| n.id().clone()).collect::<Vec<_>>(),
171177
vec![lighter.clone(), heavier_prev.clone(), heavier.clone(), heavier_next.clone()]
172178
);
173179

174180
whitelist_account!(heavier);
175-
}: _(SystemOrigin::Signed(heavier.clone()), lighter.clone())
181+
}: _(SystemOrigin::Signed(heavier.clone()), lighter_lookup.clone())
176182
verify {
177183
assert_eq!(
178184
List::<T, _>::iter().map(|n| n.id().clone()).collect::<Vec<_>>(),

frame/bags-list/src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
use codec::FullCodec;
5757
use frame_election_provider_support::{ScoreProvider, SortedListProvider};
5858
use frame_system::ensure_signed;
59-
use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded};
59+
use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, StaticLookup};
6060
use sp_std::prelude::*;
6161

6262
#[cfg(any(feature = "runtime-benchmarks", test))]
@@ -90,6 +90,8 @@ macro_rules! log {
9090
};
9191
}
9292

93+
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
94+
9395
#[frame_support::pallet]
9496
pub mod pallet {
9597
use super::*;
@@ -222,8 +224,9 @@ pub mod pallet {
222224
///
223225
/// If `dislocated` does not exists, it returns an error.
224226
#[pallet::weight(T::WeightInfo::rebag_non_terminal().max(T::WeightInfo::rebag_terminal()))]
225-
pub fn rebag(origin: OriginFor<T>, dislocated: T::AccountId) -> DispatchResult {
227+
pub fn rebag(origin: OriginFor<T>, dislocated: AccountIdLookupOf<T>) -> DispatchResult {
226228
ensure_signed(origin)?;
229+
let dislocated = T::Lookup::lookup(dislocated)?;
227230
let current_score = T::ScoreProvider::score(&dislocated);
228231
let _ = Pallet::<T, I>::do_rebag(&dislocated, current_score)
229232
.map_err::<Error<T, I>, _>(Into::into)?;
@@ -239,8 +242,12 @@ pub mod pallet {
239242
/// - both nodes are within the same bag,
240243
/// - and `origin` has a greater `Score` than `lighter`.
241244
#[pallet::weight(T::WeightInfo::put_in_front_of())]
242-
pub fn put_in_front_of(origin: OriginFor<T>, lighter: T::AccountId) -> DispatchResult {
245+
pub fn put_in_front_of(
246+
origin: OriginFor<T>,
247+
lighter: AccountIdLookupOf<T>,
248+
) -> DispatchResult {
243249
let heavier = ensure_signed(origin)?;
250+
let lighter = T::Lookup::lookup(lighter)?;
244251
List::<T, I>::put_in_front_of(&lighter, &heavier)
245252
.map_err::<Error<T, I>, _>(Into::into)
246253
.map_err::<DispatchError, _>(Into::into)

0 commit comments

Comments
 (0)