ModuleId to PalletId - part of #8372 (#8477)

* `ModuleId` to `PalletId` - part of #8372

* fix doc

* move `PalletId` to `frame-support`

* fix compile

* fix tests

* `ModuleId` to `PalletId`

* subcommand `moduleid` to `palletid`
This commit is contained in:
Xavier Lau
2021-04-09 17:15:40 +08:00
committed by GitHub
parent c675310227
commit d6f0ce0551
20 changed files with 92 additions and 80 deletions
+1
View File
@@ -9411,6 +9411,7 @@ dependencies = [
name = "substrate-frame-cli" name = "substrate-frame-cli"
version = "3.0.0" version = "3.0.0"
dependencies = [ dependencies = [
"frame-support",
"frame-system", "frame-system",
"sc-cli", "sc-cli",
"sp-core", "sp-core",
+10 -10
View File
@@ -40,7 +40,7 @@ use frame_system::{
EnsureRoot, EnsureOneOf, EnsureRoot, EnsureOneOf,
limits::{BlockWeights, BlockLength} limits::{BlockWeights, BlockLength}
}; };
use frame_support::traits::InstanceFilter; use frame_support::{traits::InstanceFilter, PalletId};
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_core::{ use sp_core::{
crypto::KeyTypeId, crypto::KeyTypeId,
@@ -52,7 +52,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use sp_api::impl_runtime_apis; use sp_api::impl_runtime_apis;
use sp_runtime::{ use sp_runtime::{
Permill, Perbill, Perquintill, Percent, ApplyExtrinsicResult, impl_opaque_keys, generic, Permill, Perbill, Perquintill, Percent, ApplyExtrinsicResult, impl_opaque_keys, generic,
create_runtime_str, ModuleId, FixedPointNumber, create_runtime_str, FixedPointNumber,
}; };
use sp_runtime::curve::PiecewiseLinear; use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}; use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority};
@@ -634,7 +634,7 @@ parameter_types! {
pub const TermDuration: BlockNumber = 7 * DAYS; pub const TermDuration: BlockNumber = 7 * DAYS;
pub const DesiredMembers: u32 = 13; pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 7; pub const DesiredRunnersUp: u32 = 7;
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect"; pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
} }
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen. // Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
@@ -642,7 +642,7 @@ const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());
impl pallet_elections_phragmen::Config for Runtime { impl pallet_elections_phragmen::Config for Runtime {
type Event = Event; type Event = Event;
type ModuleId = ElectionsPhragmenModuleId; type PalletId = ElectionsPhragmenPalletId;
type Currency = Balances; type Currency = Balances;
type ChangeMembers = Council; type ChangeMembers = Council;
// NOTE: this implies that council's genesis members cannot be set directly and must come from // NOTE: this implies that council's genesis members cannot be set directly and must come from
@@ -705,7 +705,7 @@ parameter_types! {
pub const DataDepositPerByte: Balance = 1 * CENTS; pub const DataDepositPerByte: Balance = 1 * CENTS;
pub const BountyDepositBase: Balance = 1 * DOLLARS; pub const BountyDepositBase: Balance = 1 * DOLLARS;
pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS; pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry"); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
pub const MaximumReasonLength: u32 = 16384; pub const MaximumReasonLength: u32 = 16384;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
@@ -713,7 +713,7 @@ parameter_types! {
} }
impl pallet_treasury::Config for Runtime { impl pallet_treasury::Config for Runtime {
type ModuleId = TreasuryModuleId; type PalletId = TreasuryPalletId;
type Currency = Balances; type Currency = Balances;
type ApproveOrigin = EnsureOneOf< type ApproveOrigin = EnsureOneOf<
AccountId, AccountId,
@@ -970,12 +970,12 @@ parameter_types! {
pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS; pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS;
pub const ChallengePeriod: BlockNumber = 7 * DAYS; pub const ChallengePeriod: BlockNumber = 7 * DAYS;
pub const MaxCandidateIntake: u32 = 10; pub const MaxCandidateIntake: u32 = 10;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie"); pub const SocietyPalletId: PalletId = PalletId(*b"py/socie");
} }
impl pallet_society::Config for Runtime { impl pallet_society::Config for Runtime {
type Event = Event; type Event = Event;
type ModuleId = SocietyModuleId; type PalletId = SocietyPalletId;
type Currency = Balances; type Currency = Balances;
type Randomness = RandomnessCollectiveFlip; type Randomness = RandomnessCollectiveFlip;
type CandidateDeposit = CandidateDeposit; type CandidateDeposit = CandidateDeposit;
@@ -1013,13 +1013,13 @@ impl pallet_mmr::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto"); pub const LotteryPalletId: PalletId = PalletId(*b"py/lotto");
pub const MaxCalls: usize = 10; pub const MaxCalls: usize = 10;
pub const MaxGenerateRandom: u32 = 10; pub const MaxGenerateRandom: u32 = 10;
} }
impl pallet_lottery::Config for Runtime { impl pallet_lottery::Config for Runtime {
type ModuleId = LotteryModuleId; type PalletId = LotteryPalletId;
type Call = Call; type Call = Call;
type Currency = Balances; type Currency = Balances;
type Randomness = RandomnessCollectiveFlip; type Randomness = RandomnessCollectiveFlip;
+2 -2
View File
@@ -677,14 +677,14 @@ impl<T: Config> Module<T> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn account_id() -> T::AccountId { pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account() T::PalletId::get().into_account()
} }
/// The account ID of a bounty account /// The account ID of a bounty account
pub fn bounty_account_id(id: BountyIndex) -> T::AccountId { pub fn bounty_account_id(id: BountyIndex) -> T::AccountId {
// only use two byte prefix to support 16 byte account id (used by test) // only use two byte prefix to support 16 byte account id (used by test)
// "modl" ++ "py/trsry" ++ "bt" is 14 bytes, and two bytes remaining for bounty index // "modl" ++ "py/trsry" ++ "bt" is 14 bytes, and two bytes remaining for bounty index
T::ModuleId::get().into_sub_account(("bt", id)) T::PalletId::get().into_sub_account(("bt", id))
} }
fn create_bounty( fn create_bounty(
+5 -4
View File
@@ -24,12 +24,13 @@ use super::*;
use std::cell::RefCell; use std::cell::RefCell;
use frame_support::{ use frame_support::{
assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize,
PalletId
}; };
use sp_core::H256; use sp_core::H256;
use sp_runtime::{ use sp_runtime::{
Perbill, ModuleId, Perbill,
testing::Header, testing::Header,
traits::{BlakeTwo256, IdentityLookup, BadOrigin}, traits::{BlakeTwo256, IdentityLookup, BadOrigin},
}; };
@@ -103,11 +104,11 @@ parameter_types! {
pub const SpendPeriod: u64 = 2; pub const SpendPeriod: u64 = 2;
pub const Burn: Permill = Permill::from_percent(50); pub const Burn: Permill = Permill::from_percent(50);
pub const DataDepositPerByte: u64 = 1; pub const DataDepositPerByte: u64 = 1;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry"); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
} }
// impl pallet_treasury::Config for Test { // impl pallet_treasury::Config for Test {
impl pallet_treasury::Config for Test { impl pallet_treasury::Config for Test {
type ModuleId = TreasuryModuleId; type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>; type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>; type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>; type RejectOrigin = frame_system::EnsureRoot<u128>;
@@ -175,7 +175,7 @@ pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>; type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Identifier for the elections-phragmen pallet's lock /// Identifier for the elections-phragmen pallet's lock
type ModuleId: Get<LockIdentifier>; type PalletId: Get<LockIdentifier>;
/// The currency that people are electing with. /// The currency that people are electing with.
type Currency: type Currency:
@@ -375,7 +375,7 @@ decl_module! {
const DesiredMembers: u32 = T::DesiredMembers::get(); const DesiredMembers: u32 = T::DesiredMembers::get();
const DesiredRunnersUp: u32 = T::DesiredRunnersUp::get(); const DesiredRunnersUp: u32 = T::DesiredRunnersUp::get();
const TermDuration: T::BlockNumber = T::TermDuration::get(); const TermDuration: T::BlockNumber = T::TermDuration::get();
const ModuleId: LockIdentifier = T::ModuleId::get(); const PalletId: LockIdentifier = T::PalletId::get();
/// Vote for a set of candidates for the upcoming round of election. This can be called to /// Vote for a set of candidates for the upcoming round of election. This can be called to
/// set the initial votes, or update already existing votes. /// set the initial votes, or update already existing votes.
@@ -452,7 +452,7 @@ decl_module! {
// Amount to be locked up. // Amount to be locked up.
let locked_stake = value.min(T::Currency::total_balance(&who)); let locked_stake = value.min(T::Currency::total_balance(&who));
T::Currency::set_lock( T::Currency::set_lock(
T::ModuleId::get(), T::PalletId::get(),
&who, &who,
locked_stake, locked_stake,
WithdrawReasons::all(), WithdrawReasons::all(),
@@ -807,7 +807,7 @@ impl<T: Config> Module<T> {
let Voter { deposit, .. } = <Voting<T>>::take(who); let Voter { deposit, .. } = <Voting<T>>::take(who);
// remove storage, lock and unreserve. // remove storage, lock and unreserve.
T::Currency::remove_lock(T::ModuleId::get(), who); T::Currency::remove_lock(T::PalletId::get(), who);
// NOTE: we could check the deposit amount before removing and skip if zero, but it will be // NOTE: we could check the deposit amount before removing and skip if zero, but it will be
// a noop anyhow. // a noop anyhow.
@@ -1158,11 +1158,11 @@ mod tests {
} }
parameter_types! { parameter_types! {
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect"; pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
} }
impl Config for Test { impl Config for Test {
type ModuleId = ElectionsPhragmenModuleId; type PalletId = ElectionsPhragmenPalletId;
type Event = Event; type Event = Event;
type Currency = Balances; type Currency = Balances;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
@@ -1313,7 +1313,7 @@ mod tests {
.get(0) .get(0)
.cloned() .cloned()
.map(|lock| { .map(|lock| {
assert_eq!(lock.id, ElectionsPhragmenModuleId::get()); assert_eq!(lock.id, ElectionsPhragmenPalletId::get());
lock.amount lock.amount
}) })
.unwrap_or_default() .unwrap_or_default()
+5 -5
View File
@@ -156,7 +156,7 @@ pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>; type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Identifier for the elections pallet's lock /// Identifier for the elections pallet's lock
type ModuleId: Get<LockIdentifier>; type PalletId: Get<LockIdentifier>;
/// The currency that people are electing with. /// The currency that people are electing with.
type Currency: type Currency:
@@ -391,7 +391,7 @@ decl_module! {
/// The chunk size of the approval vector. /// The chunk size of the approval vector.
const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32; const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32;
const ModuleId: LockIdentifier = T::ModuleId::get(); const PalletId: LockIdentifier = T::PalletId::get();
fn deposit_event() = default; fn deposit_event() = default;
@@ -491,7 +491,7 @@ decl_module! {
); );
T::Currency::remove_lock( T::Currency::remove_lock(
T::ModuleId::get(), T::PalletId::get(),
if valid { &who } else { &reporter } if valid { &who } else { &reporter }
); );
@@ -529,7 +529,7 @@ decl_module! {
Self::remove_voter(&who, index); Self::remove_voter(&who, index);
T::Currency::unreserve(&who, T::VotingBond::get()); T::Currency::unreserve(&who, T::VotingBond::get());
T::Currency::remove_lock(T::ModuleId::get(), &who); T::Currency::remove_lock(T::PalletId::get(), &who);
} }
/// Submit oneself for candidacy. /// Submit oneself for candidacy.
@@ -890,7 +890,7 @@ impl<T: Config> Module<T> {
} }
T::Currency::set_lock( T::Currency::set_lock(
T::ModuleId::get(), T::PalletId::get(),
&who, &who,
locked_balance, locked_balance,
WithdrawReasons::all(), WithdrawReasons::all(),
+2 -2
View File
@@ -103,7 +103,7 @@ impl ChangeMembers<u64> for TestChangeMembers {
} }
parameter_types!{ parameter_types!{
pub const ElectionModuleId: LockIdentifier = *b"py/elect"; pub const ElectionPalletId: LockIdentifier = *b"py/elect";
} }
impl elections::Config for Test { impl elections::Config for Test {
@@ -123,7 +123,7 @@ impl elections::Config for Test {
type InactiveGracePeriod = InactiveGracePeriod; type InactiveGracePeriod = InactiveGracePeriod;
type VotingPeriod = VotingPeriod; type VotingPeriod = VotingPeriod;
type DecayRatio = DecayRatio; type DecayRatio = DecayRatio;
type ModuleId = ElectionModuleId; type PalletId = ElectionPalletId;
} }
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>; pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
+6 -6
View File
@@ -56,7 +56,7 @@ pub mod weights;
use sp_std::prelude::*; use sp_std::prelude::*;
use sp_runtime::{ use sp_runtime::{
DispatchError, ModuleId, DispatchError,
traits::{AccountIdConversion, Saturating, Zero}, traits::{AccountIdConversion, Saturating, Zero},
}; };
use frame_support::{ use frame_support::{
@@ -66,7 +66,7 @@ use frame_support::{
Currency, ReservableCurrency, Get, EnsureOrigin, ExistenceRequirement::KeepAlive, Randomness, Currency, ReservableCurrency, Get, EnsureOrigin, ExistenceRequirement::KeepAlive, Randomness,
}, },
}; };
use frame_support::weights::Weight; use frame_support::{weights::Weight, PalletId};
use frame_system::ensure_signed; use frame_system::ensure_signed;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
pub use weights::WeightInfo; pub use weights::WeightInfo;
@@ -76,7 +76,7 @@ type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Con
/// The module's config trait. /// The module's config trait.
pub trait Config: frame_system::Config { pub trait Config: frame_system::Config {
/// The Lottery's module id /// The Lottery's module id
type ModuleId: Get<ModuleId>; type PalletId: Get<PalletId>;
/// A dispatchable call. /// A dispatchable call.
type Call: Parameter + Dispatchable<Origin=Self::Origin> + GetDispatchInfo + From<frame_system::Call<Self>>; type Call: Parameter + Dispatchable<Origin=Self::Origin> + GetDispatchInfo + From<frame_system::Call<Self>>;
@@ -211,7 +211,7 @@ decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = frame_system { pub struct Module<T: Config> for enum Call where origin: T::Origin, system = frame_system {
type Error = Error<T>; type Error = Error<T>;
const ModuleId: ModuleId = T::ModuleId::get(); const PalletId: PalletId = T::PalletId::get();
const MaxCalls: u32 = T::MaxCalls::get() as u32; const MaxCalls: u32 = T::MaxCalls::get() as u32;
fn deposit_event() = default; fn deposit_event() = default;
@@ -361,7 +361,7 @@ impl<T: Config> Module<T> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn account_id() -> T::AccountId { pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account() T::PalletId::get().into_account()
} }
/// Return the pot account and amount of money in the pot. /// Return the pot account and amount of money in the pot.
@@ -449,7 +449,7 @@ impl<T: Config> Module<T> {
// TODO: deal with randomness freshness // TODO: deal with randomness freshness
// https://github.com/paritytech/substrate/issues/8311 // https://github.com/paritytech/substrate/issues/8311
fn generate_random_number(seed: u32) -> u32 { fn generate_random_number(seed: u32) -> u32 {
let (random_seed, _) = T::Randomness::random(&(T::ModuleId::get(), seed).encode()); let (random_seed, _) = T::Randomness::random(&(T::PalletId::get(), seed).encode());
let random_number = <u32>::decode(&mut random_seed.as_ref()) let random_number = <u32>::decode(&mut random_seed.as_ref())
.expect("secure hashes should always be bigger than u32; qed"); .expect("secure hashes should always be bigger than u32; qed");
random_number random_number
+2 -2
View File
@@ -96,13 +96,13 @@ impl pallet_balances::Config for Test {
} }
parameter_types! { parameter_types! {
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto"); pub const LotteryPalletId: PalletId = PalletId(*b"py/lotto");
pub const MaxCalls: usize = 2; pub const MaxCalls: usize = 2;
pub const MaxGenerateRandom: u32 = 10; pub const MaxGenerateRandom: u32 = 10;
} }
impl Config for Test { impl Config for Test {
type ModuleId = LotteryModuleId; type PalletId = LotteryPalletId;
type Call = Call; type Call = Call;
type Currency = Balances; type Currency = Balances;
type Randomness = TestRandomness<Self>; type Randomness = TestRandomness<Self>;
+6 -6
View File
@@ -254,13 +254,13 @@ mod tests;
use rand_chacha::{rand_core::{RngCore, SeedableRng}, ChaChaRng}; use rand_chacha::{rand_core::{RngCore, SeedableRng}, ChaChaRng};
use sp_std::prelude::*; use sp_std::prelude::*;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_runtime::{Percent, ModuleId, RuntimeDebug, use sp_runtime::{Percent, RuntimeDebug,
traits::{ traits::{
StaticLookup, AccountIdConversion, Saturating, Zero, IntegerSquareRoot, Hash, StaticLookup, AccountIdConversion, Saturating, Zero, IntegerSquareRoot, Hash,
TrailingZeroInput, CheckedSub TrailingZeroInput, CheckedSub
} }
}; };
use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult}; use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult, PalletId};
use frame_support::weights::Weight; use frame_support::weights::Weight;
use frame_support::traits::{ use frame_support::traits::{
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus, Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
@@ -277,7 +277,7 @@ pub trait Config<I = DefaultInstance>: system::Config {
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>; type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;
/// The societies's module id /// The societies's module id
type ModuleId: Get<ModuleId>; type PalletId: Get<PalletId>;
/// The currency type used for bidding. /// The currency type used for bidding.
type Currency: ReservableCurrency<Self::AccountId>; type Currency: ReservableCurrency<Self::AccountId>;
@@ -498,7 +498,7 @@ decl_module! {
const ChallengePeriod: T::BlockNumber = T::ChallengePeriod::get(); const ChallengePeriod: T::BlockNumber = T::ChallengePeriod::get();
/// The societies's module id /// The societies's module id
const ModuleId: ModuleId = T::ModuleId::get(); const PalletId: PalletId = T::PalletId::get();
/// Maximum candidate intake per round. /// Maximum candidate intake per round.
const MaxCandidateIntake: u32 = T::MaxCandidateIntake::get(); const MaxCandidateIntake: u32 = T::MaxCandidateIntake::get();
@@ -1601,7 +1601,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn account_id() -> T::AccountId { pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account() T::PalletId::get().into_account()
} }
/// The account ID of the payouts pot. This is where payouts are made from. /// The account ID of the payouts pot. This is where payouts are made from.
@@ -1609,7 +1609,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn payouts() -> T::AccountId { pub fn payouts() -> T::AccountId {
T::ModuleId::get().into_sub_account(b"payouts") T::PalletId::get().into_sub_account(b"payouts")
} }
/// Return the duration of the lock, in blocks, with the given number of members. /// Return the duration of the lock, in blocks, with the given number of members.
+2 -2
View File
@@ -58,7 +58,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250; pub const BlockHashCount: u64 = 250;
pub const ExistentialDeposit: u64 = 1; pub const ExistentialDeposit: u64 = 1;
pub const MaxCandidateIntake: u32 = 10; pub const MaxCandidateIntake: u32 = 10;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie"); pub const SocietyPalletId: PalletId = PalletId(*b"py/socie");
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024); frame_system::limits::BlockWeights::simple_max(1024);
} }
@@ -119,7 +119,7 @@ impl Config for Test {
type SuspensionJudgementOrigin = EnsureSignedBy<SuspensionJudgementSetAccount, u128>; type SuspensionJudgementOrigin = EnsureSignedBy<SuspensionJudgementSetAccount, u128>;
type ChallengePeriod = ChallengePeriod; type ChallengePeriod = ChallengePeriod;
type MaxCandidateIntake = MaxCandidateIntake; type MaxCandidateIntake = MaxCandidateIntake;
type ModuleId = SocietyModuleId; type PalletId = SocietyPalletId;
} }
pub struct EnvBuilder { pub struct EnvBuilder {
+11
View File
@@ -80,6 +80,9 @@ pub use self::storage::{
pub use self::dispatch::{Parameter, Callable}; pub use self::dispatch::{Parameter, Callable};
pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable}; pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable};
use codec::{Encode, Decode};
use sp_runtime::TypeId;
/// A unified log target for support operations. /// A unified log target for support operations.
pub const LOG_TARGET: &'static str = "runtime::frame-support"; pub const LOG_TARGET: &'static str = "runtime::frame-support";
@@ -87,6 +90,14 @@ pub const LOG_TARGET: &'static str = "runtime::frame-support";
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum Never {} pub enum Never {}
/// A pallet identifier. These are per pallet and should be stored in a registry somewhere.
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
pub struct PalletId(pub [u8; 8]);
impl TypeId for PalletId {
const TYPE_ID: [u8; 4] = *b"modl";
}
/// Generate a new type alias for [`storage::types::value::StorageValue`], /// Generate a new type alias for [`storage::types::value::StorageValue`],
/// [`storage::types::value::StorageMap`] and [`storage::types::value::StorageDoubleMap`]. /// [`storage::types::value::StorageMap`] and [`storage::types::value::StorageDoubleMap`].
/// ///
+1 -1
View File
@@ -444,7 +444,7 @@ impl<T: Config> Module<T> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn account_id() -> T::AccountId { pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account() T::PalletId::get().into_account()
} }
/// Given a mutable reference to an `OpenTip`, insert the tip into it and check whether it /// Given a mutable reference to an `OpenTip`, insert the tip into it and check whether it
+8 -4
View File
@@ -22,11 +22,15 @@
use crate as tips; use crate as tips;
use super::*; use super::*;
use std::cell::RefCell; use std::cell::RefCell;
use frame_support::{assert_noop, assert_ok, parameter_types, weights::Weight, traits::Contains}; use frame_support::{
assert_noop, assert_ok, parameter_types,
weights::Weight, traits::Contains,
PalletId
};
use sp_runtime::Permill; use sp_runtime::Permill;
use sp_core::H256; use sp_core::H256;
use sp_runtime::{ use sp_runtime::{
Perbill, ModuleId, Perbill,
testing::Header, testing::Header,
traits::{BlakeTwo256, IdentityLookup, BadOrigin}, traits::{BlakeTwo256, IdentityLookup, BadOrigin},
}; };
@@ -121,11 +125,11 @@ parameter_types! {
pub const SpendPeriod: u64 = 2; pub const SpendPeriod: u64 = 2;
pub const Burn: Permill = Permill::from_percent(50); pub const Burn: Permill = Permill::from_percent(50);
pub const DataDepositPerByte: u64 = 1; pub const DataDepositPerByte: u64 = 1;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry"); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const MaximumReasonLength: u32 = 16384; pub const MaximumReasonLength: u32 = 16384;
} }
impl pallet_treasury::Config for Test { impl pallet_treasury::Config for Test {
type ModuleId = TreasuryModuleId; type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>; type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>; type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>; type RejectOrigin = frame_system::EnsureRoot<u128>;
+10 -7
View File
@@ -66,14 +66,17 @@ pub mod weights;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use sp_std::prelude::*; use sp_std::prelude::*;
use frame_support::{decl_module, decl_storage, decl_event, ensure, print, decl_error}; use frame_support::{decl_module, decl_storage, decl_event, ensure, print, decl_error, PalletId};
use frame_support::traits::{ use frame_support::traits::{
Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::KeepAlive, Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::KeepAlive,
ReservableCurrency, WithdrawReasons ReservableCurrency, WithdrawReasons
}; };
use sp_runtime::{Permill, ModuleId, RuntimeDebug, traits::{ use sp_runtime::{
Zero, StaticLookup, AccountIdConversion, Saturating Permill, RuntimeDebug,
}}; traits::{
Zero, StaticLookup, AccountIdConversion, Saturating
}
};
use frame_support::weights::{Weight, DispatchClass}; use frame_support::weights::{Weight, DispatchClass};
use frame_support::traits::EnsureOrigin; use frame_support::traits::EnsureOrigin;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
@@ -89,7 +92,7 @@ pub type NegativeImbalanceOf<T, I=DefaultInstance> =
pub trait Config<I=DefaultInstance>: frame_system::Config { pub trait Config<I=DefaultInstance>: frame_system::Config {
/// The treasury's module id, used for deriving its sovereign account ID. /// The treasury's module id, used for deriving its sovereign account ID.
type ModuleId: Get<ModuleId>; type PalletId: Get<PalletId>;
/// The staking balance. /// The staking balance.
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>; type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
@@ -246,7 +249,7 @@ decl_module! {
const Burn: Permill = T::Burn::get(); const Burn: Permill = T::Burn::get();
/// The treasury's module id, used for deriving its sovereign account ID. /// The treasury's module id, used for deriving its sovereign account ID.
const ModuleId: ModuleId = T::ModuleId::get(); const PalletId: PalletId = T::PalletId::get();
type Error = Error<T, I>; type Error = Error<T, I>;
@@ -346,7 +349,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
/// This actually does computation. If you need to keep using it, then make sure you cache the /// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once. /// value and only call this once.
pub fn account_id() -> T::AccountId { pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account() T::PalletId::get().into_account()
} }
/// The needed bond for a proposal whose spend is `value`. /// The needed bond for a proposal whose spend is `value`.
+3 -4
View File
@@ -24,12 +24,11 @@ use super::*;
use std::cell::RefCell; use std::cell::RefCell;
use frame_support::{ use frame_support::{
assert_noop, assert_ok, parameter_types, assert_noop, assert_ok, parameter_types,
traits::OnInitialize, traits::OnInitialize, PalletId
}; };
use sp_core::H256; use sp_core::H256;
use sp_runtime::{ use sp_runtime::{
ModuleId,
testing::Header, testing::Header,
traits::{BlakeTwo256, IdentityLookup}, traits::{BlakeTwo256, IdentityLookup},
}; };
@@ -99,13 +98,13 @@ parameter_types! {
pub const ProposalBondMinimum: u64 = 1; pub const ProposalBondMinimum: u64 = 1;
pub const SpendPeriod: u64 = 2; pub const SpendPeriod: u64 = 2;
pub const Burn: Permill = Permill::from_percent(50); pub const Burn: Permill = Permill::from_percent(50);
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry"); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const BountyUpdatePeriod: u32 = 20; pub const BountyUpdatePeriod: u32 = 20;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
pub const BountyValueMinimum: u64 = 1; pub const BountyValueMinimum: u64 = 1;
} }
impl Config for Test { impl Config for Test {
type ModuleId = TreasuryModuleId; type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>; type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>; type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>; type RejectOrigin = frame_system::EnsureRoot<u128>;
-8
View File
@@ -158,14 +158,6 @@ impl From<Justification> for Justifications {
use traits::{Verify, Lazy}; use traits::{Verify, Lazy};
/// A module identifier. These are per module and should be stored in a registry somewhere.
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
pub struct ModuleId(pub [u8; 8]);
impl TypeId for ModuleId {
const TYPE_ID: [u8; 4] = *b"modl";
}
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use serde::{Serialize, Deserialize, de::DeserializeOwned}; pub use serde::{Serialize, Deserialize, de::DeserializeOwned};
use crate::traits::IdentifyAccount; use crate::traits::IdentifyAccount;
@@ -16,6 +16,7 @@ sc-cli = { version = "0.9.0", path = "../../../client/cli" }
sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" } sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" }
structopt = "0.3.8" structopt = "0.3.8"
frame-system = { version = "3.0.0", path = "../../../frame/system" } frame-system = { version = "3.0.0", path = "../../../frame/system" }
frame-support = { version = "3.0.0", path = "../../../frame/support" }
[dev-dependencies] [dev-dependencies]
@@ -17,7 +17,7 @@
//! frame-system CLI utilities //! frame-system CLI utilities
mod module_id; mod pallet_id;
pub use module_id::ModuleIdCmd; pub use pallet_id::PalletIdCmd;
@@ -15,25 +15,25 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Implementation of the `moduleid` subcommand //! Implementation of the `palletid` subcommand
use sc_cli::{ use sc_cli::{
Error, utils::print_from_uri, CryptoSchemeFlag, Error, utils::print_from_uri, CryptoSchemeFlag,
OutputTypeFlag, KeystoreParams, with_crypto_scheme, OutputTypeFlag, KeystoreParams, with_crypto_scheme,
}; };
use sp_runtime::ModuleId;
use sp_runtime::traits::AccountIdConversion; use sp_runtime::traits::AccountIdConversion;
use sp_core::crypto::{Ss58Codec, Ss58AddressFormat}; use sp_core::crypto::{Ss58Codec, Ss58AddressFormat};
use std::convert::{TryInto, TryFrom}; use std::convert::{TryInto, TryFrom};
use structopt::StructOpt; use structopt::StructOpt;
use frame_support::PalletId;
/// The `moduleid` command /// The `palletid` command
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt( #[structopt(
name = "moduleid", name = "palletid",
about = "Inspect a module ID address" about = "Inspect a module ID address"
)] )]
pub struct ModuleIdCmd { pub struct PalletIdCmd {
/// The module ID used to derive the account /// The module ID used to derive the account
id: String, id: String,
@@ -60,7 +60,7 @@ pub struct ModuleIdCmd {
pub keystore_params: KeystoreParams, pub keystore_params: KeystoreParams,
} }
impl ModuleIdCmd { impl PalletIdCmd {
/// runs the command /// runs the command
pub fn run<R>(&self) -> Result<(), Error> pub fn run<R>(&self) -> Result<(), Error>
where where
@@ -74,9 +74,9 @@ impl ModuleIdCmd {
let id_fixed_array: [u8; 8] = self.id.as_bytes() let id_fixed_array: [u8; 8] = self.id.as_bytes()
.try_into() .try_into()
.map_err(|_| "Cannot convert argument to moduleid: argument should be 8-character string")?; .map_err(|_| "Cannot convert argument to palletid: argument should be 8-character string")?;
let account_id: R::AccountId = ModuleId(id_fixed_array).into_account(); let account_id: R::AccountId = PalletId(id_fixed_array).into_account();
with_crypto_scheme!( with_crypto_scheme!(
self.crypto_scheme.scheme, self.crypto_scheme.scheme,