Skip to content

Commit 200dd58

Browse files
aurexavjordy25519
authored andcommitted
ModuleId to PalletId - part of paritytech#8372 (paritytech#8477)
* `ModuleId` to `PalletId` - part of paritytech#8372 * fix doc * move `PalletId` to `frame-support` * fix compile * fix tests * `ModuleId` to `PalletId` * subcommand `moduleid` to `palletid`
1 parent bc82eb6 commit 200dd58

17 files changed

Lines changed: 206 additions & 167 deletions

File tree

bin/node/runtime/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use frame_system::{
4040
EnsureRoot, EnsureOneOf,
4141
limits::{BlockWeights, BlockLength}
4242
};
43-
use frame_support::traits::InstanceFilter;
43+
use frame_support::{traits::InstanceFilter, PalletId};
4444
use codec::{Encode, Decode};
4545
use sp_core::{
4646
crypto::KeyTypeId,
@@ -52,7 +52,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
5252
use sp_api::impl_runtime_apis;
5353
use sp_runtime::{
5454
Permill, Perbill, Perquintill, Percent, ApplyExtrinsicResult, impl_opaque_keys, generic,
55-
create_runtime_str, ModuleId, FixedPointNumber,
55+
create_runtime_str, FixedPointNumber,
5656
};
5757
use sp_runtime::curve::PiecewiseLinear;
5858
use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority};
@@ -634,15 +634,15 @@ parameter_types! {
634634
pub const TermDuration: BlockNumber = 7 * DAYS;
635635
pub const DesiredMembers: u32 = 13;
636636
pub const DesiredRunnersUp: u32 = 7;
637-
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
637+
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
638638
}
639639

640640
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
641641
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());
642642

