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 all 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.

20 changes: 10 additions & 10 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,15 +634,15 @@ parameter_types! {
pub const TermDuration: BlockNumber = 7 * DAYS;
pub const DesiredMembers: u32 = 13;
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.
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());

impl pallet_elections_phragmen::Config for Runtime {
type Event = Event;
type ModuleId = ElectionsPhragmenModuleId;
type PalletId = ElectionsPhragmenPalletId;
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 @@ -705,15 +705,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 TreasuryPalletId: 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 = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
AccountId,
Expand Down Expand Up @@ -970,12 +970,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 SocietyPalletId: PalletId = PalletId(*b"py/socie");
}

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

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 MaxGenerateRandom: u32 = 10;
}

impl pallet_lottery::Config for Runtime {
type ModuleId = LotteryModuleId;
type PalletId = LotteryPalletId;
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 @@ -103,11 +104,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 TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
}
// 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 ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand Down
14 changes: 7 additions & 7 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 @@ -1158,11 +1158,11 @@ mod tests {
}

parameter_types! {
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
}

impl Config for Test {
type ModuleId = ElectionsPhragmenModuleId;
type PalletId = ElectionsPhragmenPalletId;
type Event = Event;
type Currency = Balances;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
Expand Down Expand Up @@ -1313,7 +1313,7 @@ mod tests {
.get(0)
.cloned()
.map(|lock| {
assert_eq!(lock.id, ElectionsPhragmenModuleId::get());
assert_eq!(lock.id, ElectionsPhragmenPalletId::get());
lock.amount
})
.unwrap_or_default()
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
4 changes: 2 additions & 2 deletions frame/elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ChangeMembers<u64> for TestChangeMembers {
}

parameter_types!{
pub const ElectionModuleId: LockIdentifier = *b"py/elect";
pub const ElectionPalletId: LockIdentifier = *b"py/elect";
}

impl elections::Config for Test {
Expand All @@ -123,7 +123,7 @@ impl elections::Config for Test {
type InactiveGracePeriod = InactiveGracePeriod;
type VotingPeriod = VotingPeriod;
type DecayRatio = DecayRatio;
type ModuleId = ElectionModuleId;
type PalletId = ElectionPalletId;
}

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 @@ -211,7 +211,7 @@ decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = frame_system {
type Error = Error<T>;

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 @@ -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
/// 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 @@ -449,7 +449,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 @@ -96,13 +96,13 @@ impl pallet_balances::Config for Test {
}

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 MaxGenerateRandom: u32 = 10;
}

impl Config for Test {
type ModuleId = LotteryModuleId;
type PalletId = LotteryPalletId;
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
Loading