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

Replace T::AccountId with <T::Lookup as StaticLookup>::Source #11670

Merged
merged 23 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ benchmarks_instance_pallet! {
assert!(!Alliance::<T, I>::is_member(&outsider));
assert_eq!(DepositOf::<T, I>::get(&outsider), None);

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

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

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

let fellow2_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(fellow2.clone());
let fellow2_lookup: AccountIdLookupOf<T> = T::Lookup::unlookup(fellow2.clone());
let call = Call::<T, I>::kick_member { who: fellow2_lookup };
let origin = T::MembershipManager::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
Expand Down
8 changes: 5 additions & 3 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ pub enum UnscrupulousItem<AccountId, Url> {
type UnscrupulousItemOf<T, I> =
UnscrupulousItem<<T as frame_system::Config>::AccountId, UrlOf<T, I>>;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -731,7 +733,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::nominate_ally())]
pub fn nominate_ally(
origin: OriginFor<T>,
who: <T::Lookup as StaticLookup>::Source,
who: AccountIdLookupOf<T>,
) -> DispatchResult {
let nominator = ensure_signed(origin)?;
ensure!(Self::has_voting_rights(&nominator), Error::<T, I>::NoVotingRights);
Expand All @@ -758,7 +760,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::elevate_ally())]
pub fn elevate_ally(
origin: OriginFor<T>,
ally: <T::Lookup as StaticLookup>::Source,
ally: AccountIdLookupOf<T>,
) -> DispatchResult {
T::MembershipManager::ensure_origin(origin)?;
let ally = T::Lookup::lookup(ally)?;
Expand Down Expand Up @@ -794,7 +796,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::kick_member())]
pub fn kick_member(
origin: OriginFor<T>,
who: <T::Lookup as StaticLookup>::Source,
who: AccountIdLookupOf<T>,
) -> DispatchResult {
T::MembershipManager::ensure_origin(origin)?;
let member = T::Lookup::lookup(who)?;
Expand Down
4 changes: 2 additions & 2 deletions frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SEED: u32 = 0;

fn create_default_asset<T: Config<I>, I: 'static>(
is_sufficient: bool,
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
) -> (T::AccountId, AccountIdLookupOf<T>) {
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let root = SystemOrigin::Root.into();
Expand All @@ -55,7 +55,7 @@ fn create_default_asset<T: Config<I>, I: 'static>(
fn create_default_minted_asset<T: Config<I>, I: 'static>(
is_sufficient: bool,
amount: T::Balance,
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
) -> (T::AccountId, AccountIdLookupOf<T>) {
let (caller, caller_lookup) = create_default_asset::<T, I>(is_sufficient);
if !is_sufficient {
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance());
Expand Down
50 changes: 26 additions & 24 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ use frame_system::Config as SystemConfig;
pub use pallet::*;
pub use weights::WeightInfo;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -501,7 +503,7 @@ pub mod pallet {
pub fn create(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
admin: <T::Lookup as StaticLookup>::Source,
admin: AccountIdLookupOf<T>,
min_balance: T::Balance,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
Expand Down Expand Up @@ -557,7 +559,7 @@ pub mod pallet {
pub fn force_create(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
owner: <T::Lookup as StaticLookup>::Source,
owner: AccountIdLookupOf<T>,
is_sufficient: bool,
#[pallet::compact] min_balance: T::Balance,
) -> DispatchResult {
Expand Down Expand Up @@ -623,7 +625,7 @@ pub mod pallet {
pub fn mint(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
beneficiary: <T::Lookup as StaticLookup>::Source,
beneficiary: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand Down Expand Up @@ -651,7 +653,7 @@ pub mod pallet {
pub fn burn(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
who: <T::Lookup as StaticLookup>::Source,
who: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand Down Expand Up @@ -684,7 +686,7 @@ pub mod pallet {
pub fn transfer(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
target: <T::Lookup as StaticLookup>::Source,
target: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand Down Expand Up @@ -716,7 +718,7 @@ pub mod pallet {
pub fn transfer_keep_alive(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
target: <T::Lookup as StaticLookup>::Source,
target: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let source = ensure_signed(origin)?;
Expand Down Expand Up @@ -749,8 +751,8 @@ pub mod pallet {
pub fn force_transfer(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
source: <T::Lookup as StaticLookup>::Source,
dest: <T::Lookup as StaticLookup>::Source,
source: AccountIdLookupOf<T>,
dest: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand All @@ -775,7 +777,7 @@ pub mod pallet {
pub fn freeze(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
who: <T::Lookup as StaticLookup>::Source,
who: AccountIdLookupOf<T>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;

Expand Down Expand Up @@ -806,7 +808,7 @@ pub mod pallet {
pub fn thaw(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
who: <T::Lookup as StaticLookup>::Source,
who: AccountIdLookupOf<T>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;

Expand Down Expand Up @@ -891,7 +893,7 @@ pub mod pallet {
pub fn transfer_ownership(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
owner: <T::Lookup as StaticLookup>::Source,
owner: AccountIdLookupOf<T>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
let owner = T::Lookup::lookup(owner)?;
Expand Down Expand Up @@ -932,9 +934,9 @@ pub mod pallet {
pub fn set_team(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
issuer: <T::Lookup as StaticLookup>::Source,
admin: <T::Lookup as StaticLookup>::Source,
freezer: <T::Lookup as StaticLookup>::Source,
issuer: AccountIdLookupOf<T>,
admin: AccountIdLookupOf<T>,
freezer: AccountIdLookupOf<T>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
let issuer = T::Lookup::lookup(issuer)?;
Expand Down Expand Up @@ -1117,10 +1119,10 @@ pub mod pallet {
pub fn force_asset_status(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
owner: <T::Lookup as StaticLookup>::Source,
issuer: <T::Lookup as StaticLookup>::Source,
admin: <T::Lookup as StaticLookup>::Source,
freezer: <T::Lookup as StaticLookup>::Source,
owner: AccountIdLookupOf<T>,
issuer: AccountIdLookupOf<T>,
admin: AccountIdLookupOf<T>,
freezer: AccountIdLookupOf<T>,
#[pallet::compact] min_balance: T::Balance,
is_sufficient: bool,
is_frozen: bool,
Expand Down Expand Up @@ -1167,7 +1169,7 @@ pub mod pallet {
pub fn approve_transfer(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
delegate: <T::Lookup as StaticLookup>::Source,
delegate: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
Expand All @@ -1192,7 +1194,7 @@ pub mod pallet {
pub fn cancel_approval(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
delegate: <T::Lookup as StaticLookup>::Source,
delegate: AccountIdLookupOf<T>,
) -> DispatchResult {
let owner = ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
Expand Down Expand Up @@ -1225,8 +1227,8 @@ pub mod pallet {
pub fn force_cancel_approval(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
owner: <T::Lookup as StaticLookup>::Source,
delegate: <T::Lookup as StaticLookup>::Source,
owner: AccountIdLookupOf<T>,
delegate: AccountIdLookupOf<T>,
) -> DispatchResult {
let mut d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
T::ForceOrigin::try_origin(origin)
Expand Down Expand Up @@ -1272,8 +1274,8 @@ pub mod pallet {
pub fn transfer_approved(
origin: OriginFor<T>,
#[pallet::compact] id: T::AssetId,
owner: <T::Lookup as StaticLookup>::Source,
destination: <T::Lookup as StaticLookup>::Source,
owner: AccountIdLookupOf<T>,
destination: AccountIdLookupOf<T>,
#[pallet::compact] amount: T::Balance,
) -> DispatchResult {
let delegate = ensure_signed(origin)?;
Expand Down
12 changes: 9 additions & 3 deletions frame/bags-list/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ frame_benchmarking::benchmarks! {
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(),
Expand All @@ -69,7 +71,7 @@ frame_benchmarking::benchmarks! {
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!(
Expand Down Expand Up @@ -114,6 +116,8 @@ frame_benchmarking::benchmarks! {
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(),
Expand All @@ -126,7 +130,7 @@ frame_benchmarking::benchmarks! {
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!(
Expand Down Expand Up @@ -166,13 +170,15 @@ frame_benchmarking::benchmarks! {
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<_>>(),
Expand Down
16 changes: 13 additions & 3 deletions frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -222,8 +224,12 @@ 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)?;
Expand All @@ -239,8 +245,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)
Expand Down
Loading