Skip to content

Commit

Permalink
Use 'Pallet' instead of 'Module' for FRAME v1 pallets too.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium committed Dec 20, 2024
1 parent fe0f489 commit fe791f0
Show file tree
Hide file tree
Showing 92 changed files with 550 additions and 550 deletions.
74 changes: 37 additions & 37 deletions pallets/asset/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn register_metadata_global_name<T: Config>() -> AssetMetadataKey {
let name = make_metadata_name::<T>();
let spec = make_metadata_spec::<T>();

Module::<T>::register_asset_metadata_global_type(root, name, spec).unwrap();
Pallet::<T>::register_asset_metadata_global_type(root, name, spec).unwrap();

let key = Module::<T>::current_asset_metadata_global_key().unwrap();
let key = Pallet::<T>::current_asset_metadata_global_key().unwrap();
AssetMetadataKey::Global(key)
}

Expand All @@ -105,8 +105,8 @@ pub(crate) fn create_sample_asset<T: Config>(asset_owner: &User<T>, divisible: b
let asset_identifiers = (0..MAX_IDENTIFIERS_PER_ASSET)
.map(|_| AssetIdentifier::cusip(*b"17275R102").unwrap())
.collect();
let asset_id = Module::<T>::generate_asset_id(asset_owner.account(), false);
Module::<T>::create_asset(
let asset_id = Pallet::<T>::generate_asset_id(asset_owner.account(), false);
Pallet::<T>::create_asset(
asset_owner.origin.clone().into(),
asset_name,
divisible,
Expand All @@ -121,7 +121,7 @@ pub(crate) fn create_sample_asset<T: Config>(asset_owner: &User<T>, divisible: b

pub(crate) fn create_and_issue_sample_asset<T: Config>(asset_owner: &User<T>) -> AssetId {
let asset_id = create_sample_asset::<T>(asset_owner, true);
Module::<T>::issue(
Pallet::<T>::issue(
asset_owner.origin().into(),
asset_id,
(1_000_000 * POLY).into(),
Expand Down Expand Up @@ -167,7 +167,7 @@ where
mediator.did()
})
.collect();
Module::<T>::add_mandatory_mediators(
Pallet::<T>::add_mandatory_mediators(
sender.origin().into(),
asset_id,
mediators_identity.try_into().unwrap(),
Expand Down Expand Up @@ -259,7 +259,7 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");

let ticker = reg_unique_ticker::<T>(alice.account(), None);
let new_owner_auth_id = pallet_identity::Module::<T>::add_auth(
let new_owner_auth_id = pallet_identity::Pallet::<T>::add_auth(
alice.did(),
Signatory::from(bob.did()),
AuthorizationData::TransferTicker(ticker),
Expand Down Expand Up @@ -288,9 +288,9 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
let ticker = reg_unique_ticker::<T>(alice.account(), None);
Module::<T>::link_ticker_to_asset_id(alice.origin().into(), ticker, asset_id).unwrap();
Pallet::<T>::link_ticker_to_asset_id(alice.origin().into(), ticker, asset_id).unwrap();

let new_owner_auth_id = pallet_identity::Module::<T>::add_auth(
let new_owner_auth_id = pallet_identity::Pallet::<T>::add_auth(
alice.did(),
Signatory::from(bob.did()),
AuthorizationData::TransferAssetOwnership(asset_id),
Expand Down Expand Up @@ -327,7 +327,7 @@ benchmarks! {
let asset_identifiers: Vec<AssetIdentifier> = (0..i)
.map(|_| AssetIdentifier::cusip(*b"17275R102").unwrap())
.collect();
let asset_id = Module::<T>::generate_asset_id(alice.account(), false);
let asset_id = Pallet::<T>::generate_asset_id(alice.account(), false);
}: _(alice.origin.clone(), asset_name.clone(), true, AssetType::default(), asset_identifiers.clone(), Some(funding_round_name.clone()))
verify {
assert_eq!(
Expand Down Expand Up @@ -363,7 +363,7 @@ benchmarks! {
unfreeze {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
Module::<T>::freeze(alice.origin().into(), asset_id).unwrap();
Pallet::<T>::freeze(alice.origin().into(), asset_id).unwrap();
}: _(alice.origin, asset_id)
verify {
assert_eq!(Frozen::get(&asset_id), false);
Expand Down Expand Up @@ -398,7 +398,7 @@ benchmarks! {
let asset_id = create_sample_asset::<T>(&alice, true);
let portfolio_id = create_portfolio::<T>(&alice, "MyPortfolio");

Module::<T>::issue(
Pallet::<T>::issue(
alice.origin.clone().into(),
asset_id,
(1_000_000 * POLY).into(),
Expand Down Expand Up @@ -434,7 +434,7 @@ benchmarks! {
verify {
for i in 1..d {
assert_eq!(
Module::<T>::asset_documents(asset_id, DocumentId(i)).unwrap(),
Pallet::<T>::asset_documents(asset_id, DocumentId(i)).unwrap(),
docs[i as usize]
);
}
Expand All @@ -446,7 +446,7 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
let docs = iter::repeat(make_document()).take(d as usize).collect::<Vec<_>>();
Module::<T>::add_documents(alice.origin().into(), docs.clone(), asset_id).unwrap();
Pallet::<T>::add_documents(alice.origin().into(), docs.clone(), asset_id).unwrap();

let remove_doc_ids = (1..d).map(|i| DocumentId(i - 1)).collect::<Vec<_>>();
}: _(alice.origin, remove_doc_ids, asset_id)
Expand Down Expand Up @@ -495,26 +495,26 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);

Module::<T>::issue(
Pallet::<T>::issue(
alice.origin.clone().into(),
asset_id,
1_000_000,
PortfolioKind::Default
)
.unwrap();

let auth_id = pallet_identity::Module::<T>::add_auth(
let auth_id = pallet_identity::Pallet::<T>::add_auth(
alice.did(),
Signatory::from(bob.did()),
AuthorizationData::BecomeAgent(asset_id, AgentGroup::Full),
None,
)
.unwrap();
pallet_external_agents::Module::<T>::accept_become_agent(bob.origin().into(), auth_id)?;
pallet_external_agents::Pallet::<T>::accept_become_agent(bob.origin().into(), auth_id)?;
}: _(bob.origin.clone(), asset_id, 1_000, PortfolioId::default_portfolio(alice.did()))
verify {
assert_eq!(
Module::<T>::balance_of(asset_id, bob.did()),
Pallet::<T>::balance_of(asset_id, bob.did()),
1_000
);
}
Expand All @@ -524,10 +524,10 @@ benchmarks! {

let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let ty = vec![b'X'; n as usize];
assert_eq!(Module::<T>::custom_type_id_seq(), CustomAssetTypeId(0));
assert_eq!(Pallet::<T>::custom_type_id_seq(), CustomAssetTypeId(0));
}: _(alice.origin, ty)
verify {
assert_eq!(Module::<T>::custom_type_id_seq(), CustomAssetTypeId(1));
assert_eq!(Pallet::<T>::custom_type_id_seq(), CustomAssetTypeId(1));
}

set_asset_metadata {
Expand Down Expand Up @@ -582,8 +582,8 @@ benchmarks! {
// Creates an asset of type NFT
let user = user::<T>("target", 0);
let asset_name = AssetName::from(b"MyAsset");
let asset_id = Module::<T>::generate_asset_id(user.account(), false);
Module::<T>::create_asset(
let asset_id = Pallet::<T>::generate_asset_id(user.account(), false);
Pallet::<T>::create_asset(
user.origin().into(),
asset_name,
false,
Expand All @@ -599,13 +599,13 @@ benchmarks! {
description: None,
type_def: None,
};
Module::<T>::register_asset_metadata_local_type(
Pallet::<T>::register_asset_metadata_local_type(
user.origin().into(),
asset_id,
asset_metadata_name.clone(),
asset_metadata_spec.clone()
).unwrap();
Module::<T>::register_asset_metadata_local_type(
Pallet::<T>::register_asset_metadata_local_type(
user.origin().into(),
asset_id,
AssetMetadataName(b"mylocalkey2".to_vec()),
Expand All @@ -620,8 +620,8 @@ benchmarks! {
// Creates an asset of type NFT
let user = user::<T>("target", 0);
let asset_name = AssetName::from(b"MyAsset");
let asset_id = Module::<T>::generate_asset_id(user.account(), false);
Module::<T>::create_asset(
let asset_id = Pallet::<T>::generate_asset_id(user.account(), false);
Pallet::<T>::create_asset(
user.origin().into(),
asset_name,
false,
Expand All @@ -636,13 +636,13 @@ benchmarks! {
description: None,
type_def: None,
};
Module::<T>::register_asset_metadata_local_type(
Pallet::<T>::register_asset_metadata_local_type(
user.origin().into(),
asset_id,
asset_metadata_name.clone(),
asset_metadata_spec.clone()
).unwrap();
Module::<T>::set_asset_metadata(
Pallet::<T>::set_asset_metadata(
user.origin().into(),
asset_id,
AssetMetadataKey::Local(AssetMetadataLocalKey(1)),
Expand All @@ -664,7 +664,7 @@ benchmarks! {
let (sender_portfolio, receiver_portfolio, _, asset_id) =
setup_asset_transfer::<T>(&alice, &bob, None, None, true, true, 0);
}: {
Module::<T>::base_transfer(
Pallet::<T>::base_transfer(
sender_portfolio,
receiver_portfolio,
asset_id,
Expand All @@ -685,7 +685,7 @@ benchmarks! {
remove_asset_affirmation_exemption {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
Module::<T>::exempt_asset_affirmation(RawOrigin::Root.into(), asset_id).unwrap();
Pallet::<T>::exempt_asset_affirmation(RawOrigin::Root.into(), asset_id).unwrap();
}: _(RawOrigin::Root, asset_id)

pre_approve_asset {
Expand All @@ -696,7 +696,7 @@ benchmarks! {
remove_asset_pre_approval {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
Module::<T>::pre_approve_asset(alice.clone().origin().into(), asset_id).unwrap();
Pallet::<T>::pre_approve_asset(alice.clone().origin().into(), asset_id).unwrap();
}: _(alice.origin, asset_id)

add_mandatory_mediators {
Expand All @@ -705,8 +705,8 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let mediators: BTreeSet<IdentityId> = (0..n).map(|i| IdentityId::from(i as u128)).collect();

let asset_id = Module::<T>::generate_asset_id(alice.account(), false);
Module::<T>::create_asset(
let asset_id = Pallet::<T>::generate_asset_id(alice.account(), false);
Pallet::<T>::create_asset(
alice.clone().origin().into(),
AssetName::from(b"MyAsset"),
false,
Expand All @@ -724,8 +724,8 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let mediators: BTreeSet<IdentityId> = (0..n).map(|i| IdentityId::from(i as u128)).collect();

let asset_id = Module::<T>::generate_asset_id(alice.account(), false);
Module::<T>::create_asset(
let asset_id = Pallet::<T>::generate_asset_id(alice.account(), false);
Pallet::<T>::create_asset(
alice.clone().origin().into(),
AssetName::from(b"MyAsset"),
false,
Expand All @@ -735,7 +735,7 @@ benchmarks! {
)
.unwrap();

Module::<T>::add_mandatory_mediators(
Pallet::<T>::add_mandatory_mediators(
alice.clone().origin().into(),
asset_id,
mediators.clone().try_into().unwrap()
Expand All @@ -755,7 +755,7 @@ benchmarks! {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let asset_id = create_sample_asset::<T>(&alice, true);
let ticker = reg_unique_ticker::<T>(alice.account(), None);
Module::<T>::link_ticker_to_asset_id(
Pallet::<T>::link_ticker_to_asset_id(
alice.clone().origin().into(),
ticker,
asset_id
Expand Down
16 changes: 8 additions & 8 deletions pallets/asset/src/checkpoint/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn init_with_existing<T: Config>(asset_owner: &User<T>, existing: u64) -> AssetI

for n in 0..existing {
let schedule = ScheduleCheckpoints::new(CP_BASE + n);
Module::<T>::create_schedule(asset_owner.origin.clone().into(), asset_id, schedule)
Pallet::<T>::create_schedule(asset_owner.origin.clone().into(), asset_id, schedule)
.unwrap();
}

Expand All @@ -39,7 +39,7 @@ fn init_with_existing<T: Config>(asset_owner: &User<T>, existing: u64) -> AssetI
benchmarks! {
set_schedules_max_complexity {}: _(RawOrigin::Root, 7)
verify {
assert_eq!(Module::<T>::schedules_max_complexity(), 7)
assert_eq!(Pallet::<T>::schedules_max_complexity(), 7)
}

create_checkpoint {
Expand All @@ -48,38 +48,38 @@ benchmarks! {
let asset_id = create_sample_asset::<T>(&alice, true);
}: _(alice.origin, asset_id)
verify {
assert_eq!(Module::<T>::checkpoint_id_sequence(asset_id), CheckpointId(1))
assert_eq!(Pallet::<T>::checkpoint_id_sequence(asset_id), CheckpointId(1))
}

create_schedule {
<pallet_timestamp::Now<T>>::set(1000u32.into());
let alice = UserBuilder::<T>::default().generate_did().build("Alice");

let max = Module::<T>::schedules_max_complexity();
let max = Pallet::<T>::schedules_max_complexity();
let schedule = ScheduleCheckpoints::new_checkpoints(
(0..max).into_iter().map(|n| CP_BASE + n).collect()
);

// Must fit in the max complexity.
Module::<T>::set_schedules_max_complexity(
Pallet::<T>::set_schedules_max_complexity(
RawOrigin::Root.into(),
10 * max
).unwrap();

let asset_id = init_with_existing::<T>(&alice, max);
}: _(alice.origin, asset_id, schedule)
verify {
assert_eq!(Module::<T>::schedule_id_sequence(asset_id), ScheduleId(max + 1))
assert_eq!(Pallet::<T>::schedule_id_sequence(asset_id), ScheduleId(max + 1))
}

remove_schedule {
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
let max = Module::<T>::schedules_max_complexity();
let max = Pallet::<T>::schedules_max_complexity();

let id = ScheduleId(max);
let asset_id = init_with_existing::<T>(&alice, max);
}: _(alice.origin, asset_id, id)
verify {
assert_eq!(Module::<T>::scheduled_checkpoints(asset_id, id), None);
assert_eq!(Pallet::<T>::scheduled_checkpoints(asset_id, id), None);
}
}
10 changes: 5 additions & 5 deletions pallets/asset/src/checkpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ use polymesh_primitives::{storage_migration_ver, IdentityId, Moment};

use crate::Config;

type Asset<T> = crate::Module<T>;
type ExternalAgents<T> = pallet_external_agents::Module<T>;
type Asset<T> = crate::Pallet<T>;
type ExternalAgents<T> = pallet_external_agents::Pallet<T>;

storage_migration_ver!(2);

Expand Down Expand Up @@ -101,7 +101,7 @@ decl_event! {
}

decl_storage! {
trait Store for Module<T: Config> as Checkpoint {
trait Store for Pallet<T: Config> as Checkpoint {
// --------------------- Supply / Balance storage ----------------------

/// Total supply of the token at the checkpoint.
Expand Down Expand Up @@ -282,7 +282,7 @@ decl_module! {
}

decl_error! {
pub enum Error for Module<T: Config> {
pub enum Error for Pallet<T: Config> {
/// A checkpoint schedule does not exist for the asset.
NoSuchSchedule,
/// A checkpoint schedule is not removable as `ref_count(schedule_id) > 0`.
Expand All @@ -298,7 +298,7 @@ decl_error! {
}
}

impl<T: Config> Module<T> {
impl<T: Config> Pallet<T> {
/// Does checkpoint with ID `cp_id` exist for `asset_id`?
pub fn checkpoint_exists(asset_id: &AssetId, cp: CheckpointId) -> bool {
cp > CheckpointId(0) && cp <= CheckpointIdSequence::get(asset_id)
Expand Down
4 changes: 2 additions & 2 deletions pallets/asset/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use frame_support::decl_error;

use crate::{Config, Module};
use crate::{Config, Pallet};

decl_error! {
pub enum Error for Module<T: Config> {
pub enum Error for Pallet<T: Config> {
/// The user is not authorized.
Unauthorized,
/// The token has already been created.
Expand Down
Loading

0 comments on commit fe791f0

Please sign in to comment.