643643
impl pallet_elections_phragmen::Config for Runtime {
644644
type Event = Event;
645-
type ModuleId = ElectionsPhragmenModuleId;
645+
type PalletId = ElectionsPhragmenPalletId;
646646
type Currency = Balances;
647647
type ChangeMembers = Council;
648648
// NOTE: this implies that council's genesis members cannot be set directly and must come from
@@ -705,15 +705,15 @@ parameter_types! {
705705
pub const DataDepositPerByte: Balance = 1 * CENTS;
706706
pub const BountyDepositBase: Balance = 1 * DOLLARS;
707707
pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;
708-
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
708+
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
709709
pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
710710
pub const MaximumReasonLength: u32 = 16384;
711711
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
712712
pub const BountyValueMinimum: Balance = 5 * DOLLARS;
713713
}
714714

715715
impl pallet_treasury::Config for Runtime {
716-
type ModuleId = TreasuryModuleId;
716+
type PalletId = TreasuryPalletId;
717717
type Currency = Balances;
718718
type ApproveOrigin = EnsureOneOf<
719719
AccountId,
@@ -970,12 +970,13 @@ parameter_types! {
970970
pub const PeriodSpend: Balance = 500 * DOLLARS;
971971
pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS;
972972
pub const ChallengePeriod: BlockNumber = 7 * DAYS;
973-
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
973+
pub const MaxCandidateIntake: u32 = 10;
974+
pub const SocietyPalletId: PalletId = PalletId(*b"py/socie");
974975
}
975976

976977
impl pallet_society::Config for Runtime {
977978
type Event = Event;
978-
type ModuleId = SocietyModuleId;
979+
type PalletId = SocietyPalletId;
979980
type Currency = Balances;
980981
type Randomness = RandomnessCollectiveFlip;
981982
type CandidateDeposit = CandidateDeposit;
@@ -1012,13 +1013,13 @@ impl pallet_mmr::Config for Runtime {
10121013
}
10131014

10141015
parameter_types! {
1015-
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto");
1016+
pub const LotteryPalletId: PalletId = PalletId(*b"py/lotto");
10161017
pub const MaxCalls: usize = 10;
10171018
pub const MaxGenerateRandom: u32 = 10;
10181019
}
10191020

10201021
impl pallet_lottery::Config for Runtime {
1021-
type ModuleId = LotteryModuleId;
1022+
type PalletId = LotteryPalletId;
10221023
type Call = Call;
10231024
type Event = Event;
10241025
type Currency = Balances;

frame/bounties/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,14 @@ impl<T: Config> Module<T> {
670670
/// This actually does computation. If you need to keep using it, then make sure you cache the
671671
/// value and only call this once.
672672
pub fn account_id() -> T::AccountId {
673-
T::ModuleId::get().into_account()
673+
T::PalletId::get().into_account()
674674
}
675675

676676
/// The account ID of a bounty account
677677
pub fn bounty_account_id(id: BountyIndex) -> T::AccountId {
678678
// only use two byte prefix to support 16 byte account id (used by test)
679679
// "modl" ++ "py/trsry" ++ "bt" is 14 bytes, and two bytes remaining for bounty index
680-
T::ModuleId::get().into_sub_account(("bt", id))
680+
T::PalletId::get().into_sub_account(("bt", id))
681681
}
682682

683683
fn create_bounty(

frame/bounties/src/tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ use super::*;
2424
use std::cell::RefCell;
2525

2626
use frame_support::{
27-
assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize
27+
assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize,
28+
PalletId
2829
};
2930

3031
use sp_core::H256;
3132
use sp_runtime::{
32-
Perbill, ModuleId,
33+
Perbill,
3334
testing::Header,
3435
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
3536
};
@@ -102,12 +103,12 @@ parameter_types! {
102103
pub const SpendPeriod: u64 = 2;
103104
pub const Burn: Permill = Permill::from_percent(50);
104105
pub const DataDepositPerByte: u64 = 1;
105-
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
106+
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
106107
}
107108
// impl pallet_treasury::Config for Test {
108109
impl pallet_treasury::Config for Test {
109-
type ModuleId = TreasuryModuleId;
110-
type Currency = pallet_balances::Module<Test>;
110+
type PalletId = TreasuryPalletId;
111+
type Currency = pallet_balances::Pallet<Test>;
111112
type ApproveOrigin = frame_system::EnsureRoot<u128>;
112113
type RejectOrigin = frame_system::EnsureRoot<u128>;
113114
type Event = Event;

frame/elections-phragmen/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub trait Config: frame_system::Config {
175175
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
176176

177177
/// Identifier for the elections-phragmen pallet's lock
178-
type ModuleId: Get<LockIdentifier>;
178+
type PalletId: Get<LockIdentifier>;
179179

180180
/// The currency that people are electing with.
181181
type Currency:
@@ -375,7 +375,7 @@ decl_module! {
375375
const DesiredMembers: u32 = T::DesiredMembers::get();
376376
const DesiredRunnersUp: u32 = T::DesiredRunnersUp::get();
377377
const TermDuration: T::BlockNumber = T::TermDuration::get();
378-
const ModuleId: LockIdentifier = T::ModuleId::get();
378+
const PalletId: LockIdentifier = T::PalletId::get();
379379

380380
/// Vote for a set of candidates for the upcoming round of election. This can be called to
381381
/// set the initial votes, or update already existing votes.
@@ -452,7 +452,7 @@ decl_module! {
452452
// Amount to be locked up.
453453
let locked_stake = value.min(T::Currency::total_balance(&who));
454454
T::Currency::set_lock(
455-
T::ModuleId::get(),
455+
T::PalletId::get(),
456456
&who,
457457
locked_stake,
458458
WithdrawReasons::all(),
@@ -807,7 +807,7 @@ impl<T: Config> Module<T> {
807807
let Voter { deposit, .. } = <Voting<T>>::take(who);
808808

809809
// remove storage, lock and unreserve.
810-
T::Currency::remove_lock(T::ModuleId::get(), who);
810+
T::Currency::remove_lock(T::PalletId::get(), who);
811811

812812
// NOTE: we could check the deposit amount before removing and skip if zero, but it will be
813813
// a noop anyhow.
@@ -1157,11 +1157,11 @@ mod tests {
11571157
}
11581158

11591159
parameter_types! {
1160-
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
1160+
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
11611161
}
11621162

11631163
impl Config for Test {
1164-
type ModuleId = ElectionsPhragmenModuleId;
1164+
type PalletId = ElectionsPhragmenPalletId;
11651165
type Event = Event;
11661166
type Currency = Balances;
11671167
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
@@ -1313,7 +1313,7 @@ mod tests {
13131313
.get(0)
13141314
.cloned()
13151315
.map(|lock| {
1316-
assert_eq!(lock.id, ElectionsPhragmenModuleId::get());
1316+
assert_eq!(lock.id, ElectionsPhragmenPalletId::get());
13171317
lock.amount
13181318
})
13191319
.unwrap_or_default()

frame/elections/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub trait Config: frame_system::Config {
156156
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
157157

158158
/// Identifier for the elections pallet's lock
159-
type ModuleId: Get<LockIdentifier>;
159+
type PalletId: Get<LockIdentifier>;
160160

161161
/// The currency that people are electing with.
162162
type Currency:
@@ -391,7 +391,7 @@ decl_module! {
391391
/// The chunk size of the approval vector.
392392
const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32;
393393

394-
const ModuleId: LockIdentifier = T::ModuleId::get();
394+
const PalletId: LockIdentifier = T::PalletId::get();
395395

396396
fn deposit_event() = default;
397397

@@ -491,7 +491,7 @@ decl_module! {
491491
);
492492

493493
T::Currency::remove_lock(
494-
T::ModuleId::get(),
494+
T::PalletId::get(),
495495
if valid { &who } else { &reporter }
496496
);
497497

@@ -529,7 +529,7 @@ decl_module! {
529529

530530
Self::remove_voter(&who, index);
531531
T::Currency::unreserve(&who, T::VotingBond::get());
532-
T::Currency::remove_lock(T::ModuleId::get(), &who);
532+
T::Currency::remove_lock(T::PalletId::get(), &who);
533533
}
534534

535535
/// Submit oneself for candidacy.
@@ -890,7 +890,7 @@ impl<T: Config> Module<T> {
890890
}
891891

892892
T::Currency::set_lock(
893-
T::ModuleId::get(),
893+
T::PalletId::get(),
894894
&who,
895895
locked_balance,
896896
WithdrawReasons::all(),

frame/elections/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl ChangeMembers<u64> for TestChangeMembers {
102102
}
103103

104104
parameter_types!{
105-
pub const ElectionModuleId: LockIdentifier = *b"py/elect";
105+
pub const ElectionPalletId: LockIdentifier = *b"py/elect";
106106
}
107107

108108
impl elections::Config for Test {
@@ -122,7 +122,7 @@ impl elections::Config for Test {
122122
type InactiveGracePeriod = InactiveGracePeriod;
123123
type VotingPeriod = VotingPeriod;
124124
type DecayRatio = DecayRatio;
125-
type ModuleId = ElectionModuleId;
125+
type PalletId = ElectionPalletId;
126126
}
127127

128128
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;

frame/lottery/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub mod weights;
5656

5757
use sp_std::prelude::*;
5858
use sp_runtime::{
59-
DispatchError, ModuleId,
59+
DispatchError,
6060
traits::{AccountIdConversion, Saturating, Zero},
6161
};
6262
use frame_support::{
@@ -66,7 +66,7 @@ use frame_support::{
6666
Currency, ReservableCurrency, Get, EnsureOrigin, ExistenceRequirement::KeepAlive, Randomness,
6767
},
6868
};
69-
use frame_support::weights::Weight;
69+
use frame_support::{weights::Weight, PalletId};
7070
use frame_system::ensure_signed;
7171
use codec::{Encode, Decode};
7272
pub use weights::WeightInfo;
@@ -76,7 +76,7 @@ type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Con
7676
/// The module's config trait.
7777
pub trait Config: frame_system::Config {
7878
/// The Lottery's module id
79-
type ModuleId: Get<ModuleId>;
79+
type PalletId: Get<PalletId>;
8080

8181
/// A dispatchable call.
8282
type Call: Parameter + Dispatchable<Origin=Self::Origin> + GetDispatchInfo + From<frame_system::Call<Self>>;
@@ -209,7 +209,9 @@ decl_error! {
209209

210210
decl_module! {
211211
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = frame_system {
212-
const ModuleId: ModuleId = T::ModuleId::get();
212+
type Error = Error<T>;
213+
214+
const PalletId: PalletId = T::PalletId::get();
213215
const MaxCalls: u32 = T::MaxCalls::get() as u32;
214216

215217
fn deposit_event() = default;
@@ -358,7 +360,7 @@ impl<T: Config> Module<T> {
358360
/// This actually does computation. If you need to keep using it, then make sure you cache the
359361
/// value and only call this once.
360362
pub fn account_id() -> T::AccountId {
361-
T::ModuleId::get().into_account()
363+
T::PalletId::get().into_account()
362364
}
363365

364366
/// Return the pot account and amount of money in the pot.
@@ -444,7 +446,7 @@ impl<T: Config> Module<T> {
444446
// You should call this function with different seed values until the random
445447
// number lies within `u32::MAX - u32::MAX % n`.
446448
fn generate_random_number(seed: u32) -> u32 {
447-
let random_seed = T::Randomness::random(&(T::ModuleId::get(), seed).encode());
449+
let (random_seed, _) = T::Randomness::random(&(T::PalletId::get(), seed).encode());
448450
let random_number = <u32>::decode(&mut random_seed.as_ref())
449451
.expect("secure hashes should always be bigger than u32; qed");
450452
random_number

frame/lottery/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ impl pallet_balances::Config for Test {
9494
}
9595

9696
parameter_types! {
97-
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto");
97+
pub const LotteryPalletId: PalletId = PalletId(*b"py/lotto");
9898
pub const MaxCalls: usize = 2;
9999
pub const MaxGenerateRandom: u32 = 10;
100100
}
101101

102102
impl Config for Test {
103-
type ModuleId = LotteryModuleId;
103+
type PalletId = LotteryPalletId;
104104
type Call = Call;
105105
type Currency = Balances;
106106
type Randomness = TestRandomness;

frame/society/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ mod tests;
254254
use rand_chacha::{rand_core::{RngCore, SeedableRng}, ChaChaRng};
255255
use sp_std::prelude::*;
256256
use codec::{Encode, Decode};
257-
use sp_runtime::{Percent, ModuleId, RuntimeDebug,
257+
use sp_runtime::{Percent, RuntimeDebug,
258258
traits::{
259259
StaticLookup, AccountIdConversion, Saturating, Zero, IntegerSquareRoot, Hash,
260260
TrailingZeroInput, CheckedSub
261261
}
262262
};
263-
use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult};
263+
use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult, PalletId};
264264
use frame_support::weights::Weight;
265265
use frame_support::traits::{
266266
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
@@ -277,7 +277,7 @@ pub trait Config<I=DefaultInstance>: system::Config {
277277
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;
278278

279279
/// The societies's module id
280-
type ModuleId: Get<ModuleId>;
280+
type PalletId: Get<PalletId>;
281281

282282
/// The currency type used for bidding.
283283
type Currency: ReservableCurrency<Self::AccountId>;
@@ -495,7 +495,7 @@ decl_module! {
495495
const ChallengePeriod: T::BlockNumber = T::ChallengePeriod::get();
496496

497497
/// The societies's module id
498-
const ModuleId: ModuleId = T::ModuleId::get();
498+
const PalletId: PalletId = T::PalletId::get();
499499

500500
// Used for handling module events.
501501
fn deposit_event() = default;
@@ -1585,15 +1585,15 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
15851585
/// This actually does computation. If you need to keep using it, then make sure you cache the
15861586
/// value and only call this once.
15871587
pub fn account_id() -> T::AccountId {
1588-
T::ModuleId::get().into_account()
1588+
T::PalletId::get().into_account()
15891589
}
15901590

15911591
/// The account ID of the payouts pot. This is where payouts are made from.
15921592
///
15931593
/// This actually does computation. If you need to keep using it, then make sure you cache the
15941594
/// value and only call this once.
15951595
pub fn payouts() -> T::AccountId {
1596-
T::ModuleId::get().into_sub_account(b"payouts")
1596+
T::PalletId::get().into_sub_account(b"payouts")
15971597
}
15981598

15991599
/// Return the duration of the lock, in blocks, with the given number of members.

0 commit comments

Comments
 (0)