Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_system::{
EnsureRoot, EnsureOneOf,
limits::{BlockWeights, BlockLength}
};
use frame_support::traits::InstanceFilter;
use frame_support::{traits::InstanceFilter, PalletId};
use codec::{Encode, Decode};
use sp_core::{
crypto::KeyTypeId,
Expand All @@ -52,7 +52,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use sp_api::impl_runtime_apis;
use sp_runtime::{
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::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority};
Expand Down Expand Up @@ -634,7 +634,7 @@ const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());

impl pallet_elections_phragmen::Config for Runtime {
type Event = Event;
type ModuleId = ElectionsPhragmenModuleId;
type PalletId = ElectionsPhragmenModuleId;
type Currency = Balances;
type ChangeMembers = Council;
// NOTE: this implies that council's genesis members cannot be set directly and must come from
Expand Down Expand Up @@ -697,15 +697,15 @@ parameter_types! {
pub const DataDepositPerByte: Balance = 1 * CENTS;
pub const BountyDepositBase: Balance = 1 * DOLLARS;
pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");
pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
pub const MaximumReasonLength: u32 = 16384;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
pub const BountyValueMinimum: Balance = 5 * DOLLARS;
}

impl pallet_treasury::Config for Runtime {
type ModuleId = TreasuryModuleId;
type PalletId = TreasuryModuleId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
AccountId,
Expand Down Expand Up @@ -962,12 +962,12 @@ parameter_types! {
pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS;
pub const ChallengePeriod: BlockNumber = 7 * DAYS;
pub const MaxCandidateIntake: u32 = 10;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
pub const SocietyModuleId: PalletId = PalletId(*b"py/socie");
}

impl pallet_society::Config for Runtime {
type Event = Event;
type ModuleId = SocietyModuleId;
type PalletId = SocietyModuleId;
type Currency = Balances;
type Randomness = RandomnessCollectiveFlip;
type CandidateDeposit = CandidateDeposit;
Expand Down Expand Up @@ -1005,13 +1005,13 @@ impl pallet_mmr::Config for Runtime {
}

parameter_types! {
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto");
pub const LotteryModuleId: PalletId = PalletId(*b"py/lotto");
pub const MaxCalls: usize = 10;
pub const MaxGenerateRandom: u32 = 10;
}

impl pallet_lottery::Config for Runtime {
type ModuleId = LotteryModuleId;
type PalletId = LotteryModuleId;
type Call = Call;
type Currency = Balances;
type Randomness = RandomnessCollectiveFlip;
Expand Down
4 changes: 2 additions & 2 deletions frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// value and only call this once.
pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account()
T::PalletId::get().into_account()
}

/// The account ID of a bounty account
pub fn bounty_account_id(id: BountyIndex) -> T::AccountId {
// 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
T::ModuleId::get().into_sub_account(("bt", id))
T::PalletId::get().into_sub_account(("bt", id))
}

fn create_bounty(
Expand Down
9 changes: 5 additions & 4 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ use super::*;
use std::cell::RefCell;

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_runtime::{
Perbill, ModuleId,
Perbill,
testing::Header,
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
};
Expand Down Expand Up @@ -102,11 +103,11 @@ parameter_types! {
pub const SpendPeriod: u64 = 2;
pub const Burn: Permill = Permill::from_percent(50);
pub const DataDepositPerByte: u64 = 1;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");
}
// impl pallet_treasury::Config for Test {
impl pallet_treasury::Config for Test {
type ModuleId = TreasuryModuleId;
type PalletId = TreasuryModuleId;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand Down
10 changes: 5 additions & 5 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;

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

/// The currency that people are electing with.
type Currency:
Expand Down Expand Up @@ -375,7 +375,7 @@ decl_module! {
const DesiredMembers: u32 = T::DesiredMembers::get();
const DesiredRunnersUp: u32 = T::DesiredRunnersUp::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
/// set the initial votes, or update already existing votes.
Expand Down Expand Up @@ -452,7 +452,7 @@ decl_module! {
// Amount to be locked up.
let locked_stake = value.min(T::Currency::total_balance(&who));
T::Currency::set_lock(
T::ModuleId::get(),
T::PalletId::get(),
&who,
locked_stake,
WithdrawReasons::all(),
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<T: Config> Module<T> {
let Voter { deposit, .. } = <Voting<T>>::take(who);

// 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
// a noop anyhow.
Expand Down Expand Up @@ -1161,7 +1161,7 @@ mod tests {
}

impl Config for Test {
type ModuleId = ElectionsPhragmenModuleId;
type PalletId = ElectionsPhragmenModuleId;
type Event = Event;
type Currency = Balances;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
Expand Down
10 changes: 5 additions & 5 deletions frame/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;

/// Identifier for the elections pallet's lock
type ModuleId: Get<LockIdentifier>;
type PalletId: Get<LockIdentifier>;

/// The currency that people are electing with.
type Currency:
Expand Down Expand Up @@ -391,7 +391,7 @@ decl_module! {
/// The chunk size of the approval vector.
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;

Expand Down Expand Up @@ -491,7 +491,7 @@ decl_module! {
);

T::Currency::remove_lock(
T::ModuleId::get(),
T::PalletId::get(),
if valid { &who } else { &reporter }
);

Expand Down Expand Up @@ -529,7 +529,7 @@ decl_module! {

Self::remove_voter(&who, index);
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.
Expand Down Expand Up @@ -890,7 +890,7 @@ impl<T: Config> Module<T> {
}

T::Currency::set_lock(
T::ModuleId::get(),
T::PalletId::get(),
&who,
locked_balance,
WithdrawReasons::all(),
Expand Down
2 changes: 1 addition & 1 deletion frame/elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl elections::Config for Test {
type InactiveGracePeriod = InactiveGracePeriod;
type VotingPeriod = VotingPeriod;
type DecayRatio = DecayRatio;
type ModuleId = ElectionModuleId;
type PalletId = ElectionModuleId;
}

pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
Expand Down
12 changes: 6 additions & 6 deletions frame/lottery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod weights;

use sp_std::prelude::*;
use sp_runtime::{
DispatchError, ModuleId,
DispatchError,
traits::{AccountIdConversion, Saturating, Zero},
};
use frame_support::{
Expand All @@ -66,7 +66,7 @@ use frame_support::{
Currency, ReservableCurrency, Get, EnsureOrigin, ExistenceRequirement::KeepAlive, Randomness,
},
};
use frame_support::weights::Weight;
use frame_support::{weights::Weight, PalletId};
use frame_system::ensure_signed;
use codec::{Encode, Decode};
pub use weights::WeightInfo;
Expand All @@ -76,7 +76,7 @@ type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Con
/// The module's config trait.
pub trait Config: frame_system::Config {
/// The Lottery's module id
type ModuleId: Get<ModuleId>;
type PalletId: Get<PalletId>;

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

decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = frame_system {
const ModuleId: ModuleId = T::ModuleId::get();
const PalletId: PalletId = T::PalletId::get();
const MaxCalls: u32 = T::MaxCalls::get() as u32;

fn deposit_event() = default;
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<T: Config> Module<T> {
/// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once.
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.
Expand Down Expand Up @@ -447,7 +447,7 @@ impl<T: Config> Module<T> {
// TODO: deal with randomness freshness
// https://github.com/paritytech/substrate/issues/8311
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())
.expect("secure hashes should always be bigger than u32; qed");
random_number
Expand Down
4 changes: 2 additions & 2 deletions frame/lottery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const LotteryModuleId: ModuleId = ModuleId(*b"py/lotto");
pub const LotteryModuleId: PalletId = PalletId(*b"py/lotto");
pub const MaxCalls: usize = 2;
pub const MaxGenerateRandom: u32 = 10;
}

impl Config for Test {
type ModuleId = LotteryModuleId;
type PalletId = LotteryModuleId;
type Call = Call;
type Currency = Balances;
type Randomness = TestRandomness<Self>;
Expand Down
12 changes: 6 additions & 6 deletions frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ mod tests;
use rand_chacha::{rand_core::{RngCore, SeedableRng}, ChaChaRng};
use sp_std::prelude::*;
use codec::{Encode, Decode};
use sp_runtime::{Percent, ModuleId, RuntimeDebug,
use sp_runtime::{Percent, RuntimeDebug,
traits::{
StaticLookup, AccountIdConversion, Saturating, Zero, IntegerSquareRoot, Hash,
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::traits::{
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
Expand All @@ -277,7 +277,7 @@ pub trait Config<I = DefaultInstance>: system::Config {
type Event: From<Event<Self, I>> + Into<<Self as system::Config>::Event>;

/// The societies's module id
type ModuleId: Get<ModuleId>;
type PalletId: Get<PalletId>;

/// The currency type used for bidding.
type Currency: ReservableCurrency<Self::AccountId>;
Expand Down Expand Up @@ -498,7 +498,7 @@ decl_module! {
const ChallengePeriod: T::BlockNumber = T::ChallengePeriod::get();

/// The societies's module id
const ModuleId: ModuleId = T::ModuleId::get();
const PalletId: PalletId = T::PalletId::get();

/// Maximum candidate intake per round.
const MaxCandidateIntake: u32 = T::MaxCandidateIntake::get();
Expand Down Expand Up @@ -1600,15 +1600,15 @@ 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
/// value and only call this once.
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.
///
/// This actually does computation. If you need to keep using it, then make sure you cache the
/// value and only call this once.
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.
Expand Down
4 changes: 2 additions & 2 deletions frame/society/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const ExistentialDeposit: u64 = 1;
pub const MaxCandidateIntake: u32 = 10;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
pub const SocietyModuleId: PalletId = PalletId(*b"py/socie");
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl Config for Test {
type SuspensionJudgementOrigin = EnsureSignedBy<SuspensionJudgementSetAccount, u128>;
type ChallengePeriod = ChallengePeriod;
type MaxCandidateIntake = MaxCandidateIntake;
type ModuleId = SocietyModuleId;
type PalletId = SocietyModuleId;
}

pub struct EnvBuilder {
Expand Down
11 changes: 11 additions & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ pub use self::storage::{
pub use self::dispatch::{Parameter, Callable};
pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable};

use codec::{Encode, Decode};
use sp_runtime::TypeId;

/// A unified log target for support operations.
pub const LOG_TARGET: &'static str = "runtime::frame-support";

/// A type that cannot be instantiated.
#[derive(Debug, PartialEq, Eq, Clone)]
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";
}

/// Create new implementations of the [`Get`](crate::traits::Get) trait.
///
/// The so-called parameter type can be created in four different ways:
Expand Down
Loading