Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
+1
View File
@@ -1714,6 +1714,7 @@ version = "2.0.0"
dependencies = [
"frame-metadata",
"frame-support",
"frame-system",
"parity-scale-codec",
"pretty_assertions",
"rustversion",
@@ -14,9 +14,9 @@ mod mock;
mod tests;
/// Configure the pallet by specifying the parameters and types on which it depends.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}
// The pallet's runtime storage items.
@@ -25,7 +25,7 @@ decl_storage! {
// A unique name is used to ensure that the pallet's storage items are isolated.
// This name may be updated, but each pallet in the runtime must use a unique name.
// ---------------------------------vvvvvvvvvvvvvv
trait Store for Module<T: Trait> as TemplateModule {
trait Store for Module<T: Config> as TemplateModule {
// Learn more about declaring storage items:
// https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items
Something get(fn something): Option<u32>;
@@ -35,7 +35,7 @@ decl_storage! {
// Pallets use events to inform users when important changes are made.
// https://substrate.dev/docs/en/knowledgebase/runtime/events
decl_event!(
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, AccountId),
@@ -44,7 +44,7 @@ decl_event!(
// Errors inform users that something went wrong.
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Error names should be descriptive.
NoneValue,
/// Errors should have helpful documentation associated with them.
@@ -56,7 +56,7 @@ decl_error! {
// These functions materialize as "extrinsics", which are often compared to transactions.
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
// Errors must be initialized if they are used by the pallet.
type Error = Error<T>;
@@ -1,4 +1,4 @@
use crate::{Module, Trait};
use crate::{Module, Config};
use sp_core::H256;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use sp_runtime::{
@@ -21,7 +21,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl system::Trait for Test {
impl system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
@@ -49,7 +49,7 @@ impl system::Trait for Test {
type SystemWeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type Event = ();
}
@@ -140,7 +140,7 @@ parameter_types! {
// Configure FRAME pallets to include in runtime.
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// The identifier used to distinguish between accounts.
@@ -199,11 +199,11 @@ impl frame_system::Trait for Runtime {
type SystemWeightInfo = ();
}
impl pallet_aura::Trait for Runtime {
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
}
impl pallet_grandpa::Trait for Runtime {
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
@@ -226,7 +226,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
impl pallet_timestamp::Trait for Runtime {
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
@@ -239,7 +239,7 @@ parameter_types! {
pub const MaxLocks: u32 = 50;
}
impl pallet_balances::Trait for Runtime {
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
/// The type for recording an account's balance.
type Balance = Balance;
@@ -255,20 +255,20 @@ parameter_types! {
pub const TransactionByteFee: Balance = 1;
}
impl pallet_transaction_payment::Trait for Runtime {
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_sudo::Trait for Runtime {
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
/// Configure the pallet template in pallets/template.
impl template::Trait for Runtime {
impl template::Config for Runtime {
type Event = Event;
}
@@ -457,7 +457,7 @@ impl_runtime_apis! {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_system_benchmarking::Module as SystemBench;
impl frame_system_benchmarking::Trait for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
+2 -2
View File
@@ -580,7 +580,7 @@ const CODE_TRANSFER: &str = r#"
#[test]
fn deploying_wasm_contract_should_work() {
let transfer_code = wat::parse_str(CODE_TRANSFER).unwrap();
let transfer_ch = <Runtime as frame_system::Trait>::Hashing::hash(&transfer_code);
let transfer_ch = <Runtime as frame_system::Config>::Hashing::hash(&transfer_code);
let addr = pallet_contracts::Module::<Runtime>::contract_address(
&charlie(),
@@ -588,7 +588,7 @@ fn deploying_wasm_contract_should_work() {
&[],
);
let subsistence = pallet_contracts::Config::<Runtime>::subsistence_threshold_uncached();
let subsistence = pallet_contracts::ConfigCache::<Runtime>::subsistence_threshold_uncached();
let b = construct_block(
&mut new_test_ext(compact_code_unwrap(), false),
+1 -1
View File
@@ -200,7 +200,7 @@ mod multiplier_tests {
fm = next;
iterations += 1;
let fee =
<Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&tx_weight);
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&tx_weight);
let adjusted_fee = fm.saturating_mul_acc_int(fee);
println!(
"iteration {}, new fm = {:?}. Fee at this point is: {} units / {} millicents, \
+34 -34
View File
@@ -156,7 +156,7 @@ parameter_types! {
const_assert!(AvailableBlockRatio::get().deconstruct() >= AVERAGE_ON_INITIALIZE_WEIGHT.deconstruct());
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Call = Call;
@@ -184,7 +184,7 @@ impl frame_system::Trait for Runtime {
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
}
impl pallet_utility::Trait for Runtime {
impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
@@ -198,7 +198,7 @@ parameter_types! {
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Trait for Runtime {
impl pallet_multisig::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
@@ -261,7 +261,7 @@ impl InstanceFilter<Call> for ProxyType {
}
}
impl pallet_proxy::Trait for Runtime {
impl pallet_proxy::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
@@ -281,7 +281,7 @@ parameter_types! {
pub const MaxScheduledPerBlock: u32 = 50;
}
impl pallet_scheduler::Trait for Runtime {
impl pallet_scheduler::Config for Runtime {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
@@ -297,7 +297,7 @@ parameter_types! {
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}
impl pallet_babe::Trait for Runtime {
impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
@@ -324,7 +324,7 @@ parameter_types! {
pub const IndexDeposit: Balance = 1 * DOLLARS;
}
impl pallet_indices::Trait for Runtime {
impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type Deposit = IndexDeposit;
@@ -339,7 +339,7 @@ parameter_types! {
pub const MaxLocks: u32 = 50;
}
impl pallet_balances::Trait for Runtime {
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type Balance = Balance;
type DustRemoval = ();
@@ -356,7 +356,7 @@ parameter_types! {
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);
}
impl pallet_transaction_payment::Trait for Runtime {
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
@@ -368,7 +368,7 @@ parameter_types! {
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
}
impl pallet_timestamp::Trait for Runtime {
impl pallet_timestamp::Config for Runtime {
type Moment = Moment;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
@@ -379,7 +379,7 @@ parameter_types! {
pub const UncleGenerations: BlockNumber = 5;
}
impl pallet_authorship::Trait for Runtime {
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -399,9 +399,9 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}
impl pallet_session::Trait for Runtime {
impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
@@ -412,7 +412,7 @@ impl pallet_session::Trait for Runtime {
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}
impl pallet_session::historical::Trait for Runtime {
impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}
@@ -443,7 +443,7 @@ parameter_types! {
.saturating_sub(ExtrinsicBaseWeight::get());
}
impl pallet_staking::Trait for Runtime {
impl pallet_staking::Config for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = U128CurrencyToVote;
@@ -489,7 +489,7 @@ parameter_types! {
pub const MaxProposals: u32 = 100;
}
impl pallet_democracy::Trait for Runtime {
impl pallet_democracy::Config for Runtime {
type Proposal = Call;
type Event = Event;
type Currency = Balances;
@@ -541,7 +541,7 @@ parameter_types! {
}
type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Trait<CouncilCollective> for Runtime {
impl pallet_collective::Config<CouncilCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
@@ -564,7 +564,7 @@ parameter_types! {
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());
impl pallet_elections_phragmen::Trait for Runtime {
impl pallet_elections_phragmen::Config for Runtime {
type Event = Event;
type ModuleId = ElectionsPhragmenModuleId;
type Currency = Balances;
@@ -591,7 +591,7 @@ parameter_types! {
}
type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Trait<TechnicalCollective> for Runtime {
impl pallet_collective::Config<TechnicalCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
@@ -607,7 +607,7 @@ type EnsureRootOrHalfCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>
>;
impl pallet_membership::Trait<pallet_membership::Instance1> for Runtime {
impl pallet_membership::Config<pallet_membership::Instance1> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrHalfCouncil;
type RemoveOrigin = EnsureRootOrHalfCouncil;
@@ -636,7 +636,7 @@ parameter_types! {
pub const BountyValueMinimum: Balance = 5 * DOLLARS;
}
impl pallet_treasury::Trait for Runtime {
impl pallet_treasury::Config for Runtime {
type ModuleId = TreasuryModuleId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
@@ -681,7 +681,7 @@ parameter_types! {
pub const MaxValueSize: u32 = 16 * 1024;
}
impl pallet_contracts::Trait for Runtime {
impl pallet_contracts::Config for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Currency = Balances;
@@ -699,7 +699,7 @@ impl pallet_contracts::Trait for Runtime {
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
}
impl pallet_sudo::Trait for Runtime {
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
@@ -769,7 +769,7 @@ impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime where
type OverarchingCall = Call;
}
impl pallet_im_online::Trait for Runtime {
impl pallet_im_online::Config for Runtime {
type AuthorityId = ImOnlineId;
type Event = Event;
type SessionDuration = SessionDuration;
@@ -782,16 +782,16 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl pallet_offences::Trait for Runtime {
impl pallet_offences::Config for Runtime {
type Event = Event;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
}
impl pallet_authority_discovery::Trait for Runtime {}
impl pallet_authority_discovery::Config for Runtime {}
impl pallet_grandpa::Trait for Runtime {
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
@@ -820,7 +820,7 @@ parameter_types! {
pub const MaxRegistrars: u32 = 20;
}
impl pallet_identity::Trait for Runtime {
impl pallet_identity::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
@@ -842,7 +842,7 @@ parameter_types! {
pub const RecoveryDeposit: Balance = 5 * DOLLARS;
}
impl pallet_recovery::Trait for Runtime {
impl pallet_recovery::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
@@ -863,7 +863,7 @@ parameter_types! {
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
}
impl pallet_society::Trait for Runtime {
impl pallet_society::Config for Runtime {
type Event = Event;
type ModuleId = SocietyModuleId;
type Currency = Balances;
@@ -884,7 +884,7 @@ parameter_types! {
pub const MinVestedTransfer: Balance = 100 * DOLLARS;
}
impl pallet_vesting::Trait for Runtime {
impl pallet_vesting::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
@@ -1173,9 +1173,9 @@ impl_runtime_apis! {
use pallet_offences_benchmarking::Module as OffencesBench;
use frame_system_benchmarking::Module as SystemBench;
impl pallet_session_benchmarking::Trait for Runtime {}
impl pallet_offences_benchmarking::Trait for Runtime {}
impl frame_system_benchmarking::Trait for Runtime {}
impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
+1 -1
View File
@@ -63,7 +63,7 @@ pub enum Subkey {
/// Run the subkey command, given the apropriate runtime.
pub fn run<R>() -> Result<(), Error>
where
R: frame_system::Trait,
R: frame_system::Config,
R::AccountId: Ss58Codec
{
match Subkey::from_args() {
+15 -15
View File
@@ -28,7 +28,7 @@
//! * Asset Transfer
//! * Asset Destruction
//!
//! To use it in your runtime, you need to implement the assets [`Trait`](./trait.Trait.html).
//! To use it in your runtime, you need to implement the assets [`Config`](./trait.Config.html).
//!
//! The supported dispatchable functions are documented in the [`Call`](./enum.Call.html) enum.
//!
@@ -89,10 +89,10 @@
//! use frame_support::{decl_module, dispatch, ensure};
//! use frame_system::ensure_signed;
//!
//! pub trait Trait: assets::Trait { }
//! pub trait Config: assets::Config { }
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! pub fn issue_token_airdrop(origin) -> dispatch::DispatchResult {
//! let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
//!
@@ -123,7 +123,7 @@
//! them are violated, the behavior of this module is undefined.
//!
//! * The total count of assets should be less than
//! `Trait::AssetId::max_value()`.
//! `Config::AssetId::max_value()`.
//!
//! ## Related Modules
//!
@@ -139,9 +139,9 @@ use frame_system::ensure_signed;
use sp_runtime::traits::One;
/// The module configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The units in which we record balances.
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy;
@@ -151,7 +151,7 @@ pub trait Trait: frame_system::Trait {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -226,9 +226,9 @@ decl_module! {
decl_event! {
pub enum Event<T> where
<T as frame_system::Trait>::AccountId,
<T as Trait>::Balance,
<T as Trait>::AssetId,
<T as frame_system::Config>::AccountId,
<T as Config>::Balance,
<T as Config>::AssetId,
{
/// Some assets were issued. \[asset_id, owner, total_supply\]
Issued(AssetId, AccountId, Balance),
@@ -240,7 +240,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Transfer amount should be non-zero
AmountZero,
/// Account balance must be greater than or equal to the transfer amount
@@ -251,7 +251,7 @@ decl_error! {
}
decl_storage! {
trait Store for Module<T: Trait> as Assets {
trait Store for Module<T: Config> as Assets {
/// The number of units of assets held by any given account.
Balances: map hasher(blake2_128_concat) (T::AssetId, T::AccountId) => T::Balance;
/// The next asset identifier up for grabs.
@@ -264,7 +264,7 @@ decl_storage! {
}
// The main implementation block for the module.
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
// Public immutables
/// Get the asset `id` balance of `who`.
@@ -298,7 +298,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -325,7 +325,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type Balance = u64;
type AssetId = u32;
+10 -10
View File
@@ -19,7 +19,7 @@
//!
//! A module for atomically sending funds.
//!
//! - [`atomic_swap::Trait`](./trait.Trait.html)
//! - [`atomic_swap::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -56,7 +56,7 @@ use sp_runtime::RuntimeDebug;
/// Pending atomic swap operation.
#[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode)]
pub struct PendingSwap<T: Trait> {
pub struct PendingSwap<T: Config> {
/// Source of the swap.
pub source: T::AccountId,
/// Action of this swap.
@@ -74,7 +74,7 @@ pub type HashedProof = [u8; 32];
/// succeeds with best efforts.
/// - **Claim**: claim any resources reserved in the first phrase.
/// - **Cancel**: cancel any resources reserved in the first phrase.
pub trait SwapAction<AccountId, T: Trait> {
pub trait SwapAction<AccountId, T: Config> {
/// Reserve the resources needed for the swap, from the given `source`. The reservation is
/// allowed to fail. If that is the case, the the full swap creation operation is cancelled.
fn reserve(&self, source: &AccountId) -> DispatchResult;
@@ -115,7 +115,7 @@ impl<AccountId, C> DerefMut for BalanceSwapAction<AccountId, C> where C: Reserva
}
}
impl<T: Trait, AccountId, C> SwapAction<AccountId, T> for BalanceSwapAction<AccountId, C>
impl<T: Config, AccountId, C> SwapAction<AccountId, T> for BalanceSwapAction<AccountId, C>
where C: ReservableCurrency<AccountId>
{
fn reserve(&self, source: &AccountId) -> DispatchResult {
@@ -136,9 +136,9 @@ impl<T: Trait, AccountId, C> SwapAction<AccountId, T> for BalanceSwapAction<Acco
}
/// Atomic swap's pallet configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Swap action.
type SwapAction: SwapAction<Self::AccountId, Self> + Parameter;
/// Limit of proof size.
@@ -155,7 +155,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as AtomicSwap {
trait Store for Module<T: Config> as AtomicSwap {
pub PendingSwaps: double_map
hasher(twox_64_concat) T::AccountId, hasher(blake2_128_concat) HashedProof
=> Option<PendingSwap<T>>;
@@ -163,7 +163,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Swap already exists.
AlreadyExist,
/// Swap proof is invalid.
@@ -186,7 +186,7 @@ decl_error! {
decl_event!(
/// Event of atomic swap pallet.
pub enum Event<T> where
AccountId = <T as system::Trait>::AccountId,
AccountId = <T as system::Config>::AccountId,
PendingSwap = PendingSwap<T>,
{
/// Swap created. \[account, proof, swap\]
@@ -201,7 +201,7 @@ decl_event!(
decl_module! {
/// Module definition of atomic swap pallet.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
+3 -3
View File
@@ -24,7 +24,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -54,7 +54,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
@@ -67,7 +67,7 @@ parameter_types! {
pub const ProofLimit: u32 = 1024;
pub const ExpireDuration: u64 = 100;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type SwapAction = BalanceSwapAction<u64, Balances>;
type ProofLimit = ProofLimit;
+14 -14
View File
@@ -17,7 +17,7 @@
//! # Aura Module
//!
//! - [`aura::Trait`](./trait.Trait.html)
//! - [`aura::Config`](./trait.Config.html)
//! - [`Module`](./struct.Module.html)
//!
//! ## Overview
@@ -66,13 +66,13 @@ use sp_consensus_aura::{
mod mock;
mod tests;
pub trait Trait: pallet_timestamp::Trait {
pub trait Config: pallet_timestamp::Config {
/// The identifier type for an authority.
type AuthorityId: Member + Parameter + RuntimeAppPublic + Default;
}
decl_storage! {
trait Store for Module<T: Trait> as Aura {
trait Store for Module<T: Config> as Aura {
/// The last timestamp.
LastTimestamp get(fn last): T::Moment;
@@ -86,10 +86,10 @@ decl_storage! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin { }
pub struct Module<T: Config> for enum Call where origin: T::Origin { }
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
fn change_authorities(new: Vec<T::AuthorityId>) {
<Authorities<T>>::put(&new);
@@ -108,11 +108,11 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = T::AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = T::AuthorityId;
fn on_genesis_session<'a, I: 'a>(validators: I)
@@ -145,7 +145,7 @@ impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
}
}
impl<T: Trait> FindAuthor<u32> for Module<T> {
impl<T: Config> FindAuthor<u32> for Module<T> {
fn find_author<'a, I>(digests: I) -> Option<u32> where
I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
{
@@ -167,7 +167,7 @@ impl<T: Trait> FindAuthor<u32> for Module<T> {
#[doc(hidden)]
pub struct FindAccountFromAuthorIndex<T, Inner>(sp_std::marker::PhantomData<(T, Inner)>);
impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
impl<T: Config, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
for FindAccountFromAuthorIndex<T, Inner>
{
fn find_author<'a, I>(digests: I) -> Option<T::AuthorityId>
@@ -183,7 +183,7 @@ impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
/// Find the authority ID of the Aura authority who authored the current block.
pub type AuraAuthorId<T> = FindAccountFromAuthorIndex<T, Module<T>>;
impl<T: Trait> IsMember<T::AuthorityId> for Module<T> {
impl<T: Config> IsMember<T::AuthorityId> for Module<T> {
fn is_member(authority_id: &T::AuthorityId) -> bool {
Self::authorities()
.iter()
@@ -191,12 +191,12 @@ impl<T: Trait> IsMember<T::AuthorityId> for Module<T> {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Determine the Aura slot-duration based on the Timestamp module configuration.
pub fn slot_duration() -> T::Moment {
// we double the minimum block-period so each author can always propose within
// the majority of its slot.
<T as pallet_timestamp::Trait>::MinimumPeriod::get().saturating_mul(2u32.into())
<T as pallet_timestamp::Config>::MinimumPeriod::get().saturating_mul(2u32.into())
}
fn on_timestamp_set(now: T::Moment, slot_duration: T::Moment) {
@@ -218,13 +218,13 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> OnTimestampSet<T::Moment> for Module<T> {
impl<T: Config> OnTimestampSet<T::Moment> for Module<T> {
fn on_timestamp_set(moment: T::Moment) {
Self::on_timestamp_set(moment, Self::slot_duration())
}
}
impl<T: Trait> ProvideInherent for Module<T> {
impl<T: Config> ProvideInherent for Module<T> {
type Call = pallet_timestamp::Call<T>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
+4 -4
View File
@@ -19,7 +19,7 @@
#![cfg(test)]
use crate::{Trait, Module, GenesisConfig};
use crate::{Config, Module, GenesisConfig};
use sp_consensus_aura::ed25519::AuthorityId;
use sp_runtime::{
traits::IdentityLookup, Perbill,
@@ -45,7 +45,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 1;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -73,14 +73,14 @@ impl frame_system::Trait for Test {
type SystemWeightInfo = ();
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type AuthorityId = AuthorityId;
}
+10 -10
View File
@@ -28,10 +28,10 @@ use frame_support::{decl_module, decl_storage};
use sp_authority_discovery::AuthorityId;
/// The module's config trait.
pub trait Trait: frame_system::Trait + pallet_session::Trait {}
pub trait Config: frame_system::Config + pallet_session::Config {}
decl_storage! {
trait Store for Module<T: Trait> as AuthorityDiscovery {
trait Store for Module<T: Config> as AuthorityDiscovery {
/// Keys of the current and next authority set.
Keys get(fn keys): Vec<AuthorityId>;
}
@@ -42,11 +42,11 @@ decl_storage! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Retrieve authority identifiers of the current and next authority set.
pub fn authorities() -> Vec<AuthorityId> {
Keys::get()
@@ -60,11 +60,11 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = AuthorityId;
fn on_genesis_session<'a, I: 'a>(authorities: I)
@@ -107,13 +107,13 @@ mod tests {
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
impl Trait for Test {}
impl Config for Test {}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type SessionManager = ();
type Keys = UintAuthorityId;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
@@ -126,7 +126,7 @@ mod tests {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = ();
type FullIdentificationOf = ();
}
@@ -143,7 +143,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
+8 -8
View File
@@ -34,7 +34,7 @@ use sp_authorship::{INHERENT_IDENTIFIER, UnclesInherentData, InherentError};
const MAX_UNCLES: usize = 10;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// Find the author of a block.
type FindAuthor: FindAuthor<Self::AccountId>;
/// The number of blocks back we should accept uncles.
@@ -152,7 +152,7 @@ enum UncleEntryItem<BlockNumber, Hash, Author> {
}
decl_storage! {
trait Store for Module<T: Trait> as Authorship {
trait Store for Module<T: Config> as Authorship {
/// Uncles
Uncles: Vec<UncleEntryItem<T::BlockNumber, T::Hash, T::AccountId>>;
/// Author of current block.
@@ -164,7 +164,7 @@ decl_storage! {
decl_error! {
/// Error for the authorship module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// The uncle parent not in the chain.
InvalidUncleParent,
/// Uncles already set in the block.
@@ -183,7 +183,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn on_initialize(now: T::BlockNumber) -> Weight {
@@ -223,7 +223,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Fetch the author of the block.
///
/// This is safe to invoke in `on_initialize` implementations, as well
@@ -337,7 +337,7 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> ProvideInherent for Module<T> {
impl<T: Config> ProvideInherent for Module<T> {
type Call = Call<T>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
@@ -417,7 +417,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -449,7 +449,7 @@ mod tests {
pub const UncleGenerations: u64 = 5;
}
impl Trait for Test {
impl Config for Test {
type FindAuthor = AuthorGiven;
type UncleGenerations = UncleGenerations;
type FilterUncle = SealVerify<VerifyBlock>;
+5 -5
View File
@@ -48,14 +48,14 @@ use sp_staking::{
};
use sp_std::prelude::*;
use crate::{Call, Module, Trait};
use crate::{Call, Module, Config};
/// A trait with utility methods for handling equivocation reports in BABE.
/// The trait provides methods for reporting an offence triggered by a valid
/// equivocation report, checking the current block author (to declare as the
/// reporter), and also for creating and submitting equivocation report
/// extrinsics (useful only in offchain context).
pub trait HandleEquivocation<T: Trait> {
pub trait HandleEquivocation<T: Config> {
/// Report an offence proved by the given reporters.
fn report_offence(
reporters: Vec<T::AccountId>,
@@ -75,7 +75,7 @@ pub trait HandleEquivocation<T: Trait> {
fn block_author() -> Option<T::AccountId>;
}
impl<T: Trait> HandleEquivocation<T> for () {
impl<T: Config> HandleEquivocation<T> for () {
fn report_offence(
_reporters: Vec<T::AccountId>,
_offence: BabeEquivocationOffence<T::KeyOwnerIdentification>,
@@ -120,7 +120,7 @@ where
// We use the authorship pallet to fetch the current block author and use
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
// submission.
T: Trait + pallet_authorship::Trait + frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
// A system for reporting offences after valid equivocation reports are
// processed.
R: ReportOffence<
@@ -164,7 +164,7 @@ where
/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned`
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This
/// guarantees that only block authors can include unsigned equivocation reports.
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, _) = call {
+22 -22
View File
@@ -62,7 +62,7 @@ mod tests;
pub use equivocation::{BabeEquivocationOffence, EquivocationHandler, HandleEquivocation};
pub trait Trait: pallet_timestamp::Trait {
pub trait Config: pallet_timestamp::Config {
/// The amount of time, in slots, that each epoch should last.
type EpochDuration: Get<SlotNumber>;
@@ -115,7 +115,7 @@ pub trait WeightInfo {
pub trait EpochChangeTrigger {
/// Trigger an epoch change, if any should take place. This should be called
/// during every block, after initialization is done.
fn trigger<T: Trait>(now: T::BlockNumber);
fn trigger<T: Config>(now: T::BlockNumber);
}
/// A type signifying to BABE that an external trigger
@@ -123,7 +123,7 @@ pub trait EpochChangeTrigger {
pub struct ExternalTrigger;
impl EpochChangeTrigger for ExternalTrigger {
fn trigger<T: Trait>(_: T::BlockNumber) { } // nothing - trigger is external.
fn trigger<T: Config>(_: T::BlockNumber) { } // nothing - trigger is external.
}
/// A type signifying to BABE that it should perform epoch changes
@@ -131,7 +131,7 @@ impl EpochChangeTrigger for ExternalTrigger {
pub struct SameAuthoritiesForever;
impl EpochChangeTrigger for SameAuthoritiesForever {
fn trigger<T: Trait>(now: T::BlockNumber) {
fn trigger<T: Config>(now: T::BlockNumber) {
if <Module<T>>::should_epoch_change(now) {
let authorities = <Module<T>>::authorities();
let next_authorities = authorities.clone();
@@ -146,7 +146,7 @@ const UNDER_CONSTRUCTION_SEGMENT_LENGTH: usize = 256;
type MaybeRandomness = Option<schnorrkel::Randomness>;
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// An equivocation proof provided as part of an equivocation report is invalid.
InvalidEquivocationProof,
/// A key ownership proof provided as part of an equivocation report is invalid.
@@ -157,7 +157,7 @@ decl_error! {
}
decl_storage! {
trait Store for Module<T: Trait> as Babe {
trait Store for Module<T: Config> as Babe {
/// Current epoch index.
pub EpochIndex get(fn epoch_index): u64;
@@ -230,7 +230,7 @@ decl_storage! {
decl_module! {
/// The BABE Pallet
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// The number of **slots** that an epoch takes. We couple sessions to
/// epochs, i.e. we start a new session once the new epoch begins.
const EpochDuration: u64 = T::EpochDuration::get();
@@ -271,7 +271,7 @@ decl_module! {
/// the equivocation proof and validate the given key ownership proof
/// against the extracted offender. If both are valid, the offence will
/// be reported.
#[weight = <T as Trait>::WeightInfo::report_equivocation(key_owner_proof.validator_count())]
#[weight = <T as Config>::WeightInfo::report_equivocation(key_owner_proof.validator_count())]
fn report_equivocation(
origin,
equivocation_proof: EquivocationProof<T::Header>,
@@ -294,7 +294,7 @@ decl_module! {
/// block authors will call it (validated in `ValidateUnsigned`), as such
/// if the block author is defined it will be defined as the equivocation
/// reporter.
#[weight = <T as Trait>::WeightInfo::report_equivocation(key_owner_proof.validator_count())]
#[weight = <T as Config>::WeightInfo::report_equivocation(key_owner_proof.validator_count())]
fn report_equivocation_unsigned(
origin,
equivocation_proof: EquivocationProof<T::Header>,
@@ -311,7 +311,7 @@ decl_module! {
}
}
impl<T: Trait> RandomnessT<<T as frame_system::Trait>::Hash> for Module<T> {
impl<T: Config> RandomnessT<<T as frame_system::Config>::Hash> for Module<T> {
/// Some BABE blocks have VRF outputs where the block producer has exactly one bit of influence,
/// either they make the block or they do not make the block and thus someone else makes the
/// next block. Yet, this randomness is not fresh in all BABE blocks.
@@ -332,14 +332,14 @@ impl<T: Trait> RandomnessT<<T as frame_system::Trait>::Hash> for Module<T> {
subject.reserve(VRF_OUTPUT_LENGTH);
subject.extend_from_slice(&Self::randomness()[..]);
<T as frame_system::Trait>::Hashing::hash(&subject[..])
<T as frame_system::Config>::Hashing::hash(&subject[..])
}
}
/// A BABE public key
pub type BabeKey = [u8; PUBLIC_KEY_LENGTH];
impl<T: Trait> FindAuthor<u32> for Module<T> {
impl<T: Config> FindAuthor<u32> for Module<T> {
fn find_author<'a, I>(digests: I) -> Option<u32> where
I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
{
@@ -354,7 +354,7 @@ impl<T: Trait> FindAuthor<u32> for Module<T> {
}
}
impl<T: Trait> IsMember<AuthorityId> for Module<T> {
impl<T: Config> IsMember<AuthorityId> for Module<T> {
fn is_member(authority_id: &AuthorityId) -> bool {
<Module<T>>::authorities()
.iter()
@@ -362,7 +362,7 @@ impl<T: Trait> IsMember<AuthorityId> for Module<T> {
}
}
impl<T: Trait> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
impl<T: Config> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
fn should_end_session(now: T::BlockNumber) -> bool {
// it might be (and it is in current implementation) that session module is calling
// should_end_session() from it's own on_initialize() handler
@@ -374,12 +374,12 @@ impl<T: Trait> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Determine the BABE slot duration based on the Timestamp module configuration.
pub fn slot_duration() -> T::Moment {
// we double the minimum block-period so each author can always propose within
// the majority of their slot.
<T as pallet_timestamp::Trait>::MinimumPeriod::get().saturating_mul(2u32.into())
<T as pallet_timestamp::Config>::MinimumPeriod::get().saturating_mul(2u32.into())
}
/// Determine whether an epoch change should take place at this block.
@@ -690,11 +690,11 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> OnTimestampSet<T::Moment> for Module<T> {
impl<T: Config> OnTimestampSet<T::Moment> for Module<T> {
fn on_timestamp_set(_moment: T::Moment) { }
}
impl<T: Trait> frame_support::traits::EstimateNextSessionRotation<T::BlockNumber> for Module<T> {
impl<T: Config> frame_support::traits::EstimateNextSessionRotation<T::BlockNumber> for Module<T> {
fn estimate_next_session_rotation(now: T::BlockNumber) -> Option<T::BlockNumber> {
Self::next_expected_epoch_change(now)
}
@@ -706,17 +706,17 @@ impl<T: Trait> frame_support::traits::EstimateNextSessionRotation<T::BlockNumber
}
}
impl<T: Trait> frame_support::traits::Lateness<T::BlockNumber> for Module<T> {
impl<T: Config> frame_support::traits::Lateness<T::BlockNumber> for Module<T> {
fn lateness(&self) -> T::BlockNumber {
Self::lateness()
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = AuthorityId;
fn on_genesis_session<'a, I: 'a>(validators: I)
@@ -766,7 +766,7 @@ fn compute_randomness(
sp_io::hashing::blake2_256(&s)
}
impl<T: Trait> ProvideInherent for Module<T> {
impl<T: Config> ProvideInherent for Module<T> {
type Call = pallet_timestamp::Call<T>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
+11 -11
View File
@@ -18,7 +18,7 @@
//! Test utilities
use codec::Encode;
use super::{Trait, Module, CurrentSlot};
use super::{Config, Module, CurrentSlot};
use sp_runtime::{
Perbill, impl_opaque_keys,
curve::PiecewiseLinear,
@@ -65,7 +65,7 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(16);
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -107,9 +107,9 @@ impl_opaque_keys! {
}
}
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type Event = ();
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
@@ -120,7 +120,7 @@ impl pallet_session::Trait for Test {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = pallet_staking::Exposure<u64, u128>;
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
}
@@ -129,7 +129,7 @@ parameter_types! {
pub const UncleGenerations: u64 = 0;
}
impl pallet_authorship::Trait for Test {
impl pallet_authorship::Config for Test {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -140,7 +140,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 1;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
@@ -151,7 +151,7 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
@@ -183,7 +183,7 @@ parameter_types! {
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
}
impl pallet_staking::Trait for Test {
impl pallet_staking::Config for Test {
type RewardRemainder = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = ();
@@ -212,14 +212,14 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl pallet_offences::Trait for Test {
impl pallet_offences::Config for Test {
type Event = ();
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
}
impl Trait for Test {
impl Config for Test {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = crate::ExternalTrigger;
+4 -4
View File
@@ -206,7 +206,7 @@ fn authority_index() {
#[test]
fn can_predict_next_epoch_change() {
new_test_ext(1).execute_with(|| {
assert_eq!(<Test as Trait>::EpochDuration::get(), 3);
assert_eq!(<Test as Config>::EpochDuration::get(), 3);
// this sets the genesis slot to 6;
go_to_block(1, 6);
assert_eq!(Babe::genesis_slot(), 6);
@@ -227,7 +227,7 @@ fn can_predict_next_epoch_change() {
#[test]
fn can_enact_next_config() {
new_test_ext(1).execute_with(|| {
assert_eq!(<Test as Trait>::EpochDuration::get(), 3);
assert_eq!(<Test as Config>::EpochDuration::get(), 3);
// this sets the genesis slot to 6;
go_to_block(1, 6);
assert_eq!(Babe::genesis_slot(), 6);
@@ -661,7 +661,7 @@ fn report_equivocation_has_valid_weight() {
// but there's a lower bound of 100 validators.
assert!(
(1..=100)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] == w[1])
@@ -671,7 +671,7 @@ fn report_equivocation_has_valid_weight() {
// with every extra validator.
assert!(
(100..=1000)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] < w[1])
+38 -38
View File
@@ -19,7 +19,7 @@
//!
//! The Balances module provides functionality for handling accounts and balances.
//!
//! - [`balances::Trait`](./trait.Trait.html)
//! - [`balances::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -99,12 +99,12 @@
//!
//! ```
//! use frame_support::traits::Currency;
//! # pub trait Trait: frame_system::Trait {
//! # pub trait Config: frame_system::Config {
//! # type Currency: Currency<Self::AccountId>;
//! # }
//!
//! pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
//! pub type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
//! pub type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
//! pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
//!
//! # fn main() {}
//! ```
@@ -114,17 +114,17 @@
//! ```
//! use frame_support::traits::{WithdrawReasons, LockableCurrency};
//! use sp_runtime::traits::Bounded;
//! pub trait Trait: frame_system::Trait {
//! pub trait Config: frame_system::Config {
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
//! }
//! # struct StakingLedger<T: Trait> {
//! # stash: <T as frame_system::Trait>::AccountId,
//! # total: <<T as Trait>::Currency as frame_support::traits::Currency<<T as frame_system::Trait>::AccountId>>::Balance,
//! # struct StakingLedger<T: Config> {
//! # stash: <T as frame_system::Config>::AccountId,
//! # total: <<T as Config>::Currency as frame_support::traits::Currency<<T as frame_system::Config>::AccountId>>::Balance,
//! # phantom: std::marker::PhantomData<T>,
//! # }
//! # const STAKING_ID: [u8; 8] = *b"staking ";
//!
//! fn update_ledger<T: Trait>(
//! fn update_ledger<T: Config>(
//! controller: &T::AccountId,
//! ledger: &StakingLedger<T>
//! ) {
@@ -145,7 +145,7 @@
//!
//! ## Assumptions
//!
//! * Total issued balanced of all accounts should be less than `Trait::Balance::max_value()`.
//! * Total issued balanced of all accounts should be less than `Config::Balance::max_value()`.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -179,7 +179,7 @@ use frame_system::{self as system, ensure_signed, ensure_root};
pub use self::imbalances::{PositiveImbalance, NegativeImbalance};
pub use weights::WeightInfo;
pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Config {
/// The balance of an account.
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + Default + Copy +
MaybeSerializeDeserialize + Debug;
@@ -198,7 +198,7 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
type MaxLocks: Get<u32>;
}
pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
pub trait Config<I: Instance = DefaultInstance>: frame_system::Config {
/// The balance of an account.
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + Default + Copy +
MaybeSerializeDeserialize + Debug;
@@ -207,7 +207,7 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
type DustRemoval: OnUnbalanced<NegativeImbalance<Self, I>>;
/// The overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
/// The minimum amount required to keep an account open.
type ExistentialDeposit: Get<Self::Balance>;
@@ -223,18 +223,18 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
type MaxLocks: Get<u32>;
}
impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
impl<T: Config<I>, I: Instance> Subtrait<I> for T {
type Balance = T::Balance;
type ExistentialDeposit = T::ExistentialDeposit;
type AccountStore = T::AccountStore;
type WeightInfo = <T as Trait<I>>::WeightInfo;
type WeightInfo = <T as Config<I>>::WeightInfo;
type MaxLocks = T::MaxLocks;
}
decl_event!(
pub enum Event<T, I: Instance = DefaultInstance> where
<T as frame_system::Trait>::AccountId,
<T as Trait<I>>::Balance
<T as frame_system::Config>::AccountId,
<T as Config<I>>::Balance
{
/// An account was created with some free balance. \[account, free_balance\]
Endowed(AccountId, Balance),
@@ -259,7 +259,7 @@ decl_event!(
);
decl_error! {
pub enum Error for Module<T: Trait<I>, I: Instance> {
pub enum Error for Module<T: Config<I>, I: Instance> {
/// Vesting balance too high to send value
VestingBalance,
/// Account liquidity restrictions prevent withdrawal
@@ -382,7 +382,7 @@ impl Default for Releases {
}
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Balances {
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Balances {
/// The total units issued in the system.
pub TotalIssuance get(fn total_issuance) build(|config: &GenesisConfig<T, I>| {
config.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n)
@@ -408,7 +408,7 @@ decl_storage! {
build(|config: &GenesisConfig<T, I>| {
for (_, balance) in &config.balances {
assert!(
*balance >= <T as Trait<I>>::ExistentialDeposit::get(),
*balance >= <T as Config<I>>::ExistentialDeposit::get(),
"the balance of any account should always be more than existential deposit.",
)
}
@@ -420,7 +420,7 @@ decl_storage! {
}
decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
type Error = Error<T, I>;
/// The minimum amount required to keep an account open.
@@ -565,7 +565,7 @@ decl_module! {
}
}
impl<T: Trait<I>, I: Instance> Module<T, I> {
impl<T: Config<I>, I: Instance> Module<T, I> {
// PRIVATE MUTABLES
/// Get the free balance of an account.
@@ -704,7 +704,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
// of the inner member.
mod imbalances {
use super::{
result, DefaultInstance, Imbalance, Trait, Zero, Instance, Saturating,
result, DefaultInstance, Imbalance, Config, Zero, Instance, Saturating,
StorageValue, TryDrop,
};
use sp_std::mem;
@@ -712,9 +712,9 @@ mod imbalances {
/// Opaque, move-only struct with private fields that serves as a token denoting that
/// funds have been created without any equal and opposite accounting.
#[must_use]
pub struct PositiveImbalance<T: Trait<I>, I: Instance=DefaultInstance>(T::Balance);
pub struct PositiveImbalance<T: Config<I>, I: Instance=DefaultInstance>(T::Balance);
impl<T: Trait<I>, I: Instance> PositiveImbalance<T, I> {
impl<T: Config<I>, I: Instance> PositiveImbalance<T, I> {
/// Create a new positive imbalance from a balance.
pub fn new(amount: T::Balance) -> Self {
PositiveImbalance(amount)
@@ -724,22 +724,22 @@ mod imbalances {
/// Opaque, move-only struct with private fields that serves as a token denoting that
/// funds have been destroyed without any equal and opposite accounting.
#[must_use]
pub struct NegativeImbalance<T: Trait<I>, I: Instance=DefaultInstance>(T::Balance);
pub struct NegativeImbalance<T: Config<I>, I: Instance=DefaultInstance>(T::Balance);
impl<T: Trait<I>, I: Instance> NegativeImbalance<T, I> {
impl<T: Config<I>, I: Instance> NegativeImbalance<T, I> {
/// Create a new negative imbalance from a balance.
pub fn new(amount: T::Balance) -> Self {
NegativeImbalance(amount)
}
}
impl<T: Trait<I>, I: Instance> TryDrop for PositiveImbalance<T, I> {
impl<T: Config<I>, I: Instance> TryDrop for PositiveImbalance<T, I> {
fn try_drop(self) -> result::Result<(), Self> {
self.drop_zero()
}
}
impl<T: Trait<I>, I: Instance> Imbalance<T::Balance> for PositiveImbalance<T, I> {
impl<T: Config<I>, I: Instance> Imbalance<T::Balance> for PositiveImbalance<T, I> {
type Opposite = NegativeImbalance<T, I>;
fn zero() -> Self {
@@ -784,13 +784,13 @@ mod imbalances {
}
}
impl<T: Trait<I>, I: Instance> TryDrop for NegativeImbalance<T, I> {
impl<T: Config<I>, I: Instance> TryDrop for NegativeImbalance<T, I> {
fn try_drop(self) -> result::Result<(), Self> {
self.drop_zero()
}
}
impl<T: Trait<I>, I: Instance> Imbalance<T::Balance> for NegativeImbalance<T, I> {
impl<T: Config<I>, I: Instance> Imbalance<T::Balance> for NegativeImbalance<T, I> {
type Opposite = PositiveImbalance<T, I>;
fn zero() -> Self {
@@ -835,7 +835,7 @@ mod imbalances {
}
}
impl<T: Trait<I>, I: Instance> Drop for PositiveImbalance<T, I> {
impl<T: Config<I>, I: Instance> Drop for PositiveImbalance<T, I> {
/// Basic drop handler will just square up the total issuance.
fn drop(&mut self) {
<super::TotalIssuance<T, I>>::mutate(
@@ -844,7 +844,7 @@ mod imbalances {
}
}
impl<T: Trait<I>, I: Instance> Drop for NegativeImbalance<T, I> {
impl<T: Config<I>, I: Instance> Drop for NegativeImbalance<T, I> {
/// Basic drop handler will just square up the total issuance.
fn drop(&mut self) {
<super::TotalIssuance<T, I>>::mutate(
@@ -854,7 +854,7 @@ mod imbalances {
}
}
impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
impl<T: Config<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
T::Balance: MaybeSerializeDeserialize + Debug
{
type Balance = T::Balance;
@@ -1103,7 +1103,7 @@ impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
}
}
impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I> where
impl<T: Config<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I> where
T::Balance: MaybeSerializeDeserialize + Debug
{
/// Check if `who` can reserve `value` from their free balance.
@@ -1218,7 +1218,7 @@ impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I>
/// NOTE: You probably won't need to use this! This only needs to be "wired in" to System module
/// if you're using the local balance storage. **If you're using the composite system account
/// storage (which is the default in most examples and tests) then there's no need.**
impl<T: Trait<I>, I: Instance> OnKilledAccount<T::AccountId> for Module<T, I> {
impl<T: Config<I>, I: Instance> OnKilledAccount<T::AccountId> for Module<T, I> {
fn on_killed_account(who: &T::AccountId) {
Account::<T, I>::mutate_exists(who, |account| {
let total = account.as_ref().map(|acc| acc.total()).unwrap_or_default();
@@ -1231,7 +1231,7 @@ impl<T: Trait<I>, I: Instance> OnKilledAccount<T::AccountId> for Module<T, I> {
}
}
impl<T: Trait<I>, I: Instance> LockableCurrency<T::AccountId> for Module<T, I>
impl<T: Config<I>, I: Instance> LockableCurrency<T::AccountId> for Module<T, I>
where
T::Balance: MaybeSerializeDeserialize + Debug
{
@@ -1296,7 +1296,7 @@ where
}
}
impl<T: Trait<I>, I: Instance> IsDeadAccount<T::AccountId> for Module<T, I> where
impl<T: Config<I>, I: Instance> IsDeadAccount<T::AccountId> for Module<T, I> where
T::Balance: MaybeSerializeDeserialize + Debug
{
fn is_dead_account(who: &T::AccountId) -> bool {
+3 -3
View File
@@ -23,7 +23,7 @@
pub struct CallWithDispatchInfo;
impl sp_runtime::traits::Dispatchable for CallWithDispatchInfo {
type Origin = ();
type Trait = ();
type Config = ();
type Info = frame_support::weights::DispatchInfo;
type PostInfo = frame_support::weights::PostDispatchInfo;
@@ -55,7 +55,7 @@ macro_rules! decl_tests {
pub type System = frame_system::Module<$test>;
pub type Balances = Module<$test>;
pub const CALL: &<$test as frame_system::Trait>::Call = &$crate::tests::CallWithDispatchInfo;
pub const CALL: &<$test as frame_system::Config>::Call = &$crate::tests::CallWithDispatchInfo;
/// create a transaction info struct from weight. Handy to avoid building the whole struct.
pub fn info_from_weight(w: Weight) -> DispatchInfo {
@@ -91,7 +91,7 @@ macro_rules! decl_tests {
<$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| {
assert_eq!(Balances::free_balance(1), 10);
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 10, AllowDeath));
assert!(!<<Test as Trait>::AccountStore as StoredMap<u64, AccountData<u64>>>::is_explicit(&1));
assert!(!<<Test as Config>::AccountStore as StoredMap<u64, AccountData<u64>>>::is_explicit(&1));
});
}
@@ -29,7 +29,7 @@ use sp_io;
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types};
use frame_support::weights::{Weight, DispatchInfo, IdentityFee};
use pallet_transaction_payment::CurrencyAdapter;
use crate::{GenesisConfig, Module, Trait, decl_tests, tests::CallWithDispatchInfo};
use crate::{GenesisConfig, Module, Config, decl_tests, tests::CallWithDispatchInfo};
use frame_system as system;
impl_outer_origin!{
@@ -57,7 +57,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -87,14 +87,14 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const TransactionByteFee: u64 = 1;
}
impl pallet_transaction_payment::Trait for Test {
impl pallet_transaction_payment::Config for Test {
type OnChargeTransaction = CurrencyAdapter<Module<Test>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
}
impl Trait for Test {
impl Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
+4 -4
View File
@@ -29,7 +29,7 @@ use sp_io;
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types};
use frame_support::traits::StorageMapShim;
use frame_support::weights::{Weight, DispatchInfo, IdentityFee};
use crate::{GenesisConfig, Module, Trait, decl_tests, tests::CallWithDispatchInfo};
use crate::{GenesisConfig, Module, Config, decl_tests, tests::CallWithDispatchInfo};
use pallet_transaction_payment::CurrencyAdapter;
use frame_system as system;
@@ -58,7 +58,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -88,7 +88,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const TransactionByteFee: u64 = 1;
}
impl pallet_transaction_payment::Trait for Test {
impl pallet_transaction_payment::Config for Test {
type OnChargeTransaction = CurrencyAdapter<Module<Test>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<u64>;
@@ -97,7 +97,7 @@ impl pallet_transaction_payment::Trait for Test {
parameter_types! {
pub const MaxLocks: u32 = 50;
}
impl Trait for Test {
impl Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
+1 -1
View File
@@ -53,7 +53,7 @@ pub trait WeightInfo {
/// Weights for pallet_balances using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn transfer() -> Weight {
(94_088_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
+7 -7
View File
@@ -137,7 +137,7 @@ pub use sp_storage::TrackedStorageKey;
///
/// Test functions are automatically generated for each benchmark and are accessible to you when you
/// run `cargo test`. All tests are named `test_benchmark_<benchmark_name>`, expect you to pass them
/// the Runtime Trait, and run them in a test externalities environment. The test function runs your
/// the Runtime Config, and run them in a test externalities environment. The test function runs your
/// benchmark just like a regular benchmark, but only testing at the lowest and highest values for
/// each component. The function will return `Ok(())` if the benchmarks return no errors.
///
@@ -636,7 +636,7 @@ macro_rules! benchmark_backend {
#[allow(non_camel_case_types)]
struct $name;
#[allow(unused_variables)]
impl<T: Trait $( <$instance>, I: Instance)? >
impl<T: Config $( <$instance>, I: Instance)? >
$crate::BenchmarkingSetup<T $(, $instance)? > for $name
where $( $where_clause )*
{
@@ -710,7 +710,7 @@ macro_rules! selected_benchmark {
}
// Allow us to select a benchmark from the list of available benchmarks.
impl<T: Trait $( <$instance>, I: Instance )? >
impl<T: Config $( <$instance>, I: Instance )? >
$crate::BenchmarkingSetup<T $(, $instance )? > for SelectedBenchmark
where $( $where_clause )*
{
@@ -750,9 +750,9 @@ macro_rules! impl_benchmark {
( $( { $( $name_inst:ident )? } $name:ident )* )
( $( $name_extra:ident ),* )
) => {
impl<T: Trait $(<$instance>, I: Instance)? >
impl<T: Config $(<$instance>, I: Instance)? >
$crate::Benchmarking<$crate::BenchmarkResults> for Module<T $(, $instance)? >
where T: frame_system::Trait, $( $where_clause )*
where T: frame_system::Config, $( $where_clause )*
{
fn benchmarks(extra: bool) -> Vec<&'static [u8]> {
let mut all = vec![ $( stringify!($name).as_ref() ),* ];
@@ -948,8 +948,8 @@ macro_rules! impl_benchmark_test {
$name:ident
) => {
$crate::paste::item! {
fn [<test_benchmark_ $name>] <T: Trait > () -> Result<(), &'static str>
where T: frame_system::Trait, $( $where_clause )*
fn [<test_benchmark_ $name>] <T: Config > () -> Result<(), &'static str>
where T: frame_system::Config, $( $where_clause )*
{
let selected_benchmark = SelectedBenchmark::$name;
let components = <
+9 -9
View File
@@ -29,16 +29,16 @@ use frame_support::{
use frame_system::{RawOrigin, ensure_signed, ensure_none};
decl_storage! {
trait Store for Module<T: Trait> as Test where
<T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event>
trait Store for Module<T: Config> as Test where
<T as OtherTrait>::OtherEvent: Into<<T as Config>::Event>
{
Value get(fn value): Option<u32>;
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where
origin: T::Origin, <T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event>
pub struct Module<T: Config> for enum Call where
origin: T::Origin, <T as OtherTrait>::OtherEvent: Into<<T as Config>::Event>
{
#[weight = 0]
fn set_value(origin, n: u32) -> DispatchResult {
@@ -63,8 +63,8 @@ pub trait OtherTrait {
type OtherEvent;
}
pub trait Trait: frame_system::Trait + OtherTrait
where Self::OtherEvent: Into<<Self as Trait>::Event>
pub trait Config: frame_system::Config + OtherTrait
where Self::OtherEvent: Into<<Self as Config>::Event>
{
type Event;
}
@@ -72,7 +72,7 @@ pub trait Trait: frame_system::Trait + OtherTrait
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -100,7 +100,7 @@ impl frame_system::Trait for Test {
type SystemWeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type Event = ();
}
@@ -113,7 +113,7 @@ fn new_test_ext() -> sp_io::TestExternalities {
}
benchmarks!{
where_clause { where <T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event> }
where_clause { where <T as OtherTrait>::OtherEvent: Into<<T as Config>::Event> }
_ {
// Define a common range for `b`.
@@ -33,9 +33,9 @@ const SEED: u32 = 0;
const MAX_BYTES: u32 = 1_024;
fn assert_last_event<T: Trait<I>, I: Instance>(generic_event: <T as Trait<I>>::Event) {
fn assert_last_event<T: Config<I>, I: Instance>(generic_event: <T as Config<I>>::Event) {
let events = System::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
+21 -21
View File
@@ -121,18 +121,18 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
}
}
pub trait Trait<I: Instance=DefaultInstance>: frame_system::Trait {
pub trait Config<I: Instance=DefaultInstance>: frame_system::Config {
/// The outer origin type.
type Origin: From<RawOrigin<Self::AccountId, I>>;
/// The outer call dispatch type.
type Proposal: Parameter
+ Dispatchable<Origin=<Self as Trait<I>>::Origin, PostInfo=PostDispatchInfo>
+ Dispatchable<Origin=<Self as Config<I>>::Origin, PostInfo=PostDispatchInfo>
+ From<frame_system::Call<Self>>
+ GetDispatchInfo;
/// The outer event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
/// The time-out for council motions.
type MotionDuration: Get<Self::BlockNumber>;
@@ -166,7 +166,7 @@ pub enum RawOrigin<AccountId, I> {
}
/// Origin for the collective module.
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Trait>::AccountId, I>;
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Config>::AccountId, I>;
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
/// Info for keeping track of a motion being voted on.
@@ -184,12 +184,12 @@ pub struct Votes<AccountId, BlockNumber> {
}
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Collective {
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Collective {
/// The hashes of the active proposals.
pub Proposals get(fn proposals): Vec<T::Hash>;
/// Actual proposal for a given hash, if it's current.
pub ProposalOf get(fn proposal_of):
map hasher(identity) T::Hash => Option<<T as Trait<I>>::Proposal>;
map hasher(identity) T::Hash => Option<<T as Config<I>>::Proposal>;
/// Votes on a given proposal, if it is ongoing.
pub Voting get(fn voting):
map hasher(identity) T::Hash => Option<Votes<T::AccountId, T::BlockNumber>>;
@@ -209,8 +209,8 @@ decl_storage! {
decl_event! {
pub enum Event<T, I=DefaultInstance> where
<T as frame_system::Trait>::Hash,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::Hash,
<T as frame_system::Config>::AccountId,
{
/// A motion (given hash) has been proposed (by given account) with a threshold (given
/// `MemberCount`).
@@ -239,7 +239,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait<I>, I: Instance> {
pub enum Error for Module<T: Config<I>, I: Instance> {
/// Account is not a member
NotMember,
/// Duplicate proposals not allowed
@@ -276,7 +276,7 @@ fn get_result_weight(result: DispatchResultWithPostInfo) -> Option<Weight> {
// Note that councillor operations are assigned to the operational class.
decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Trait>::Origin {
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Config>::Origin {
type Error = Error<T, I>;
fn deposit_event() = default;
@@ -365,7 +365,7 @@ decl_module! {
DispatchClass::Operational
)]
fn execute(origin,
proposal: Box<<T as Trait<I>>::Proposal>,
proposal: Box<<T as Config<I>>::Proposal>,
#[compact] length_bound: u32,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
@@ -432,7 +432,7 @@ decl_module! {
)]
fn propose(origin,
#[compact] threshold: MemberCount,
proposal: Box<<T as Trait<I>>::Proposal>,
proposal: Box<<T as Config<I>>::Proposal>,
#[compact] length_bound: u32
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
@@ -682,7 +682,7 @@ decl_module! {
}
}
impl<T: Trait<I>, I: Instance> Module<T, I> {
impl<T: Config<I>, I: Instance> Module<T, I> {
/// Check whether `who` is a member of the collective.
pub fn is_member(who: &T::AccountId) -> bool {
// Note: The dispatchables *do not* use this to check membership so make sure
@@ -698,7 +698,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
hash: &T::Hash,
length_bound: u32,
weight_bound: Weight
) -> Result<(<T as Trait<I>>::Proposal, usize), DispatchError> {
) -> Result<(<T as Config<I>>::Proposal, usize), DispatchError> {
let key = ProposalOf::<T, I>::hashed_key_for(hash);
// read the length of the proposal storage entry directly
let proposal_len = storage::read(&key, &mut [0; 0], 0)
@@ -728,7 +728,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
seats: MemberCount,
voting: Votes<T::AccountId, T::BlockNumber>,
proposal_hash: T::Hash,
proposal: <T as Trait<I>>::Proposal,
proposal: <T as Config<I>>::Proposal,
) -> (Weight, u32) {
Self::deposit_event(RawEvent::Approved(proposal_hash));
@@ -764,7 +764,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
}
}
impl<T: Trait<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
impl<T: Config<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
/// Update the members of the collective. Votes are updated and the prime is reset.
///
/// NOTE: Does not enforce the expected `MaxMembers` limit on the amount of members, but
@@ -819,7 +819,7 @@ impl<T: Trait<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
}
}
impl<T: Trait<I>, I: Instance> InitializeMembers<T::AccountId> for Module<T, I> {
impl<T: Config<I>, I: Instance> InitializeMembers<T::AccountId> for Module<T, I> {
fn initialize_members(members: &[T::AccountId]) {
if !members.is_empty() {
assert!(<Members<T, I>>::get().is_empty(), "Members are already initialized!");
@@ -952,7 +952,7 @@ mod tests {
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -979,7 +979,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl Trait<Instance1> for Test {
impl Config<Instance1> for Test {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
@@ -989,7 +989,7 @@ mod tests {
type DefaultVote = PrimeDefaultVote;
type WeightInfo = ();
}
impl Trait<Instance2> for Test {
impl Config<Instance2> for Test {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
@@ -999,7 +999,7 @@ mod tests {
type DefaultVote = MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
+1 -1
View File
@@ -58,7 +58,7 @@ pub trait WeightInfo {
/// Weights for pallet_collective using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn set_members(m: u32, n: u32, p: u32, ) -> Weight {
(0 as Weight)
.saturating_add((20_933_000 as Weight).saturating_mul(m as Weight))
@@ -24,7 +24,7 @@
//! we define this simple definition of a contract that can be passed to `create_code` that
//! compiles it down into a `WasmModule` that can be used as a contract's code.
use crate::Trait;
use crate::Config;
use crate::Module as Contracts;
use parity_wasm::elements::{Instruction, Instructions, FuncBody, ValueType, BlockType};
@@ -87,9 +87,9 @@ pub struct ImportedMemory {
}
impl ImportedMemory {
pub fn max<T: Trait>() -> Self
pub fn max<T: Config>() -> Self
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
let pages = max_pages::<T>();
@@ -105,15 +105,15 @@ pub struct ImportedFunction {
/// A wasm module ready to be put on chain with `put_code`.
#[derive(Clone)]
pub struct WasmModule<T:Trait> {
pub struct WasmModule<T:Config> {
pub code: Vec<u8>,
pub hash: <T::Hashing as Hash>::Output,
memory: Option<ImportedMemory>,
}
impl<T: Trait> From<ModuleDefinition> for WasmModule<T>
impl<T: Config> From<ModuleDefinition> for WasmModule<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
fn from(def: ModuleDefinition) -> Self {
@@ -225,9 +225,9 @@ where
}
}
impl<T: Trait> WasmModule<T>
impl<T: Config> WasmModule<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Creates a wasm module with an empty `call` and `deploy` function and nothing else.
@@ -483,9 +483,9 @@ pub mod body {
}
/// The maximum amount of pages any contract is allowed to have according to the current `Schedule`.
pub fn max_pages<T: Trait>() -> u32
pub fn max_pages<T: Config>() -> u32
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
Contracts::<T>::current_schedule().limits.memory_pages
@@ -50,7 +50,7 @@ const API_BENCHMARK_BATCHES: u32 = 20;
const INSTR_BENCHMARK_BATCHES: u32 = 1;
/// An instantiated and deployed contract.
struct Contract<T: Trait> {
struct Contract<T: Config> {
caller: T::AccountId,
account_id: T::AccountId,
addr: <T::Lookup as StaticLookup>::Source,
@@ -72,14 +72,14 @@ impl Endow {
/// The maximum amount of balance a caller can transfer without being brought below
/// the existential deposit. This assumes that every caller is funded with the amount
/// returned by `caller_funding`.
fn max<T:Trait>() -> BalanceOf<T> {
fn max<T:Config>() -> BalanceOf<T> {
caller_funding::<T>().saturating_sub(T::Currency::minimum_balance())
}
}
impl<T: Trait> Contract<T>
impl<T: Config> Contract<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Create new contract and use a default account id as instantiator.
@@ -115,7 +115,7 @@ where
// storage_size cannot be zero because otherwise a contract that is just above
// the subsistence threshold does not pay rent given a large enough subsistence
// threshold. But we need rent payments to occur in order to benchmark for worst cases.
let storage_size = Config::<T>::subsistence_threshold_uncached()
let storage_size = ConfigCache::<T>::subsistence_threshold_uncached()
.checked_div(&T::RentDepositOffset::get())
.unwrap_or_else(Zero::zero);
@@ -212,16 +212,16 @@ where
/// A `Contract` that was evicted after accumulating some storage.
///
/// This is used to benchmark contract resurrection.
struct Tombstone<T: Trait> {
struct Tombstone<T: Config> {
/// The contract that was evicted.
contract: Contract<T>,
/// The storage the contract held when it was avicted.
storage: Vec<(StorageKey, Vec<u8>)>,
}
impl<T: Trait> Tombstone<T>
impl<T: Config> Tombstone<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Create and evict a new contract with the supplied storage item count and size each.
@@ -243,7 +243,7 @@ where
}
/// Generate `stor_num` storage items. Each has the size `stor_size`.
fn create_storage<T: Trait>(
fn create_storage<T: Config>(
stor_num: u32,
stor_size: u32
) -> Result<Vec<(StorageKey, Vec<u8>)>, &'static str> {
@@ -257,7 +257,7 @@ fn create_storage<T: Trait>(
}
/// The funding that each account that either calls or instantiates contracts is funded with.
fn caller_funding<T: Trait>() -> BalanceOf<T> {
fn caller_funding<T: Config>() -> BalanceOf<T> {
BalanceOf::<T>::max_value() / 2u32.into()
}
@@ -299,7 +299,7 @@ benchmarks! {
let s in 0 .. code::max_pages::<T>() * 64;
let data = vec![42u8; (n * 1024) as usize];
let salt = vec![42u8; (s * 1024) as usize];
let endowment = Config::<T>::subsistence_threshold_uncached();
let endowment = ConfigCache::<T>::subsistence_threshold_uncached();
let caller = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::dummy_with_mem();
@@ -374,7 +374,7 @@ benchmarks! {
// the caller should get the reward for being a good snitch
assert_eq!(
T::Currency::free_balance(&instance.caller),
caller_funding::<T>() - instance.endowment + <T as Trait>::SurchargeReward::get(),
caller_funding::<T>() - instance.endowment + <T as Config>::SurchargeReward::get(),
);
}
@@ -1127,7 +1127,7 @@ benchmarks! {
.collect::<Vec<_>>();
let account_len = accounts.get(0).map(|i| i.encode().len()).unwrap_or(0);
let account_bytes = accounts.iter().flat_map(|x| x.encode()).collect();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -1334,7 +1334,7 @@ benchmarks! {
let hash_len = hashes.get(0).map(|x| x.encode().len()).unwrap_or(0);
let hashes_bytes = hashes.iter().flat_map(|x| x.encode()).collect::<Vec<_>>();
let hashes_len = hashes_bytes.len();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -1454,7 +1454,7 @@ benchmarks! {
let input_len = inputs.get(0).map(|x| x.len()).unwrap_or(0);
let input_bytes = inputs.iter().cloned().flatten().collect::<Vec<_>>();
let inputs_len = input_bytes.len();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -20,7 +20,7 @@
///! environment that provides the seal interface as imported functions.
use super::{
Trait,
Config,
code::WasmModule,
};
use sp_core::crypto::UncheckedFrom;
@@ -39,9 +39,9 @@ impl Sandbox {
}
}
impl<T: Trait> From<&WasmModule<T>> for Sandbox
impl<T: Config> From<&WasmModule<T>> for Sandbox
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Creates an instance from the supplied module and supplies as much memory
+39 -39
View File
@@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::{
CodeHash, Config, Event, RawEvent, Trait, Module as Contracts,
CodeHash, ConfigCache, Event, RawEvent, Config, Module as Contracts,
TrieId, BalanceOf, ContractInfo, gas::GasMeter, rent::Rent, storage::{self, Storage},
Error, ContractInfoOf
};
@@ -30,14 +30,14 @@ use frame_support::{
};
use pallet_contracts_primitives::{ErrorOrigin, ExecError, ExecReturnValue, ExecResult, ReturnFlags};
pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
pub type MomentOf<T> = <<T as Trait>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Trait>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Trait>::BlockNumber;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type MomentOf<T> = <<T as Config>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Config>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type StorageKey = [u8; 32];
/// A type that represents a topic of an event. At the moment a hash is used.
pub type TopicOf<T> = <T as frame_system::Trait>::Hash;
pub type TopicOf<T> = <T as frame_system::Config>::Hash;
/// Describes whether we deal with a contract or a plain account.
pub enum TransactorKind {
@@ -54,7 +54,7 @@ pub enum TransactorKind {
/// This interface is specialized to an account of the executing code, so all
/// operations are implicitly performed on that account.
pub trait Ext {
type T: Trait;
type T: Config;
/// Returns the storage entry of the executing account by the given `key`.
///
@@ -171,7 +171,7 @@ pub trait Ext {
/// Loader is a companion of the `Vm` trait. It loads an appropriate abstract
/// executable to be executed by an accompanying `Vm` implementation.
pub trait Loader<T: Trait> {
pub trait Loader<T: Config> {
type Executable;
/// Load the initializer portion of the code specified by the `code_hash`. This
@@ -190,7 +190,7 @@ pub trait Loader<T: Trait> {
///
/// Execution of code can end by either implicit termination (that is, reached the end of
/// executable), explicit termination via returning a buffer or termination due to a trap.
pub trait Vm<T: Trait> {
pub trait Vm<T: Config> {
type Executable;
fn execute<E: Ext<T = T>>(
@@ -202,12 +202,12 @@ pub trait Vm<T: Trait> {
) -> ExecResult;
}
pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
pub struct ExecutionContext<'a, T: Config + 'a, V, L> {
pub caller: Option<&'a ExecutionContext<'a, T, V, L>>,
pub self_account: T::AccountId,
pub self_trie_id: Option<TrieId>,
pub depth: usize,
pub config: &'a Config<T>,
pub config: &'a ConfigCache<T>,
pub vm: &'a V,
pub loader: &'a L,
pub timestamp: MomentOf<T>,
@@ -216,7 +216,7 @@ pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
impl<'a, T, E, V, L> ExecutionContext<'a, T, V, L>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
L: Loader<T, Executable = E>,
V: Vm<T, Executable = E>,
@@ -225,7 +225,7 @@ where
///
/// The specified `origin` address will be used as `sender` for. The `origin` must be a regular
/// account (not a contract).
pub fn top_level(origin: T::AccountId, cfg: &'a Config<T>, vm: &'a V, loader: &'a L) -> Self {
pub fn top_level(origin: T::AccountId, cfg: &'a ConfigCache<T>, vm: &'a V, loader: &'a L) -> Self {
ExecutionContext {
caller: None,
self_trie_id: None,
@@ -437,7 +437,7 @@ enum TransferCause {
/// is specified as `Terminate`. Otherwise, any transfer that would bring the sender below the
/// subsistence threshold (for contracts) or the existential deposit (for plain accounts)
/// results in an error.
fn transfer<'a, T: Trait, V: Vm<T>, L: Loader<T>>(
fn transfer<'a, T: Config, V: Vm<T>, L: Loader<T>>(
cause: TransferCause,
origin: TransactorKind,
transactor: &T::AccountId,
@@ -483,7 +483,7 @@ where
/// implies that the control won't be returned to the contract anymore, but there is still some code
/// on the path of the return from that call context. Therefore, care must be taken in these
/// situations.
struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm<T> + 'b, L: Loader<T>> {
struct CallContext<'a, 'b: 'a, T: Config + 'b, V: Vm<T> + 'b, L: Loader<T>> {
ctx: &'a mut ExecutionContext<'b, T, V, L>,
caller: T::AccountId,
value_transferred: BalanceOf<T>,
@@ -493,7 +493,7 @@ struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm<T> + 'b, L: Loader<T>> {
impl<'a, 'b: 'a, T, E, V, L> Ext for CallContext<'a, 'b, T, V, L>
where
T: Trait + 'b,
T: Config + 'b,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
V: Vm<T, Executable = E>,
L: Loader<T, Executable = E>,
@@ -693,13 +693,13 @@ where
}
}
fn deposit_event<T: Trait>(
fn deposit_event<T: Config>(
topics: Vec<T::Hash>,
event: Event<T>,
) {
<frame_system::Module<T>>::deposit_event_indexed(
&*topics,
<T as Trait>::Event::from(event).into(),
<T as Config>::Event::from(event).into(),
)
}
@@ -716,7 +716,7 @@ mod tests {
};
use crate::{
gas::GasMeter, tests::{ExtBuilder, Test, MetaEvent},
exec::ExecReturnValue, CodeHash, Config,
exec::ExecReturnValue, CodeHash, ConfigCache,
gas::Gas,
storage::Storage,
tests::{ALICE, BOB, CHARLIE},
@@ -769,7 +769,7 @@ mod tests {
fn insert(&mut self, f: impl Fn(MockCtx) -> ExecResult + 'a) -> CodeHash<Test> {
// Generate code hashes as monotonically increasing values.
let code_hash = <Test as frame_system::Trait>::Hash::from_low_u64_be(self.counter);
let code_hash = <Test as frame_system::Config>::Hash::from_low_u64_be(self.counter);
self.counter += 1;
self.map.insert(code_hash, MockExecutable::new(f));
@@ -843,7 +843,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, exec_ch);
@@ -867,7 +867,7 @@ mod tests {
let loader = MockLoader::empty();
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
set_balance(&origin, 100);
set_balance(&dest, 0);
@@ -900,7 +900,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
set_balance(&origin, 100);
@@ -930,7 +930,7 @@ mod tests {
let loader = MockLoader::empty();
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
set_balance(&origin, 0);
@@ -966,7 +966,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
@@ -997,7 +997,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
@@ -1025,7 +1025,7 @@ mod tests {
// This one tests passing the input data into a contract via call.
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, input_data_ch);
@@ -1050,7 +1050,7 @@ mod tests {
// This one tests passing the input data into a contract via instantiate.
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 100);
@@ -1097,7 +1097,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&BOB, 1);
place_contract(&BOB, recurse_ch);
@@ -1142,7 +1142,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
place_contract(&dest, bob_ch);
@@ -1184,7 +1184,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, bob_ch);
place_contract(&CHARLIE, charlie_ch);
@@ -1208,7 +1208,7 @@ mod tests {
let dummy_ch = loader.insert(|_| exec_success());
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
assert_matches!(
@@ -1234,7 +1234,7 @@ mod tests {
);
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1268,7 +1268,7 @@ mod tests {
);
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1303,7 +1303,7 @@ mod tests {
// Instantiate a contract and save it's address in `instantiated_contract_address`.
let (address, output) = ctx.ext.instantiate(
&dummy_ch,
Config::<Test>::subsistence_threshold_uncached(),
ConfigCache::<Test>::subsistence_threshold_uncached(),
ctx.gas_meter,
vec![],
&[48, 49, 50],
@@ -1315,7 +1315,7 @@ mod tests {
});
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
set_balance(&BOB, 100);
@@ -1368,7 +1368,7 @@ mod tests {
});
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
set_balance(&BOB, 100);
@@ -1400,7 +1400,7 @@ mod tests {
.existential_deposit(15)
.build()
.execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1434,7 +1434,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 100);
+4 -4
View File
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::Trait;
use crate::Config;
use sp_std::marker::PhantomData;
use sp_runtime::traits::Zero;
use frame_support::dispatch::{
@@ -60,7 +60,7 @@ impl<T: Any + Debug + PartialEq + Eq> TestAuxiliaries for T {}
/// Implementing type is expected to be super lightweight hence `Copy` (`Clone` is added
/// for consistency). If inlined there should be no observable difference compared
/// to a hand-written code.
pub trait Token<T: Trait>: Copy + Clone + TestAuxiliaries {
pub trait Token<T: Config>: Copy + Clone + TestAuxiliaries {
/// Metadata type, which the token can require for calculating the amount
/// of gas to charge. Can be a some configuration type or
/// just the `()`.
@@ -84,7 +84,7 @@ pub struct ErasedToken {
pub token: Box<dyn Any>,
}
pub struct GasMeter<T: Trait> {
pub struct GasMeter<T: Config> {
gas_limit: Gas,
/// Amount of gas left from initial gas limit. Can reach zero.
gas_left: Gas,
@@ -92,7 +92,7 @@ pub struct GasMeter<T: Trait> {
#[cfg(test)]
tokens: Vec<ErasedToken>,
}
impl<T: Trait> GasMeter<T> {
impl<T: Config> GasMeter<T> {
pub fn new(gas_limit: Gas) -> Self {
GasMeter {
gas_limit,
+23 -23
View File
@@ -18,7 +18,7 @@
//!
//! The Contract module provides functionality for the runtime to deploy and execute WebAssembly smart-contracts.
//!
//! - [`contract::Trait`](./trait.Trait.html)
//! - [`contract::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -126,18 +126,18 @@ use pallet_contracts_primitives::{
};
use frame_support::weights::Weight;
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
pub type CodeHash<T> = <T as frame_system::Config>::Hash;
pub type TrieId = Vec<u8>;
/// Information for managing an account and its sub trie abstraction.
/// This is the required info to cache for an account
#[derive(Encode, Decode, RuntimeDebug)]
pub enum ContractInfo<T: Trait> {
pub enum ContractInfo<T: Config> {
Alive(AliveContractInfo<T>),
Tombstone(TombstoneContractInfo<T>),
}
impl<T: Trait> ContractInfo<T> {
impl<T: Config> ContractInfo<T> {
/// If contract is alive then return some alive info
pub fn get_alive(self) -> Option<AliveContractInfo<T>> {
if let ContractInfo::Alive(alive) = self {
@@ -190,7 +190,7 @@ impl<T: Trait> ContractInfo<T> {
}
pub type AliveContractInfo<T> =
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as frame_system::Trait>::BlockNumber>;
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as frame_system::Config>::BlockNumber>;
/// Information for managing an account and its sub trie abstraction.
/// This is the required info to cache for an account.
@@ -230,7 +230,7 @@ pub(crate) fn child_trie_info(trie_id: &[u8]) -> ChildInfo {
}
pub type TombstoneContractInfo<T> =
RawTombstoneContractInfo<<T as frame_system::Trait>::Hash, <T as frame_system::Trait>::Hashing>;
RawTombstoneContractInfo<<T as frame_system::Config>::Hash, <T as frame_system::Config>::Hashing>;
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
pub struct RawTombstoneContractInfo<H, Hasher>(H, PhantomData<Hasher>);
@@ -250,18 +250,18 @@ where
}
}
impl<T: Trait> From<AliveContractInfo<T>> for ContractInfo<T> {
impl<T: Config> From<AliveContractInfo<T>> for ContractInfo<T> {
fn from(alive_info: AliveContractInfo<T>) -> Self {
Self::Alive(alive_info)
}
}
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
type Time: Time;
type Randomness: Randomness<Self::Hash>;
@@ -269,7 +269,7 @@ pub trait Trait: frame_system::Trait {
type Currency: Currency<Self::AccountId>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Handler for rent payments.
type RentPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -323,7 +323,7 @@ pub trait Trait: frame_system::Trait {
decl_error! {
/// Error for the contracts module.
pub enum Error for Module<T: Trait>
pub enum Error for Module<T: Config>
where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
@@ -383,7 +383,7 @@ decl_error! {
decl_module! {
/// Contracts module.
pub struct Module<T: Trait> for enum Call
pub struct Module<T: Config> for enum Call
where
origin: T::Origin,
T::AccountId: UncheckedFrom<T::Hash>,
@@ -564,7 +564,7 @@ decl_module! {
}
/// Public APIs provided by the contracts module.
impl<T: Trait> Module<T>
impl<T: Config> Module<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
@@ -638,7 +638,7 @@ where
}
}
impl<T: Trait> Module<T>
impl<T: Config> Module<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
@@ -647,7 +647,7 @@ where
gas_meter: &mut GasMeter<T>,
func: impl FnOnce(&mut ExecutionContext<T, WasmVm<T>, WasmLoader<T>>, &mut GasMeter<T>) -> ExecResult,
) -> ExecResult {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let vm = WasmVm::new(&cfg.schedule);
let loader = WasmLoader::new(&cfg.schedule);
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
@@ -659,8 +659,8 @@ decl_event! {
pub enum Event<T>
where
Balance = BalanceOf<T>,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Trait>::Hash
<T as frame_system::Config>::AccountId,
<T as frame_system::Config>::Hash
{
/// Contract deployed by address at the specified address. \[owner, contract\]
Instantiated(AccountId, AccountId),
@@ -699,7 +699,7 @@ decl_event! {
}
decl_storage! {
trait Store for Module<T: Trait> as Contracts
trait Store for Module<T: Config> as Contracts
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -722,7 +722,7 @@ decl_storage! {
///
/// We assume that these values can't be changed in the
/// course of transaction execution.
pub struct Config<T: Trait> {
pub struct ConfigCache<T: Config> {
pub schedule: Schedule<T>,
pub existential_deposit: BalanceOf<T>,
pub tombstone_deposit: BalanceOf<T>,
@@ -730,12 +730,12 @@ pub struct Config<T: Trait> {
pub max_value_size: u32,
}
impl<T: Trait> Config<T>
impl<T: Config> ConfigCache<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
fn preload() -> Config<T> {
Config {
fn preload() -> ConfigCache<T> {
ConfigCache {
schedule: <Module<T>>::current_schedule(),
existential_deposit: T::Currency::minimum_balance(),
tombstone_deposit: T::TombstoneDeposit::get(),
+6 -6
View File
@@ -18,7 +18,7 @@
use crate::{
AliveContractInfo, BalanceOf, ContractInfo, ContractInfoOf, Module, RawEvent,
TombstoneContractInfo, Trait, CodeHash, Config, Error,
TombstoneContractInfo, Config, CodeHash, ConfigCache, Error,
};
use sp_std::prelude::*;
use sp_io::hashing::blake2_256;
@@ -36,11 +36,11 @@ use sp_runtime::{
///
/// This amount respects the contract's rent allowance and the subsistence deposit.
/// Because of that, charging the amount cannot remove the contract.
struct OutstandingAmount<T: Trait> {
struct OutstandingAmount<T: Config> {
amount: BalanceOf<T>,
}
impl<T: Trait> OutstandingAmount<T> {
impl<T: Config> OutstandingAmount<T> {
/// Create the new outstanding amount.
///
/// The amount should be always withdrawable and it should not kill the account.
@@ -67,7 +67,7 @@ impl<T: Trait> OutstandingAmount<T> {
}
}
enum Verdict<T: Trait> {
enum Verdict<T: Config> {
/// The contract is exempted from paying rent.
///
/// For example, it already paid its rent in the current block, or it has enough deposit for not
@@ -90,7 +90,7 @@ pub struct Rent<T>(sp_std::marker::PhantomData<T>);
impl<T> Rent<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
/// Returns a fee charged per block from the contract.
@@ -129,7 +129,7 @@ where
free_balance: &BalanceOf<T>,
contract: &AliveContractInfo<T>,
) -> Option<BalanceOf<T>> {
let subsistence_threshold = Config::<T>::subsistence_threshold_uncached();
let subsistence_threshold = ConfigCache::<T>::subsistence_threshold_uncached();
// Reserved balance contributes towards the subsistence threshold to stay consistent
// with the existential deposit where the reserved balance is also counted.
if *total_balance < subsistence_threshold {
+10 -10
View File
@@ -17,7 +17,7 @@
//! This module contains the cost schedule and supporting code that constructs a
//! sane default schedule from a `WeightInfo` implementation.
use crate::{Trait, weights::WeightInfo};
use crate::{Config, weights::WeightInfo};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
@@ -42,7 +42,7 @@ pub const INSTR_BENCHMARK_BATCH_SIZE: u32 = 1_000;
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(bound(serialize = "", deserialize = "")))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug)]
pub struct Schedule<T: Trait> {
pub struct Schedule<T: Config> {
/// Version of the schedule.
pub version: u32,
@@ -131,7 +131,7 @@ pub struct Limits {
/// and dropping return values in order to maintain a valid module.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, WeightDebug)]
pub struct InstructionWeights<T: Trait> {
pub struct InstructionWeights<T: Config> {
pub i64const: u32,
pub i64load: u32,
pub i64store: u32,
@@ -190,7 +190,7 @@ pub struct InstructionWeights<T: Trait> {
/// Describes the weight for each imported function that a contract is allowed to call.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, WeightDebug)]
pub struct HostFnWeights<T: Trait> {
pub struct HostFnWeights<T: Config> {
/// Weight of calling `seal_caller`.
pub caller: Weight,
@@ -410,7 +410,7 @@ macro_rules! cost_byte_batched {
}
}
impl<T: Trait> Default for Schedule<T> {
impl<T: Config> Default for Schedule<T> {
fn default() -> Self {
Self {
version: 0,
@@ -440,7 +440,7 @@ impl Default for Limits {
}
}
impl<T: Trait> Default for InstructionWeights<T> {
impl<T: Config> Default for InstructionWeights<T> {
fn default() -> Self {
let max_pages = Limits::default().memory_pages;
Self {
@@ -500,7 +500,7 @@ impl<T: Trait> Default for InstructionWeights<T> {
}
}
impl<T: Trait> Default for HostFnWeights<T> {
impl<T: Config> Default for HostFnWeights<T> {
fn default() -> Self {
Self {
caller: cost_batched!(seal_caller),
@@ -554,12 +554,12 @@ impl<T: Trait> Default for HostFnWeights<T> {
}
}
struct ScheduleRules<'a, T: Trait> {
struct ScheduleRules<'a, T: Config> {
schedule: &'a Schedule<T>,
params: Vec<u32>,
}
impl<T: Trait> Schedule<T> {
impl<T: Config> Schedule<T> {
pub fn rules(&self, module: &elements::Module) -> impl rules::Rules + '_ {
ScheduleRules {
schedule: &self,
@@ -576,7 +576,7 @@ impl<T: Trait> Schedule<T> {
}
}
impl<'a, T: Trait> rules::Rules for ScheduleRules<'a, T> {
impl<'a, T: Config> rules::Rules for ScheduleRules<'a, T> {
fn instruction_cost(&self, instruction: &elements::Instruction) -> Option<u32> {
use parity_wasm::elements::Instruction::*;
let w = &self.schedule.instruction_weights;
+2 -2
View File
@@ -18,7 +18,7 @@
use crate::{
exec::{AccountIdOf, StorageKey},
AliveContractInfo, BalanceOf, CodeHash, ContractInfo, ContractInfoOf, Trait, TrieId,
AliveContractInfo, BalanceOf, CodeHash, ContractInfo, ContractInfoOf, Config, TrieId,
AccountCounter,
};
use sp_std::prelude::*;
@@ -37,7 +37,7 @@ pub struct Storage<T>(PhantomData<T>);
impl<T> Storage<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
/// Reads a storage kv pair of a contract.
+25 -25
View File
@@ -16,8 +16,8 @@
use crate::{
BalanceOf, ContractInfo, ContractInfoOf, GenesisConfig, Module,
RawAliveContractInfo, RawEvent, Trait, Schedule, gas::Gas,
Error, Config, RuntimeReturnCode, storage::Storage,
RawAliveContractInfo, RawEvent, Config, Schedule, gas::Gas,
Error, ConfigCache, RuntimeReturnCode, storage::Storage,
exec::AccountIdOf,
};
use assert_matches::assert_matches;
@@ -110,7 +110,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -137,7 +137,7 @@ impl frame_system::Trait for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = MetaEvent;
@@ -149,7 +149,7 @@ impl pallet_balances::Trait for Test {
parameter_types! {
pub const MinimumPeriod: u64 = 1;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -176,7 +176,7 @@ impl Convert<Weight, BalanceOf<Self>> for Test {
}
}
impl Trait for Test {
impl Config for Test {
type Time = Timestamp;
type Randomness = Randomness;
type Currency = Balances;
@@ -251,7 +251,7 @@ fn compile_module<T>(
fixture_name: &str,
) -> wat::Result<(Vec<u8>, <T::Hashing as Hash>::Output)>
where
T: frame_system::Trait,
T: frame_system::Config,
{
let fixture_path = ["fixtures/", fixture_name, ".wat"].concat();
let wasm_binary = wat::parse_file(fixture_path)?;
@@ -367,7 +367,7 @@ fn instantiate_and_call_and_deposit_event() {
.build()
.execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
let subsistence = super::Config::<Test>::subsistence_threshold_uncached();
let subsistence = super::ConfigCache::<Test>::subsistence_threshold_uncached();
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
@@ -472,7 +472,7 @@ fn deposit_event_max_value_limit() {
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer,
<Test as Trait>::MaxValueSize::get().encode(),
<Test as Config>::MaxValueSize::get().encode(),
));
// Call contract with too large a storage value.
@@ -482,7 +482,7 @@ fn deposit_event_max_value_limit() {
addr,
0,
GAS_LIMIT,
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
(<Test as Config>::MaxValueSize::get() + 1).encode(),
),
Error::<Test>::ValueTooLarge,
);
@@ -591,7 +591,7 @@ fn storage_size() {
30_000,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -725,7 +725,7 @@ fn deduct_blocks() {
Origin::signed(ALICE),
30_000,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -830,7 +830,7 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn(AccountIdOf<Test>) -> bool
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -869,7 +869,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -911,7 +911,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
1_000,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(100u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(100u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -960,14 +960,14 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
// Create
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
let subsistence_threshold =
Balances::minimum_balance() + <Test as Trait>::TombstoneDeposit::get();
Balances::minimum_balance() + <Test as Config>::TombstoneDeposit::get();
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm.clone()));
assert_ok!(Contracts::instantiate(
Origin::signed(ALICE),
50 + subsistence_threshold,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -1039,7 +1039,7 @@ fn call_removed_contract() {
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -1177,7 +1177,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
30_000,
GAS_LIMIT,
set_rent_code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(0u32).encode(),
<Test as pallet_balances::Config>::Balance::from(0u32).encode(),
vec![],
));
let addr_bob = Contracts::contract_address(&ALICE, &set_rent_code_hash, &[]);
@@ -1227,7 +1227,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
30_000,
GAS_LIMIT,
restoration_code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(0u32).encode(),
<Test as pallet_balances::Config>::Balance::from(0u32).encode(),
vec![],
));
let addr_django = Contracts::contract_address(&CHARLIE, &restoration_code_hash, &[]);
@@ -1384,7 +1384,7 @@ fn storage_max_value_limit() {
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer
<Test as Trait>::MaxValueSize::get().encode(),
<Test as Config>::MaxValueSize::get().encode(),
));
// Call contract with too large a storage value.
@@ -1394,7 +1394,7 @@ fn storage_max_value_limit() {
addr,
0,
GAS_LIMIT,
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
(<Test as Config>::MaxValueSize::get() + 1).encode(),
),
Error::<Test>::ValueTooLarge,
);
@@ -1709,7 +1709,7 @@ fn crypto_hashes() {
fn transfer_return_code() {
let (wasm, code_hash) = compile_module::<Test>("transfer_return_code").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
@@ -1756,7 +1756,7 @@ fn call_return_code() {
let (caller_code, caller_hash) = compile_module::<Test>("call_return_code").unwrap();
let (callee_code, callee_hash) = compile_module::<Test>("ok_trap_revert").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
let _ = Balances::deposit_creating(&CHARLIE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), caller_code));
@@ -1849,7 +1849,7 @@ fn instantiate_return_code() {
let (caller_code, caller_hash) = compile_module::<Test>("instantiate_return_code").unwrap();
let (callee_code, callee_hash) = compile_module::<Test>("ok_trap_revert").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
let _ = Balances::deposit_creating(&CHARLIE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), caller_code));
@@ -27,7 +27,7 @@
//! Thus, before executing a contract it should be reinstrument with new schedule.
use crate::wasm::{prepare, runtime::Env, PrefabWasmModule};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Trait};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Config};
use sp_std::prelude::*;
use sp_runtime::traits::Hash;
use sp_core::crypto::UncheckedFrom;
@@ -37,7 +37,7 @@ use frame_support::StorageMap;
/// as a result of this function.
///
/// This function instruments the given code and caches it in the storage.
pub fn save<T: Trait>(
pub fn save<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -55,7 +55,7 @@ pub fn save<T: Trait>(
/// This version neither checks nor instruments the passed in code. This is useful
/// when code needs to be benchmarked without the injected instrumentation.
#[cfg(feature = "runtime-benchmarks")]
pub fn save_raw<T: Trait>(
pub fn save_raw<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -73,7 +73,7 @@ pub fn save_raw<T: Trait>(
/// If the module was instrumented with a lower version of schedule than
/// the current one given as an argument, then this function will perform
/// re-instrumentation and update the cache in the storage.
pub fn load<T: Trait>(
pub fn load<T: Config>(
code_hash: &CodeHash<T>,
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -129,8 +129,8 @@ macro_rules! define_func {
args: &[sp_sandbox::Value],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError>
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
#[allow(unused)]
@@ -190,8 +190,8 @@ macro_rules! define_env {
impl<E: Ext> $crate::wasm::env_def::FunctionImplProvider<E> for $init_name
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
fn impls<F: FnMut(&[u8], $crate::wasm::env_def::HostFunc<E>)>(f: &mut F) {
+9 -9
View File
@@ -17,7 +17,7 @@
//! This module provides a means for executing contracts
//! represented in wasm.
use crate::{CodeHash, Schedule, Trait};
use crate::{CodeHash, Schedule, Config};
use crate::wasm::env_def::FunctionImplProvider;
use crate::exec::Ext;
use crate::gas::GasMeter;
@@ -68,17 +68,17 @@ pub struct WasmExecutable {
}
/// Loader which fetches `WasmExecutable` from the code cache.
pub struct WasmLoader<'a, T: Trait> {
pub struct WasmLoader<'a, T: Config> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmLoader { schedule }
}
}
impl<'a, T: Trait> crate::exec::Loader<T> for WasmLoader<'a, T>
impl<'a, T: Config> crate::exec::Loader<T> for WasmLoader<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -101,17 +101,17 @@ where
}
/// Implementation of `Vm` that takes `WasmExecutable` and executes it.
pub struct WasmVm<'a, T: Trait> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub struct WasmVm<'a, T: Config> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmVm { schedule }
}
}
impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a, T>
impl<'a, T: Config> crate::exec::Vm<T> for WasmVm<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -462,8 +462,8 @@ mod tests {
gas_meter: &mut GasMeter<E::T>,
) -> ExecResult
where
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
use crate::exec::Vm;
@@ -20,7 +20,7 @@
use crate::wasm::env_def::ImportSatisfyCheck;
use crate::wasm::PrefabWasmModule;
use crate::{Schedule, Trait};
use crate::{Schedule, Config};
use parity_wasm::elements::{self, Internal, External, MemoryType, Type, ValueType};
use pwasm_utils;
@@ -34,13 +34,13 @@ pub const IMPORT_MODULE_FN: &str = "seal0";
/// compiler toolchains might not support specifying other modules than "env" for memory imports.
pub const IMPORT_MODULE_MEMORY: &str = "env";
struct ContractModule<'a, T: Trait> {
struct ContractModule<'a, T: Config> {
/// A deserialized module. The module is valid (this is Guaranteed by `new` method).
module: elements::Module,
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> ContractModule<'a, T> {
impl<'a, T: Config> ContractModule<'a, T> {
/// Creates a new instance of `ContractModule`.
///
/// Returns `Err` if the `original_code` couldn't be decoded or
@@ -369,7 +369,7 @@ impl<'a, T: Trait> ContractModule<'a, T> {
}
}
fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<T>)
fn get_memory_limits<T: Config>(module: Option<&MemoryType>, schedule: &Schedule<T>)
-> Result<(u32, u32), &'static str>
{
if let Some(memory_type) = module {
@@ -410,7 +410,7 @@ fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<
/// - all imported functions from the external environment matches defined by `env` module,
///
/// The preprocessing includes injecting code for gas metering and metering the height of stack.
pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
pub fn prepare_contract<C: ImportSatisfyCheck, T: Config>(
original_code: &[u8],
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> {
@@ -452,7 +452,7 @@ pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking {
use super::{
Trait, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
Config, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
};
use parity_wasm::elements::FunctionType;
@@ -463,7 +463,7 @@ pub mod benchmarking {
}
/// Prepare function that neither checks nor instruments the passed in code.
pub fn prepare_contract<T: Trait>(original_code: &[u8], schedule: &Schedule<T>)
pub fn prepare_contract<T: Config>(original_code: &[u8], schedule: &Schedule<T>)
-> Result<PrefabWasmModule, &'static str>
{
let contract_module = ContractModule::new(original_code, schedule)?;
@@ -17,7 +17,7 @@
//! Environment definition of the wasm smart-contract runtime.
use crate::{
HostFnWeights, Schedule, Trait, CodeHash, BalanceOf, Error,
HostFnWeights, Schedule, Config, CodeHash, BalanceOf, Error,
exec::{Ext, StorageKey, TopicOf},
gas::{Gas, GasMeter, Token, GasMeterResult},
wasm::env_def::ConvertibleToWasm,
@@ -193,7 +193,7 @@ pub enum RuntimeToken {
HashBlake128(u32),
}
impl<T: Trait> Token<T> for RuntimeToken
impl<T: Config> Token<T> for RuntimeToken
where
T::AccountId: UncheckedFrom<T::Hash>, T::AccountId: AsRef<[u8]>
{
@@ -291,8 +291,8 @@ pub struct Runtime<'a, E: Ext + 'a> {
impl<'a, E> Runtime<'a, E>
where
E: Ext + 'a,
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
pub fn new(
ext: &'a mut E,
@@ -709,7 +709,7 @@ define_env!(Env, <E: Ext>,
value_len: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::Transfer)?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(account_ptr, account_len)?;
let value: BalanceOf<<E as Ext>::T> =
ctx.read_sandbox_memory_as(value_ptr, value_len)?;
@@ -762,7 +762,7 @@ define_env!(Env, <E: Ext>,
output_len_ptr: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::CallBase(input_data_len))?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(callee_ptr, callee_len)?;
let value: BalanceOf<<E as Ext>::T> = ctx.read_sandbox_memory_as(value_ptr, value_len)?;
let input_data = ctx.read_sandbox_memory(input_data_ptr, input_data_len)?;
@@ -922,7 +922,7 @@ define_env!(Env, <E: Ext>,
beneficiary_len: u32
) => {
ctx.charge_gas(RuntimeToken::Terminate)?;
let beneficiary: <<E as Ext>::T as frame_system::Trait>::AccountId =
let beneficiary: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(beneficiary_ptr, beneficiary_len)?;
if let Ok(_) = ctx.ext.terminate(&beneficiary).map_err(|e| ctx.store_err(e)) {
@@ -1169,7 +1169,7 @@ define_env!(Env, <E: Ext>,
delta_count: u32
) => {
ctx.charge_gas(RuntimeToken::RestoreTo(delta_count))?;
let dest: <<E as Ext>::T as frame_system::Trait>::AccountId =
let dest: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(dest_ptr, dest_len)?;
let code_hash: CodeHash<<E as Ext>::T> =
ctx.read_sandbox_memory_as(code_hash_ptr, code_hash_len)?;
+1 -1
View File
@@ -144,7 +144,7 @@ pub trait WeightInfo {
/// Weights for pallet_contracts using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn update_schedule() -> Weight {
(35_214_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
@@ -34,21 +34,21 @@ const MAX_REFERENDUMS: u32 = 99;
const MAX_SECONDERS: u32 = 100;
const MAX_BYTES: u32 = 16_384;
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = System::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}
fn funded_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let caller: T::AccountId = account(name, index, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
caller
}
fn add_proposal<T: Trait>(n: u32) -> Result<T::Hash, &'static str> {
fn add_proposal<T: Config>(n: u32) -> Result<T::Hash, &'static str> {
let other = funded_account::<T>("proposer", n);
let value = T::MinimumDeposit::get();
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
@@ -62,7 +62,7 @@ fn add_proposal<T: Trait>(n: u32) -> Result<T::Hash, &'static str> {
Ok(proposal_hash)
}
fn add_referendum<T: Trait>(n: u32) -> Result<ReferendumIndex, &'static str> {
fn add_referendum<T: Config>(n: u32) -> Result<ReferendumIndex, &'static str> {
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
let vote_threshold = VoteThreshold::SimpleMajority;
@@ -84,7 +84,7 @@ fn add_referendum<T: Trait>(n: u32) -> Result<ReferendumIndex, &'static str> {
Ok(referendum_index)
}
fn account_vote<T: Trait>(b: BalanceOf<T>) -> AccountVote<BalanceOf<T>> {
fn account_vote<T: Config>(b: BalanceOf<T>) -> AccountVote<BalanceOf<T>> {
let v = Vote {
aye: true,
conviction: Conviction::Locked1x,
+12 -12
View File
@@ -17,7 +17,7 @@
//! # Democracy Pallet
//!
//! - [`democracy::Trait`](./trait.Trait.html)
//! - [`democracy::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -199,13 +199,13 @@ pub type PropIndex = u32;
/// A referendum index.
pub type ReferendumIndex = u32;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub trait Trait: frame_system::Trait + Sized {
pub trait Config: frame_system::Config + Sized {
type Proposal: Parameter + Dispatchable<Origin=Self::Origin> + From<Call<Self>>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Currency type for this module.
type Currency: ReservableCurrency<Self::AccountId>
@@ -338,7 +338,7 @@ enum Releases {
}
decl_storage! {
trait Store for Module<T: Trait> as Democracy {
trait Store for Module<T: Config> as Democracy {
// TODO: Refactor public proposal queue into its own pallet.
// https://github.com/paritytech/substrate/issues/5322
/// The number of (public) proposals that have been made so far.
@@ -413,9 +413,9 @@ decl_storage! {
decl_event! {
pub enum Event<T> where
Balance = BalanceOf<T>,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Trait>::Hash,
<T as frame_system::Trait>::BlockNumber,
<T as frame_system::Config>::AccountId,
<T as frame_system::Config>::Hash,
<T as frame_system::Config>::BlockNumber,
{
/// A motion has been proposed by a public account. \[proposal_index, deposit\]
Proposed(PropIndex, Balance),
@@ -461,7 +461,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Value too low
ValueLow,
/// Proposal does not exist
@@ -537,7 +537,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// The minimum period of locking and the period between a proposal being approved and enacted.
@@ -1168,7 +1168,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
// exposed immutables.
/// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal
+5 -5
View File
@@ -92,7 +92,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type Origin = Origin;
type Index = u64;
@@ -122,7 +122,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
}
impl pallet_scheduler::Trait for Test {
impl pallet_scheduler::Config for Test {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
@@ -135,7 +135,7 @@ impl pallet_scheduler::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = Event;
@@ -173,7 +173,7 @@ impl Contains<u64> for OneToFive {
fn add(_m: &u64) {}
}
impl super::Trait for Test {
impl super::Config for Test {
type Proposal = Call;
type Event = Event;
type Currency = pallet_balances::Module<Self>;
@@ -242,7 +242,7 @@ fn set_balance_proposal(value: u64) -> Vec<u8> {
fn set_balance_proposal_is_correctly_filtered_out() {
for i in 0..10 {
let call = Call::decode(&mut &set_balance_proposal(i)[..]).unwrap();
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ pub trait WeightInfo {
/// Weights for pallet_democracy using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn propose() -> Weight {
(87_883_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
@@ -30,7 +30,7 @@ const BALANCE_FACTOR: u32 = 250;
const MAX_VOTERS: u32 = 500;
const MAX_CANDIDATES: u32 = 200;
type Lookup<T> = <<T as frame_system::Trait>::Lookup as StaticLookup>::Source;
type Lookup<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
macro_rules! whitelist {
($acc:ident) => {
@@ -41,7 +41,7 @@ macro_rules! whitelist {
}
/// grab new account with infinite balance.
fn endowed_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
fn endowed_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let account: T::AccountId = account(name, index, 0);
let amount = default_stake::<T>(BALANCE_FACTOR);
let _ = T::Currency::make_free_balance_be(&account, amount);
@@ -53,28 +53,28 @@ fn endowed_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
}
/// Account to lookup type of system trait.
fn as_lookup<T: Trait>(account: T::AccountId) -> Lookup<T> {
fn as_lookup<T: Config>(account: T::AccountId) -> Lookup<T> {
T::Lookup::unlookup(account)
}
/// Get a reasonable amount of stake based on the execution trait's configuration
fn default_stake<T: Trait>(factor: u32) -> BalanceOf<T> {
fn default_stake<T: Config>(factor: u32) -> BalanceOf<T> {
let factor = BalanceOf::<T>::from(factor);
T::Currency::minimum_balance() * factor
}
/// Get the current number of candidates.
fn candidate_count<T: Trait>() -> u32 {
fn candidate_count<T: Config>() -> u32 {
<Candidates<T>>::decode_len().unwrap_or(0usize) as u32
}
/// Get the number of votes of a voter.
fn vote_count_of<T: Trait>(who: &T::AccountId) -> u32 {
fn vote_count_of<T: Config>(who: &T::AccountId) -> u32 {
<Voting<T>>::get(who).1.len() as u32
}
/// A `DefunctVoter` struct with correct value
fn defunct_for<T: Trait>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
fn defunct_for<T: Config>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
DefunctVoter {
who: as_lookup::<T>(who.clone()),
candidate_count: candidate_count::<T>(),
@@ -83,7 +83,7 @@ fn defunct_for<T: Trait>(who: T::AccountId) -> DefunctVoter<Lookup<T>> {
}
/// Add `c` new candidates.
fn submit_candidates<T: Trait>(c: u32, prefix: &'static str)
fn submit_candidates<T: Config>(c: u32, prefix: &'static str)
-> Result<Vec<T::AccountId>, &'static str>
{
(0..c).map(|i| {
@@ -97,7 +97,7 @@ fn submit_candidates<T: Trait>(c: u32, prefix: &'static str)
}
/// Add `c` new candidates with self vote.
fn submit_candidates_with_self_vote<T: Trait>(c: u32, prefix: &'static str)
fn submit_candidates_with_self_vote<T: Config>(c: u32, prefix: &'static str)
-> Result<Vec<T::AccountId>, &'static str>
{
let candidates = submit_candidates::<T>(c, prefix)?;
@@ -110,7 +110,7 @@ fn submit_candidates_with_self_vote<T: Trait>(c: u32, prefix: &'static str)
/// Submit one voter.
fn submit_voter<T: Trait>(caller: T::AccountId, votes: Vec<T::AccountId>, stake: BalanceOf<T>)
fn submit_voter<T: Config>(caller: T::AccountId, votes: Vec<T::AccountId>, stake: BalanceOf<T>)
-> Result<(), sp_runtime::DispatchError>
{
<Elections<T>>::vote(RawOrigin::Signed(caller).into(), votes, stake)
@@ -118,7 +118,7 @@ fn submit_voter<T: Trait>(caller: T::AccountId, votes: Vec<T::AccountId>, stake:
/// create `num_voter` voters who randomly vote for at most `votes` of `all_candidates` if
/// available.
fn distribute_voters<T: Trait>(mut all_candidates: Vec<T::AccountId>, num_voters: u32, votes: usize)
fn distribute_voters<T: Config>(mut all_candidates: Vec<T::AccountId>, num_voters: u32, votes: usize)
-> Result<(), &'static str>
{
let stake = default_stake::<T>(BALANCE_FACTOR);
@@ -138,7 +138,7 @@ fn distribute_voters<T: Trait>(mut all_candidates: Vec<T::AccountId>, num_voters
/// Fill the seats of members and runners-up up until `m`. Note that this might include either only
/// members, or members and runners-up.
fn fill_seats_up_to<T: Trait>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
let _ = submit_candidates_with_self_vote::<T>(m, "fill_seats_up_to")?;
assert_eq!(<Elections<T>>::candidates().len() as u32, m, "wrong number of candidates.");
<Elections<T>>::do_phragmen();
@@ -158,7 +158,7 @@ fn fill_seats_up_to<T: Trait>(m: u32) -> Result<Vec<T::AccountId>, &'static str>
}
/// removes all the storage items to reverse any genesis state.
fn clean<T: Trait>() {
fn clean<T: Config>() {
<Members<T>>::kill();
<Candidates<T>>::kill();
<RunnersUp<T>>::kill();
+15 -15
View File
@@ -77,7 +77,7 @@
//!
//! ### Module Information
//!
//! - [`election_sp_phragmen::Trait`](./trait.Trait.html)
//! - [`election_sp_phragmen::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
@@ -112,9 +112,9 @@ pub use weights::WeightInfo;
pub const MAXIMUM_VOTE: usize = 16;
type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
/// An indication that the renouncing account currently has which of the below roles.
#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug)]
@@ -140,9 +140,9 @@ pub struct DefunctVoter<AccountId> {
pub candidate_count: u32
}
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.c
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Identifier for the elections-phragmen pallet's lock
type ModuleId: Get<LockIdentifier>;
@@ -193,7 +193,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as PhragmenElection {
trait Store for Module<T: Config> as PhragmenElection {
// ---- State
/// The current elected membership. Sorted based on account id.
pub Members get(fn members): Vec<(T::AccountId, BalanceOf<T>)>;
@@ -251,7 +251,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Cannot vote when no candidates or members exist.
UnableToVote,
/// Must vote for at least one candidate.
@@ -290,7 +290,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -667,7 +667,7 @@ decl_module! {
decl_event!(
pub enum Event<T> where
Balance = BalanceOf<T>,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
{
/// A new term with \[new_members\]. This indicates that enough candidates existed to run the
/// election, not that enough have has been elected. The inner value must be examined for
@@ -694,7 +694,7 @@ decl_event!(
}
);
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Attempts to remove a member `who`. If a runner-up exists, it is used as the replacement and
/// Ok(true). is returned.
///
@@ -1027,7 +1027,7 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> Contains<T::AccountId> for Module<T> {
impl<T: Config> Contains<T::AccountId> for Module<T> {
fn contains(who: &T::AccountId) -> bool {
Self::is_member(who)
}
@@ -1046,7 +1046,7 @@ impl<T: Trait> Contains<T::AccountId> for Module<T> {
}
}
impl<T: Trait> ContainsLengthBound for Module<T> {
impl<T: Config> ContainsLengthBound for Module<T> {
fn min_len() -> usize { 0 }
/// Implementation uses a parameter type so calling is cost-free.
@@ -1076,7 +1076,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -1108,7 +1108,7 @@ mod tests {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type Balance = u64;
type Event = Event;
type DustRemoval = ();
@@ -1175,7 +1175,7 @@ mod tests {
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}
impl Trait for Test {
impl Config for Test {
type ModuleId = ElectionsPhragmenModuleId;
type Event = Event;
type Currency = Balances;
@@ -59,7 +59,7 @@ pub trait WeightInfo {
/// Weights for pallet_elections_phragmen using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn vote(v: u32, ) -> Weight {
(89_627_000 as Weight)
.saturating_add((197_000 as Weight).saturating_mul(v as Weight))
+9 -9
View File
@@ -139,9 +139,9 @@ pub const VOTER_SET_SIZE: usize = 64;
/// NUmber of approvals grouped in one chunk.
pub const APPROVAL_SET_SIZE: usize = 8;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
/// Index used to access chunks.
type SetIndex = u32;
@@ -152,8 +152,8 @@ type ApprovalFlag = u32;
/// Number of approval flags that can fit into [`ApprovalFlag`] type.
const APPROVAL_FLAG_LEN: usize = 32;
pub trait Trait: frame_system::Trait {
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
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>;
@@ -218,7 +218,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Elections {
trait Store for Module<T: Config> as Elections {
// ---- parameters
/// How long to give each top candidate to present themselves after the vote ends.
@@ -286,7 +286,7 @@ decl_storage! {
decl_error! {
/// Error for the elections module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Reporter must be a voter.
NotVoter,
/// Target for inactivity cleanup must be active.
@@ -345,7 +345,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// How much should be locked up in order to submit one's candidacy. A reasonable
@@ -706,7 +706,7 @@ decl_module! {
}
decl_event!(
pub enum Event<T> where <T as frame_system::Trait>::AccountId {
pub enum Event<T> where <T as frame_system::Config>::AccountId {
/// Reaped \[voter, reaper\].
VoterReaped(AccountId, AccountId),
/// Slashed \[reaper\].
@@ -719,7 +719,7 @@ decl_event!(
}
);
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
// exposed immutables.
/// True if we're currently in a presentation period.
+3 -3
View File
@@ -37,7 +37,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = Call;
@@ -68,7 +68,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
@@ -110,7 +110,7 @@ parameter_types!{
pub const ElectionModuleId: LockIdentifier = *b"py/elect";
}
impl elections::Trait for Test {
impl elections::Config for Test {
type Event = Event;
type Currency = Balances;
type BadPresentation = ();
+2 -2
View File
@@ -680,8 +680,8 @@ fn retracting_active_voter_should_slash_reporter() {
assert_ok!(Elections::end_block(System::block_number()));
assert_eq!(Elections::vote_index(), 2);
assert_eq!(<Test as Trait>::InactiveGracePeriod::get(), 1);
assert_eq!(<Test as Trait>::VotingPeriod::get(), 4);
assert_eq!(<Test as Config>::InactiveGracePeriod::get(), 1);
assert_eq!(<Test as Config>::VotingPeriod::get(), 4);
assert_eq!(Elections::voter_info(4), Some(VoterInfo { last_win: 1, last_active: 0, stake: 40, pot: 0 }));
assert_ok!(Elections::reap_inactive_voter(Origin::signed(4),
@@ -24,7 +24,7 @@
//! Run `cargo doc --package pallet-example-offchain-worker --open` to view this module's
//! documentation.
//!
//! - [`pallet_example_offchain_worker::Trait`](./trait.Trait.html)
//! - [`pallet_example_offchain_worker::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -103,12 +103,12 @@ pub mod crypto {
}
/// This pallet's configuration trait
pub trait Trait: CreateSignedTransaction<Call<Self>> {
pub trait Config: CreateSignedTransaction<Call<Self>> {
/// The identifier type for an offchain worker.
type AuthorityId: AppCrypto<Self::Public, Self::Signature>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The overarching dispatch call type.
type Call: From<Call<Self>>;
@@ -149,7 +149,7 @@ impl<T: SigningTypes> SignedPayload<T> for PricePayload<T::Public, T::BlockNumbe
}
decl_storage! {
trait Store for Module<T: Trait> as ExampleOffchainWorker {
trait Store for Module<T: Config> as ExampleOffchainWorker {
/// A vector of recently submitted prices.
///
/// This is used to calculate average price, should have bounded size.
@@ -165,7 +165,7 @@ decl_storage! {
decl_event!(
/// Events generated by the module.
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId {
/// Event generated when new price is accepted to contribute to the average.
/// \[price, who\]
NewPrice(u32, AccountId),
@@ -174,7 +174,7 @@ decl_event!(
decl_module! {
/// A public part of the pallet.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn deposit_event() = default;
/// Submit new price to the list.
@@ -310,7 +310,7 @@ enum TransactionType {
///
/// This greatly helps with error messages, as the ones inside the macro
/// can sometimes be hard to debug.
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Chooses which transaction type to send.
///
/// This function serves mostly to showcase `StorageValue` helper
@@ -679,7 +679,7 @@ impl<T: Trait> Module<T> {
}
#[allow(deprecated)] // ValidateUnsigned
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
/// Validate unsigned call to this module.
@@ -56,7 +56,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
@@ -118,7 +118,7 @@ parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type AuthorityId = crypto::TestAuthId;
type Call = Call<Test>;
@@ -282,7 +282,7 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() {
let signature_valid = <PricePayload<
<Test as SigningTypes>::Public,
<Test as frame_system::Trait>::BlockNumber
<Test as frame_system::Config>::BlockNumber
> as SignedPayload<Test>>::verify::<crypto::TestAuthId>(&price_payload, signature);
assert!(signature_valid);
@@ -335,7 +335,7 @@ fn should_submit_unsigned_transaction_on_chain_for_all_accounts() {
let signature_valid = <PricePayload<
<Test as SigningTypes>::Public,
<Test as frame_system::Trait>::BlockNumber
<Test as frame_system::Config>::BlockNumber
> as SignedPayload<Test>>::verify::<crypto::TestAuthId>(&price_payload, signature);
assert!(signature_valid);
+4 -4
View File
@@ -34,15 +34,15 @@ use sp_std::vec::Vec;
#[cfg(test)]
mod tests;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// The overarching dispatch call type.
type Call: From<Call<Self>>;
}
decl_storage! {
trait Store for Module<T: Trait> as ExampleOffchainWorker {
trait Store for Module<T: Config> as ExampleOffchainWorker {
/// A vector of current participants
///
/// To enlist someone to participate, signed payload should be
@@ -87,7 +87,7 @@ impl EnlistedParticipant {
decl_module! {
/// A public part of the pallet.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn deposit_event() = default;
/// Get the new event running.
@@ -39,7 +39,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
@@ -73,7 +73,7 @@ parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type Call = Call<Test>;
}
+23 -23
View File
@@ -63,7 +63,7 @@
//! // Include the following links that shows what trait needs to be implemented to use the pallet
//! // and the supported dispatchables that are documented in the Call enum.
//!
//! - \[`<INSERT_CUSTOM_PALLET_NAME>::Trait`](./trait.Trait.html)
//! - \[`<INSERT_CUSTOM_PALLET_NAME>::Config`](./trait.Config.html)
//! - \[`Call`](./enum.Call.html)
//! - \[`Module`](./struct.Module.html)
//!
@@ -212,7 +212,7 @@
//! \```rust
//! use <INSERT_CUSTOM_PALLET_NAME>;
//!
//! pub trait Trait: <INSERT_CUSTOM_PALLET_NAME>::Trait { }
//! pub trait Config: <INSERT_CUSTOM_PALLET_NAME>::Config { }
//! \```
//!
//! \### Simple Code Snippet
@@ -286,9 +286,9 @@ use sp_runtime::{
// - The final weight of each dispatch is calculated as the argument of the call multiplied by the
// parameter given to the `WeightForSetDummy`'s constructor.
// - assigns a dispatch class `operational` if the argument of the call is more than 1000.
struct WeightForSetDummy<T: pallet_balances::Trait>(BalanceOf<T>);
struct WeightForSetDummy<T: pallet_balances::Config>(BalanceOf<T>);
impl<T: pallet_balances::Trait> WeighData<(&BalanceOf<T>,)> for WeightForSetDummy<T>
impl<T: pallet_balances::Config> WeighData<(&BalanceOf<T>,)> for WeightForSetDummy<T>
{
fn weigh_data(&self, target: (&BalanceOf<T>,)) -> Weight {
let multiplier = self.0;
@@ -296,7 +296,7 @@ impl<T: pallet_balances::Trait> WeighData<(&BalanceOf<T>,)> for WeightForSetDumm
}
}
impl<T: pallet_balances::Trait> ClassifyDispatch<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
impl<T: pallet_balances::Config> ClassifyDispatch<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
fn classify_dispatch(&self, target: (&BalanceOf<T>,)) -> DispatchClass {
if *target.0 > <BalanceOf<T>>::from(1000u32) {
DispatchClass::Operational
@@ -306,23 +306,23 @@ impl<T: pallet_balances::Trait> ClassifyDispatch<(&BalanceOf<T>,)> for WeightFor
}
}
impl<T: pallet_balances::Trait> PaysFee<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
impl<T: pallet_balances::Config> PaysFee<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
fn pays_fee(&self, _target: (&BalanceOf<T>,)) -> Pays {
Pays::Yes
}
}
/// A type alias for the balance type from this pallet's point of view.
type BalanceOf<T> = <T as pallet_balances::Trait>::Balance;
type BalanceOf<T> = <T as pallet_balances::Config>::Balance;
/// Our pallet's configuration trait. All our types and constants go in here. If the
/// pallet is dependent on specific other pallets, then their configuration traits
/// should be added to our implied traits list.
///
/// `frame_system::Trait` should always be included in our implied traits.
pub trait Trait: pallet_balances::Trait {
/// `frame_system::Config` should always be included in our implied traits.
pub trait Config: pallet_balances::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}
decl_storage! {
@@ -333,7 +333,7 @@ decl_storage! {
// It is important to update your storage name so that your pallet's
// storage items are isolated from other pallets.
// ---------------------------------vvvvvvv
trait Store for Module<T: Trait> as Example {
trait Store for Module<T: Config> as Example {
// Any storage declarations of the form:
// `pub? Name get(fn getter_name)? [config()|config(myname)] [build(|_| {...})] : <type> (= <new_default_value>)?;`
// where `<type>` is either:
@@ -371,7 +371,7 @@ decl_event!(
/// Events are a simple means of reporting specific conditions and
/// circumstances that have happened that users, Dapps and/or chain explorers would find
/// interesting and otherwise difficult to detect.
pub enum Event<T> where B = <T as pallet_balances::Trait>::Balance {
pub enum Event<T> where B = <T as pallet_balances::Config>::Balance {
// Just a normal `enum`, here's a dummy event to ensure it compiles.
/// Dummy event, just here so there's a generic type that's used.
Dummy(B),
@@ -414,7 +414,7 @@ decl_event!(
// `ensure_root` and `ensure_none`.
decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// Deposit one of this pallet's events by using the default implementation.
/// It is also possible to provide a custom implementation.
/// For non-generic events, the generic parameter just needs to be dropped, so that it
@@ -548,7 +548,7 @@ decl_module! {
// - Public interface. These are functions that are `pub` and generally fall into inspector
// functions that do not write to storage and operation functions that do.
// - Private functions. These are your usual private utilities unavailable to other pallets.
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
// Add public immutables and private mutables.
#[allow(dead_code)]
fn accumulate_foo(origin: T::Origin, increase_by: T::Balance) -> DispatchResult {
@@ -571,7 +571,7 @@ impl<T: Trait> Module<T> {
// decodable type that implements `SignedExtension`. See the trait definition for the full list of
// bounds. As a convention, you can follow this approach to create an extension for your pallet:
// - If the extension does not carry any data, then use a tuple struct with just a `marker`
// (needed for the compiler to accept `T: Trait`) will suffice.
// (needed for the compiler to accept `T: Config`) will suffice.
// - Otherwise, create a tuple struct which contains the external data. Of course, for the entire
// struct to be decodable, each individual item also needs to be decodable.
//
@@ -602,21 +602,21 @@ impl<T: Trait> Module<T> {
/// Additionally, it drops any transaction with an encoded length higher than 200 bytes. No
/// particular reason why, just to demonstrate the power of signed extensions.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
pub struct WatchDummy<T: Trait + Send + Sync>(PhantomData<T>);
pub struct WatchDummy<T: Config + Send + Sync>(PhantomData<T>);
impl<T: Trait + Send + Sync> sp_std::fmt::Debug for WatchDummy<T> {
impl<T: Config + Send + Sync> sp_std::fmt::Debug for WatchDummy<T> {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
write!(f, "WatchDummy")
}
}
impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T>
impl<T: Config + Send + Sync> SignedExtension for WatchDummy<T>
where
<T as frame_system::Trait>::Call: IsSubType<Call<T>>,
<T as frame_system::Config>::Call: IsSubType<Call<T>>,
{
const IDENTIFIER: &'static str = "WatchDummy";
type AccountId = T::AccountId;
type Call = <T as frame_system::Trait>::Call;
type Call = <T as frame_system::Config>::Call;
type AdditionalSigned = ();
type Pre = ();
@@ -744,7 +744,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -774,7 +774,7 @@ mod tests {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
@@ -783,7 +783,7 @@ mod tests {
type AccountStore = System;
type WeightInfo = ();
}
impl Trait for Test {
impl Config for Test {
type Event = ();
}
type System = frame_system::Module<Test>;
+20 -20
View File
@@ -145,7 +145,7 @@ pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
/// Main entry point for certain runtime actions as e.g. `execute_block`.
///
/// Generic parameters:
/// - `System`: Something that implements `frame_system::Trait`
/// - `System`: Something that implements `frame_system::Config`
/// - `Block`: The block type of the runtime
/// - `Context`: The context that is used when checking an extrinsic.
/// - `UnsignedValidator`: The unsigned transaction validator of the runtime.
@@ -158,7 +158,7 @@ pub struct Executive<System, Block, Context, UnsignedValidator, AllModules, OnRu
);
impl<
System: frame_system::Trait,
System: frame_system::Config,
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
UnsignedValidator,
@@ -185,7 +185,7 @@ where
}
impl<
System: frame_system::Trait,
System: frame_system::Config,
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
UnsignedValidator,
@@ -505,10 +505,10 @@ mod tests {
UnknownTransaction, TransactionSource, TransactionValidity
};
pub trait Trait: frame_system::Trait {}
pub trait Config: frame_system::Config {}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
#[weight = 100]
fn some_function(origin) {
// NOTE: does not make any different.
@@ -555,7 +555,7 @@ mod tests {
}
}
impl<T: Trait> sp_runtime::traits::ValidateUnsigned for Module<T> {
impl<T: Config> sp_runtime::traits::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(
@@ -594,7 +594,7 @@ mod tests {
write: 100,
};
}
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -626,7 +626,7 @@ mod tests {
parameter_types! {
pub const ExistentialDeposit: Balance = 1;
}
impl pallet_balances::Trait for Runtime {
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type Event = Event;
type DustRemoval = ();
@@ -639,13 +639,13 @@ mod tests {
parameter_types! {
pub const TransactionByteFee: Balance = 0;
}
impl pallet_transaction_payment::Trait for Runtime {
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
}
impl custom::Trait for Runtime {}
impl custom::Config for Runtime {}
pub struct RuntimeVersion;
impl frame_support::traits::Get<sp_version::RuntimeVersion> for RuntimeVersion {
@@ -668,8 +668,8 @@ mod tests {
type TestXt = sp_runtime::testing::TestXt<Call, SignedExtra>;
type TestBlock = Block<TestXt>;
type TestUncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<
<Runtime as frame_system::Trait>::AccountId,
<Runtime as frame_system::Trait>::Call,
<Runtime as frame_system::Config>::AccountId,
<Runtime as frame_system::Config>::Call,
(),
SignedExtra,
>;
@@ -715,9 +715,9 @@ mod tests {
balances: vec![(1, 211)],
}.assimilate_storage(&mut t).unwrap();
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(2, 69)), sign_extra(1, 0, 0));
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get();
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
let fee: Balance
= <Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight);
= <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
let mut t = sp_io::TestExternalities::new(t);
t.execute_with(|| {
Executive::initialize_block(&Header::new(
@@ -818,7 +818,7 @@ mod tests {
let encoded = xt.encode();
let encoded_len = encoded.len() as Weight;
// on_initialize weight + block execution weight
let base_block_weight = 175 + <Runtime as frame_system::Trait>::BlockExecutionWeight::get();
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockExecutionWeight::get();
let limit = AvailableBlockRatio::get() * MaximumBlockWeight::get() - base_block_weight;
let num_to_exhaust_block = limit / (encoded_len + 5);
t.execute_with(|| {
@@ -861,7 +861,7 @@ mod tests {
let mut t = new_test_ext(1);
t.execute_with(|| {
// Block execution weight + on_initialize weight from custom module
let base_block_weight = 175 + <Runtime as frame_system::Trait>::BlockExecutionWeight::get();
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockExecutionWeight::get();
Executive::initialize_block(&Header::new(
1,
@@ -879,7 +879,7 @@ mod tests {
assert!(Executive::apply_extrinsic(x2.clone()).unwrap().is_ok());
// default weight for `TestXt` == encoded length.
let extrinsic_weight = len as Weight + <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get();
let extrinsic_weight = len as Weight + <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
assert_eq!(
<frame_system::Module<Runtime>>::block_weight().total(),
base_block_weight + 3 * extrinsic_weight,
@@ -946,9 +946,9 @@ mod tests {
sign_extra(1, 0, 0),
);
let weight = xt.get_dispatch_info().weight
+ <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get();
+ <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
let fee: Balance =
<Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight);
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
Executive::initialize_block(&Header::new(
1,
H256::default(),
@@ -1106,7 +1106,7 @@ mod tests {
let runtime_upgrade_weight = <AllModules as OnRuntimeUpgrade>::on_runtime_upgrade();
let frame_system_on_initialize_weight = frame_system::Module::<Runtime>::on_initialize(block_number);
let on_initialize_weight = <AllModules as OnInitialize<u64>>::on_initialize(block_number);
let base_block_weight = <Runtime as frame_system::Trait>::BlockExecutionWeight::get();
let base_block_weight = <Runtime as frame_system::Config>::BlockExecutionWeight::get();
// Weights are recorded correctly
assert_eq!(
+5 -5
View File
@@ -54,13 +54,13 @@ use sp_staking::{
SessionIndex,
};
use super::{Call, Module, Trait};
use super::{Call, Module, Config};
/// A trait with utility methods for handling equivocation reports in GRANDPA.
/// The offence type is generic, and the trait provides , reporting an offence
/// triggered by a valid equivocation report, and also for creating and
/// submitting equivocation report extrinsics (useful only in offchain context).
pub trait HandleEquivocation<T: Trait> {
pub trait HandleEquivocation<T: Config> {
/// The offence type used for reporting offences on valid equivocation reports.
type Offence: GrandpaOffence<T::KeyOwnerIdentification>;
@@ -86,7 +86,7 @@ pub trait HandleEquivocation<T: Trait> {
fn block_author() -> Option<T::AccountId>;
}
impl<T: Trait> HandleEquivocation<T> for () {
impl<T: Config> HandleEquivocation<T> for () {
type Offence = GrandpaEquivocationOffence<T::KeyOwnerIdentification>;
fn report_offence(
@@ -136,7 +136,7 @@ where
// We use the authorship pallet to fetch the current block author and use
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
// submission.
T: Trait + pallet_authorship::Trait + frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
// A system for reporting offences after valid equivocation reports are
// processed.
R: ReportOffence<T::AccountId, T::KeyOwnerIdentification, O>,
@@ -187,7 +187,7 @@ pub struct GrandpaTimeSlot {
/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned`
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This
/// guarantees that only block authors can include unsigned equivocation reports.
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, _) = call {
+9 -9
View File
@@ -67,9 +67,9 @@ pub use equivocation::{
HandleEquivocation,
};
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The event type of this module.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// The function call.
type Call: From<Call<Self>>;
@@ -188,7 +188,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Attempt to signal GRANDPA pause when the authority set isn't live
/// (either paused or already pending pause).
PauseFailed,
@@ -209,7 +209,7 @@ decl_error! {
}
decl_storage! {
trait Store for Module<T: Trait> as GrandpaFinality {
trait Store for Module<T: Config> as GrandpaFinality {
/// State of the current authority set.
State get(fn state): StoredState<T::BlockNumber> = StoredState::Live;
@@ -241,7 +241,7 @@ decl_storage! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -372,7 +372,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Get the current set of authorities, along with their respective weights.
pub fn grandpa_authorities() -> AuthorityList {
storage::unhashed::get_or_default::<VersionedAuthorityList>(GRANDPA_AUTHORITIES_KEY).into()
@@ -583,12 +583,12 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T>
where T: pallet_session::Trait
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T>
where T: pallet_session::Config
{
type Key = AuthorityId;
+10 -10
View File
@@ -19,7 +19,7 @@
#![cfg(test)]
use crate::{AuthorityId, AuthorityList, ConsensusLog, Module, Trait};
use crate::{AuthorityId, AuthorityList, ConsensusLog, Module, Config};
use ::grandpa as finality_grandpa;
use codec::Encode;
use frame_support::{
@@ -79,7 +79,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -122,7 +122,7 @@ parameter_types! {
}
/// Custom `SessionHandler` since we use `TestSessionKeys` as `Keys`.
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type Event = TestEvent;
type ValidatorId = u64;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
@@ -135,7 +135,7 @@ impl pallet_session::Trait for Test {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = pallet_staking::Exposure<u64, u128>;
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
}
@@ -144,7 +144,7 @@ parameter_types! {
pub const UncleGenerations: u64 = 0;
}
impl pallet_authorship::Trait for Test {
impl pallet_authorship::Config for Test {
type FindAuthor = ();
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -155,7 +155,7 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
@@ -169,7 +169,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 3;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -198,7 +198,7 @@ parameter_types! {
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
}
impl pallet_staking::Trait for Test {
impl pallet_staking::Config for Test {
type RewardRemainder = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = TestEvent;
@@ -227,14 +227,14 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl pallet_offences::Trait for Test {
impl pallet_offences::Config for Test {
type Event = TestEvent;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
+2 -2
View File
@@ -850,7 +850,7 @@ fn report_equivocation_has_valid_weight() {
// but there's a lower bound of 100 validators.
assert!(
(1..=100)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] == w[1])
@@ -860,7 +860,7 @@ fn report_equivocation_has_valid_weight() {
// with every extra validator.
assert!(
(100..=1000)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] < w[1])
+12 -12
View File
@@ -29,16 +29,16 @@ use crate::Module as Identity;
const SEED: u32 = 0;
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}
// Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields.
fn add_registrars<T: Trait>(r: u32) -> Result<(), &'static str> {
fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
let _ = T::Currency::make_free_balance_be(&registrar, BalanceOf::<T>::max_value());
@@ -57,7 +57,7 @@ fn add_registrars<T: Trait>(r: u32) -> Result<(), &'static str> {
// Create `s` sub-accounts for the identity of `who` and return them.
// Each will have 32 bytes of raw data added to it.
fn create_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
fn create_sub_accounts<T: Config>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
let mut subs = Vec::new();
let who_origin = RawOrigin::Signed(who.clone());
let data = Data::Raw(vec![0; 32]);
@@ -77,7 +77,7 @@ fn create_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::A
// Adds `s` sub-accounts to the identity of `who`. Each will have 32 bytes of raw data added to it.
// This additionally returns the vector of sub-accounts so it can be modified if needed.
fn add_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
fn add_sub_accounts<T: Config>(who: &T::AccountId, s: u32) -> Result<Vec<(T::AccountId, Data)>, &'static str> {
let who_origin = RawOrigin::Signed(who.clone());
let subs = create_sub_accounts::<T>(who, s)?;
@@ -88,7 +88,7 @@ fn add_sub_accounts<T: Trait>(who: &T::AccountId, s: u32) -> Result<Vec<(T::Acco
// This creates an `IdentityInfo` object with `num_fields` extra fields.
// All data is pre-populated with some arbitrary bytes.
fn create_identity_info<T: Trait>(num_fields: u32) -> IdentityInfo {
fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo {
let data = Data::Raw(vec![0; 32]);
let info = IdentityInfo {
@@ -121,7 +121,7 @@ benchmarks! {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};
}
@@ -143,7 +143,7 @@ benchmarks! {
// The target user
let caller: T::AccountId = whitelisted_caller();
let caller_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(caller.clone());
let caller_origin: <T as frame_system::Trait>::Origin = RawOrigin::Signed(caller.clone()).into();
let caller_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(caller.clone()).into();
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Add an initial identity
@@ -200,7 +200,7 @@ benchmarks! {
clear_identity {
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
@@ -237,7 +237,7 @@ benchmarks! {
cancel_request {
let caller: T::AccountId = whitelisted_caller();
let caller_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(caller.clone()));
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let r in ...;
@@ -300,7 +300,7 @@ benchmarks! {
provide_judgement {
// The user
let user: T::AccountId = account("user", r, SEED);
let user_origin = <T as frame_system::Trait>::Origin::from(RawOrigin::Signed(user.clone()));
let user_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(user.clone()));
let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
@@ -328,7 +328,7 @@ benchmarks! {
let x in _ .. _ => {};
let target: T::AccountId = account("target", 0, SEED);
let target_origin: <T as frame_system::Trait>::Origin = RawOrigin::Signed(target.clone()).into();
let target_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(target.clone()).into();
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
+11 -11
View File
@@ -17,7 +17,7 @@
//! # Identity Module
//!
//! - [`identity::Trait`](./trait.Trait.html)
//! - [`identity::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -68,7 +68,7 @@
//! * `kill_identity` - Forcibly remove the associated identity; the deposit is lost.
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
#![cfg_attr(not(feature = "std"), no_std)]
@@ -91,12 +91,12 @@ use frame_support::{
use frame_system::ensure_signed;
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The currency trait.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -399,7 +399,7 @@ pub struct RegistrarInfo<
}
decl_storage! {
trait Store for Module<T: Trait> as Identity {
trait Store for Module<T: Config> as Identity {
/// Information that is pertinent to identify the entity behind an account.
///
/// TWOX-NOTE: OK ― `AccountId` is a secure hash.
@@ -428,7 +428,7 @@ decl_storage! {
}
decl_event!(
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId, Balance = BalanceOf<T> {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId, Balance = BalanceOf<T> {
/// A name was set or reset (which will remove all judgements). \[who\]
IdentitySet(AccountId),
/// A name was cleared, and the given balance returned. \[who, deposit\]
@@ -456,7 +456,7 @@ decl_event!(
decl_error! {
/// Error for the identity module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Too many subs-accounts.
TooManySubAccounts,
/// Account isn't found.
@@ -494,7 +494,7 @@ decl_error! {
decl_module! {
/// Identity module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// The amount held on deposit for a registered identity.
const BasicDeposit: BalanceOf<T> = T::BasicDeposit::get();
@@ -1125,7 +1125,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Get the subs of an account.
pub fn subs(who: &T::AccountId) -> Vec<(T::AccountId, Data)> {
SubsOf::<T>::get(who).1
+3 -3
View File
@@ -42,7 +42,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -72,7 +72,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type Balance = u64;
type Event = ();
type DustRemoval = ();
@@ -103,7 +103,7 @@ type EnsureTwoOrRoot = EnsureOneOf<
EnsureRoot<u64>,
EnsureSignedBy<Two, u64>
>;
impl Trait for Test {
impl Config for Test {
type Event = ();
type Currency = Balances;
type Slashed = ();
+1 -1
View File
@@ -64,7 +64,7 @@ pub trait WeightInfo {
/// Weights for pallet_identity using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn add_registrar(r: u32, ) -> Weight {
(28_965_000 as Weight)
.saturating_add((421_000 as Weight).saturating_mul(r as Weight))
@@ -34,7 +34,7 @@ use crate::Module as ImOnline;
const MAX_KEYS: u32 = 1000;
const MAX_EXTERNAL_ADDRESSES: u32 = 100;
pub fn create_heartbeat<T: Trait>(k: u32, e: u32) ->
pub fn create_heartbeat<T: Config>(k: u32, e: u32) ->
Result<(crate::Heartbeat<T::BlockNumber>, <T::AuthorityId as RuntimeAppPublic>::Signature), &'static str>
{
let mut keys = Vec::new();
+16 -16
View File
@@ -30,7 +30,7 @@
//! as the [NetworkState](../../client/offchain/struct.NetworkState.html).
//! It is submitted as an Unsigned Transaction via off-chain workers.
//!
//! - [`im_online::Trait`](./trait.Trait.html)
//! - [`im_online::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -47,10 +47,10 @@
//! use frame_system::ensure_signed;
//! use pallet_im_online::{self as im_online};
//!
//! pub trait Trait: im_online::Trait {}
//! pub trait Config: im_online::Config {}
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! #[weight = 0]
//! pub fn is_online(origin, authority_index: u32) -> dispatch::DispatchResult {
//! let _sender = ensure_signed(origin)?;
@@ -227,12 +227,12 @@ pub struct Heartbeat<BlockNumber>
pub validators_len: u32,
}
pub trait Trait: SendTransactionTypes<Call<Self>> + pallet_session::historical::Trait {
pub trait Config: SendTransactionTypes<Call<Self>> + pallet_session::historical::Config {
/// The identifier type for an authority.
type AuthorityId: Member + Parameter + RuntimeAppPublic + Default + Ord;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// An expected duration of the session.
///
@@ -262,7 +262,7 @@ pub trait Trait: SendTransactionTypes<Call<Self>> + pallet_session::historical::
decl_event!(
pub enum Event<T> where
<T as Trait>::AuthorityId,
<T as Config>::AuthorityId,
IdentificationTuple = IdentificationTuple<T>,
{
/// A new heartbeat was received from `AuthorityId` \[authority_id\]
@@ -275,7 +275,7 @@ decl_event!(
);
decl_storage! {
trait Store for Module<T: Trait> as ImOnline {
trait Store for Module<T: Config> as ImOnline {
/// The block number after which it's ok to send heartbeats in current session.
///
/// At the beginning of each session we set this to a value that should
@@ -307,7 +307,7 @@ decl_storage! {
decl_error! {
/// Error for the im-online module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Non existent public key.
InvalidKey,
/// Duplicated heartbeat.
@@ -316,7 +316,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -332,7 +332,7 @@ decl_module! {
/// # </weight>
// NOTE: the weight includes the cost of validate_unsigned as it is part of the cost to
// import block with such an extrinsic.
#[weight = <T as Trait>::WeightInfo::validate_unsigned_and_then_heartbeat(
#[weight = <T as Config>::WeightInfo::validate_unsigned_and_then_heartbeat(
heartbeat.validators_len as u32,
heartbeat.network_state.external_addresses.len() as u32,
)]
@@ -393,11 +393,11 @@ decl_module! {
}
}
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Trait>::BlockNumber>>;
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Config>::BlockNumber>>;
/// Keep track of number of authored blocks per authority, uncles are counted as
/// well since they're a valid proof of being online.
impl<T: Trait + pallet_authorship::Trait> pallet_authorship::EventHandler<T::ValidatorId, T::BlockNumber> for Module<T> {
impl<T: Config + pallet_authorship::Config> pallet_authorship::EventHandler<T::ValidatorId, T::BlockNumber> for Module<T> {
fn note_author(author: T::ValidatorId) {
Self::note_authorship(author);
}
@@ -407,7 +407,7 @@ impl<T: Trait + pallet_authorship::Trait> pallet_authorship::EventHandler<T::Val
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Returns `true` if a heartbeat has been received for the authority at
/// `authority_index` in the authorities series or if the authority has
/// authored at least one block, during the current session. Otherwise
@@ -610,11 +610,11 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = T::AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = T::AuthorityId;
fn on_genesis_session<'a, I: 'a>(validators: I)
@@ -677,7 +677,7 @@ impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
/// Invalid transaction custom error. Returned when validators_len field in heartbeat is incorrect.
const INVALID_VALIDATORS_LEN: u8 = 10;
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(
+6 -6
View File
@@ -21,7 +21,7 @@
use std::cell::RefCell;
use crate::{Module, Trait};
use crate::{Module, Config};
use sp_runtime::Perbill;
use sp_staking::{SessionIndex, offence::{ReportOffence, OffenceError}};
use sp_runtime::testing::{Header, UintAuthorityId, TestXt};
@@ -109,7 +109,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -146,7 +146,7 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}
impl pallet_session::Trait for Runtime {
impl pallet_session::Config for Runtime {
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Runtime, TestSessionManager>;
type SessionHandler = (ImOnline, );
@@ -159,7 +159,7 @@ impl pallet_session::Trait for Runtime {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Runtime {
impl pallet_session::historical::Config for Runtime {
type FullIdentification = u64;
type FullIdentificationOf = ConvertInto;
}
@@ -168,7 +168,7 @@ parameter_types! {
pub const UncleGenerations: u32 = 5;
}
impl pallet_authorship::Trait for Runtime {
impl pallet_authorship::Config for Runtime {
type FindAuthor = ();
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -179,7 +179,7 @@ parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}
impl Trait for Runtime {
impl Config for Runtime {
type AuthorityId = UintAuthorityId;
type Event = ();
type ReportUnresponsiveness = OffenceHandler;
+1 -1
View File
@@ -49,7 +49,7 @@ pub trait WeightInfo {
/// Weights for pallet_im_online using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn validate_unsigned_and_then_heartbeat(k: u32, e: u32, ) -> Weight {
(114_379_000 as Weight)
.saturating_add((219_000 as Weight).saturating_mul(k as Weight))
+10 -10
View File
@@ -37,10 +37,10 @@ use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Re
use frame_system::{ensure_signed, ensure_root};
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// The module's config trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// Type used for storing an account's index; implies the maximum number of accounts the system
/// can hold.
type AccountIndex: Parameter + Member + Codec + Default + AtLeast32Bit + Copy;
@@ -52,14 +52,14 @@ pub trait Trait: frame_system::Trait {
type Deposit: Get<BalanceOf<Self>>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
decl_storage! {
trait Store for Module<T: Trait> as Indices {
trait Store for Module<T: Config> as Indices {
/// The lookup from index to account.
pub Accounts build(|config: &GenesisConfig<T>|
config.indices.iter()
@@ -75,8 +75,8 @@ decl_storage! {
decl_event!(
pub enum Event<T> where
<T as frame_system::Trait>::AccountId,
<T as Trait>::AccountIndex
<T as frame_system::Config>::AccountId,
<T as Config>::AccountIndex
{
/// A account index was assigned. \[index, who\]
IndexAssigned(AccountId, AccountIndex),
@@ -88,7 +88,7 @@ decl_event!(
);
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// The index was not already assigned.
NotAssigned,
/// The index is assigned to another account.
@@ -103,7 +103,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> 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 {
/// The deposit needed for reserving an index.
const Deposit: BalanceOf<T> = T::Deposit::get();
@@ -275,7 +275,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
// PUBLIC IMMUTABLES
/// Lookup an T::AccountIndex to get an Id, if there's one there.
@@ -295,7 +295,7 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> StaticLookup for Module<T> {
impl<T: Config> StaticLookup for Module<T> {
type Source = MultiAddress<T::AccountId, T::AccountIndex>;
type Target = T::AccountId;
+4 -4
View File
@@ -23,7 +23,7 @@ use sp_runtime::testing::Header;
use sp_runtime::Perbill;
use sp_core::H256;
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types, weights::Weight};
use crate::{self as indices, Module, Trait};
use crate::{self as indices, Module, Config};
use frame_system as system;
use pallet_balances as balances;
@@ -49,7 +49,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
@@ -81,7 +81,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
@@ -95,7 +95,7 @@ parameter_types! {
pub const Deposit: u64 = 1;
}
impl Trait for Test {
impl Config for Test {
type AccountIndex = u64;
type Currency = Balances;
type Deposit = Deposit;
+1 -1
View File
@@ -53,7 +53,7 @@ pub trait WeightInfo {
/// Weights for pallet_indices using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn claim() -> Weight {
(53_799_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
+11 -11
View File
@@ -30,9 +30,9 @@ use frame_support::{
};
use frame_system::ensure_signed;
pub trait Trait<I=DefaultInstance>: frame_system::Trait {
pub trait Config<I=DefaultInstance>: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
/// Required origin for adding a member (though can always be Root).
type AddOrigin: EnsureOrigin<Self::Origin>;
@@ -59,7 +59,7 @@ pub trait Trait<I=DefaultInstance>: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Membership {
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Membership {
/// The current membership, stored as an ordered Vec.
Members get(fn members): Vec<T::AccountId>;
@@ -80,8 +80,8 @@ decl_storage! {
decl_event!(
pub enum Event<T, I=DefaultInstance> where
<T as frame_system::Trait>::AccountId,
<T as Trait<I>>::Event,
<T as frame_system::Config>::AccountId,
<T as Config<I>>::Event,
{
/// The given member was added; see the transaction for who.
MemberAdded,
@@ -100,7 +100,7 @@ decl_event!(
decl_error! {
/// Error for the nicks module.
pub enum Error for Module<T: Trait<I>, I: Instance> {
pub enum Error for Module<T: Config<I>, I: Instance> {
/// Already a member.
AlreadyMember,
/// Not a member.
@@ -109,7 +109,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance>
pub struct Module<T: Config<I>, I: Instance=DefaultInstance>
for enum Call
where origin: T::Origin
{
@@ -253,7 +253,7 @@ decl_module! {
}
}
impl<T: Trait<I>, I: Instance> Module<T, I> {
impl<T: Config<I>, I: Instance> Module<T, I> {
fn rejig_prime(members: &[T::AccountId]) {
if let Some(prime) = Prime::<T, I>::get() {
match members.binary_search(&prime) {
@@ -264,7 +264,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
}
}
impl<T: Trait<I>, I: Instance> Contains<T::AccountId> for Module<T, I> {
impl<T: Config<I>, I: Instance> Contains<T::AccountId> for Module<T, I> {
fn sorted_members() -> Vec<T::AccountId> {
Self::members()
}
@@ -300,7 +300,7 @@ mod tests {
pub static Members: Vec<u64> = vec![];
pub static Prime: Option<u64> = None;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -359,7 +359,7 @@ mod tests {
}
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type AddOrigin = EnsureSignedBy<One, u64>;
type RemoveOrigin = EnsureSignedBy<Two, u64>;
+3 -3
View File
@@ -29,7 +29,7 @@ use crate::Module as Multisig;
const SEED: u32 = 0;
fn setup_multi<T: Trait>(s: u32, z: u32)
fn setup_multi<T: Config>(s: u32, z: u32)
-> Result<(Vec<T::AccountId>, Vec<u8>), &'static str>
{
let mut signatories: Vec<T::AccountId> = Vec::new();
@@ -42,7 +42,7 @@ fn setup_multi<T: Trait>(s: u32, z: u32)
}
signatories.sort();
// Must first convert to outer call type.
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![0; z as usize]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![0; z as usize]).into();
let call_data = call.encode();
return Ok((signatories, call_data))
}
@@ -55,7 +55,7 @@ benchmarks! {
let z in 0 .. 10_000;
let max_signatories = T::MaxSignatories::get().into();
let (mut signatories, _) = setup_multi::<T>(max_signatories, z)?;
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![0; z as usize]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![0; z as usize]).into();
let call_hash = call.using_encoded(blake2_256);
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, 1);
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
+13 -13
View File
@@ -18,7 +18,7 @@
//! # Multisig Module
//! A module for doing multisig dispatch.
//!
//! - [`multisig::Trait`](./trait.Trait.html)
//! - [`multisig::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -41,7 +41,7 @@
//! * `cancel_as_multi` - Cancel a call from a composite origin.
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -62,14 +62,14 @@ use frame_system::{self as system, ensure_signed, RawOrigin};
use sp_runtime::{DispatchError, DispatchResult, traits::{Dispatchable, Zero}};
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// Just a bunch of bytes, but they should decode to a valid `Call`.
pub type OpaqueCall = Vec<u8>;
/// Configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The overarching call type.
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
@@ -123,7 +123,7 @@ pub struct Multisig<BlockNumber, Balance, AccountId> {
}
decl_storage! {
trait Store for Module<T: Trait> as Multisig {
trait Store for Module<T: Config> as Multisig {
/// The set of open multisig operations.
pub Multisigs: double_map
hasher(twox_64_concat) T::AccountId, hasher(blake2_128_concat) [u8; 32]
@@ -134,7 +134,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Threshold must be 2 or greater.
MinimumThreshold,
/// Call is already approved by this signatory.
@@ -169,8 +169,8 @@ decl_error! {
decl_event! {
/// Events type.
pub enum Event<T> where
AccountId = <T as system::Trait>::AccountId,
BlockNumber = <T as system::Trait>::BlockNumber,
AccountId = <T as system::Config>::AccountId,
BlockNumber = <T as system::Config>::BlockNumber,
CallHash = [u8; 32]
{
/// A new multisig operation has begun. \[approving, multisig, call_hash\]
@@ -191,7 +191,7 @@ enum CallOrHash {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// Deposit one of this module's events by using the default implementation.
@@ -232,7 +232,7 @@ decl_module! {
)]
fn as_multi_threshold_1(origin,
other_signatories: Vec<T::AccountId>,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let max_sigs = T::MaxSignatories::get() as usize;
@@ -443,7 +443,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Derive a multi-account ID from the sorted list of accounts and the threshold that are
/// required.
///
@@ -615,7 +615,7 @@ impl<T: Trait> Module<T> {
}
/// Attempt to decode and return the call, provided by the user or from storage.
fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(<T as Trait>::Call, usize)> {
fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(<T as Config>::Call, usize)> {
maybe_known.map_or_else(|| {
Calls::<T>::get(hash).and_then(|(data, ..)| {
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
+3 -3
View File
@@ -59,7 +59,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = TestBaseCallFilter;
type Origin = Origin;
type Index = u64;
@@ -89,7 +89,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = TestEvent;
@@ -114,7 +114,7 @@ impl Filter<Call> for TestBaseCallFilter {
}
}
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
type Currency = Balances;
+1 -1
View File
@@ -58,7 +58,7 @@ pub trait WeightInfo {
/// Weights for pallet_multisig using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn as_multi_threshold_1(z: u32, ) -> Weight {
(14_183_000 as Weight)
.saturating_add((1_000 as Weight).saturating_mul(z as Weight))
+13 -13
View File
@@ -17,7 +17,7 @@
//! # Nicks Module
//!
//! - [`nicks::Trait`](./trait.Trait.html)
//! - [`nicks::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -37,7 +37,7 @@
//! * `kill_name` - Forcibly remove the associated name; the deposit is lost.
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
#![cfg_attr(not(feature = "std"), no_std)]
@@ -51,12 +51,12 @@ use frame_support::{
};
use frame_system::ensure_signed;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The currency trait.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -78,14 +78,14 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Nicks {
trait Store for Module<T: Config> as Nicks {
/// The lookup table for names.
NameOf: map hasher(twox_64_concat) T::AccountId => Option<(Vec<u8>, BalanceOf<T>)>;
}
}
decl_event!(
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId, Balance = BalanceOf<T> {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId, Balance = BalanceOf<T> {
/// A name was set. \[who\]
NameSet(AccountId),
/// A name was forcibly set. \[target\]
@@ -101,7 +101,7 @@ decl_event!(
decl_error! {
/// Error for the nicks module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// A name is too short.
TooShort,
/// A name is too long.
@@ -113,7 +113,7 @@ decl_error! {
decl_module! {
/// Nicks module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -262,7 +262,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -292,7 +292,7 @@ mod tests {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = ();
@@ -309,7 +309,7 @@ mod tests {
ord_parameter_types! {
pub const One: u64 = 1;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type Currency = Balances;
type ReservationFee = ReservationFee;
@@ -76,9 +76,9 @@ impl WeightInfo for () {
fn remove_connections() -> Weight { 50_000_000 }
}
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The event type of this module.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The maximum number of well known nodes that are allowed to set
type MaxWellKnownNodes: Get<u32>;
@@ -103,7 +103,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as NodeAuthorization {
trait Store for Module<T: Config> as NodeAuthorization {
/// The set of well known nodes. This is stored sorted (just by value).
pub WellKnownNodes get(fn well_known_nodes): BTreeSet<PeerId>;
/// A map that maintains the ownership of each node.
@@ -123,7 +123,7 @@ decl_storage! {
decl_event! {
pub enum Event<T> where
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
{
/// The given well known node was added.
NodeAdded(PeerId, AccountId),
@@ -149,7 +149,7 @@ decl_event! {
decl_error! {
/// Error for the node authorization module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// The PeerId is too long.
PeerIdTooLong,
/// Too many well known nodes.
@@ -170,7 +170,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// The maximum number of authorized well known nodes
const MaxWellKnownNodes: u32 = T::MaxWellKnownNodes::get();
@@ -403,7 +403,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
fn initialize_nodes(nodes: &Vec<(PeerId, T::AccountId)>) {
let peer_ids = nodes.iter()
.map(|item| item.0.clone())
@@ -453,7 +453,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -491,7 +491,7 @@ mod tests {
pub const MaxWellKnownNodes: u32 = 4;
pub const MaxPeerIdLength: u32 = 2;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type MaxWellKnownNodes = MaxWellKnownNodes;
type MaxPeerIdLength = MaxPeerIdLength;
@@ -24,22 +24,22 @@ mod mock;
use sp_std::prelude::*;
use sp_std::vec;
use frame_system::{RawOrigin, Module as System, Trait as SystemTrait};
use frame_system::{RawOrigin, Module as System, Config as SystemTrait};
use frame_benchmarking::{benchmarks, account};
use frame_support::traits::{Currency, OnInitialize};
use sp_runtime::{Perbill, traits::{Convert, StaticLookup, Saturating, UniqueSaturatedInto}};
use sp_staking::offence::{ReportOffence, Offence, OffenceDetails};
use pallet_balances::{Trait as BalancesTrait};
use pallet_balances::{Config as BalancesTrait};
use pallet_babe::BabeEquivocationOffence;
use pallet_grandpa::{GrandpaEquivocationOffence, GrandpaTimeSlot};
use pallet_im_online::{Trait as ImOnlineTrait, Module as ImOnline, UnresponsivenessOffence};
use pallet_offences::{Trait as OffencesTrait, Module as Offences};
use pallet_session::historical::{Trait as HistoricalTrait, IdentificationTuple};
use pallet_session::{Trait as SessionTrait, SessionManager};
use pallet_im_online::{Config as ImOnlineTrait, Module as ImOnline, UnresponsivenessOffence};
use pallet_offences::{Config as OffencesTrait, Module as Offences};
use pallet_session::historical::{Config as HistoricalTrait, IdentificationTuple};
use pallet_session::{Config as SessionTrait, SessionManager};
use pallet_staking::{
Module as Staking, Trait as StakingTrait, RewardDestination, ValidatorPrefs,
Module as Staking, Config as StakingTrait, RewardDestination, ValidatorPrefs,
Exposure, IndividualExposure, ElectionStatus, MAX_NOMINATIONS, Event as StakingEvent
};
@@ -50,9 +50,9 @@ const MAX_OFFENDERS: u32 = 100;
const MAX_NOMINATORS: u32 = 100;
const MAX_DEFERRED_OFFENCES: u32 = 100;
pub struct Module<T: Trait>(Offences<T>);
pub struct Module<T: Config>(Offences<T>);
pub trait Trait:
pub trait Config:
SessionTrait
+ StakingTrait
+ OffencesTrait
@@ -80,17 +80,17 @@ impl<T: HistoricalTrait + OffencesTrait> IdTupleConvert<T> for T where
type LookupSourceOf<T> = <<T as SystemTrait>::Lookup as StaticLookup>::Source;
type BalanceOf<T> = <<T as StakingTrait>::Currency as Currency<<T as SystemTrait>::AccountId>>::Balance;
struct Offender<T: Trait> {
struct Offender<T: Config> {
pub controller: T::AccountId,
pub stash: T::AccountId,
pub nominator_stashes: Vec<T::AccountId>,
}
fn bond_amount<T: Trait>() -> BalanceOf<T> {
fn bond_amount<T: Config>() -> BalanceOf<T> {
T::Currency::minimum_balance().saturating_mul(10_000u32.into())
}
fn create_offender<T: Trait>(n: u32, nominators: u32) -> Result<Offender<T>, &'static str> {
fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'static str> {
let stash: T::AccountId = account("stash", n, SEED);
let controller: T::AccountId = account("controller", n, SEED);
let controller_lookup: LookupSourceOf<T> = T::Lookup::unlookup(controller.clone());
@@ -149,7 +149,7 @@ fn create_offender<T: Trait>(n: u32, nominators: u32) -> Result<Offender<T>, &'s
Ok(Offender { controller, stash, nominator_stashes })
}
fn make_offenders<T: Trait>(num_offenders: u32, num_nominators: u32) -> Result<
fn make_offenders<T: Config>(num_offenders: u32, num_nominators: u32) -> Result<
(Vec<IdentificationTuple<T>>, Vec<Offender<T>>),
&'static str
> {
@@ -176,7 +176,7 @@ fn make_offenders<T: Trait>(num_offenders: u32, num_nominators: u32) -> Result<
}
#[cfg(test)]
fn check_events<T: Trait, I: Iterator<Item = <T as SystemTrait>::Event>>(expected: I) {
fn check_events<T: Config, I: Iterator<Item = <T as SystemTrait>::Event>>(expected: I) {
let events = System::<T>::events() .into_iter()
.map(|frame_system::EventRecord { event, .. }| event).collect::<Vec<_>>();
let expected = expected.collect::<Vec<_>>();
@@ -40,7 +40,7 @@ parameter_types! {
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = AccountIndex;
@@ -70,7 +70,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = Balance;
type Event = Event;
@@ -83,13 +83,13 @@ impl pallet_balances::Trait for Test {
parameter_types! {
pub const MinimumPeriod: u64 = 5;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
}
@@ -120,7 +120,7 @@ parameter_types! {
pub const Offset: u64 = 0;
}
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
type Keys = SessionKeys;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
@@ -149,7 +149,7 @@ parameter_types! {
pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;
impl pallet_staking::Trait for Test {
impl pallet_staking::Config for Test {
type Currency = Balances;
type UnixTime = pallet_timestamp::Module<Self>;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
@@ -174,7 +174,7 @@ impl pallet_staking::Trait for Test {
type WeightInfo = ();
}
impl pallet_im_online::Trait for Test {
impl pallet_im_online::Config for Test {
type AuthorityId = UintAuthorityId;
type Event = Event;
type SessionDuration = Period;
@@ -187,7 +187,7 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl pallet_offences::Trait for Test {
impl pallet_offences::Config for Test {
type Event = Event;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
@@ -199,7 +199,7 @@ impl<T> frame_system::offchain::SendTransactionTypes<T> for Test where Call: Fro
type OverarchingCall = Call;
}
impl crate::Trait for Test {}
impl crate::Config for Test {}
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, u64, ()>;
+11 -11
View File
@@ -42,11 +42,11 @@ use codec::{Encode, Decode};
type OpaqueTimeSlot = Vec<u8>;
/// A type alias for a report identifier.
type ReportIdOf<T> = <T as frame_system::Trait>::Hash;
type ReportIdOf<T> = <T as frame_system::Config>::Hash;
/// Type of data stored as a deferred offence
pub type DeferredOffenceOf<T> = (
Vec<OffenceDetails<<T as frame_system::Trait>::AccountId, <T as Trait>::IdentificationTuple>>,
Vec<OffenceDetails<<T as frame_system::Config>::AccountId, <T as Config>::IdentificationTuple>>,
Vec<Perbill>,
SessionIndex,
);
@@ -66,9 +66,9 @@ impl WeightInfo for () {
}
/// Offences trait
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// Full identification of the validator.
type IdentificationTuple: Parameter + Ord;
/// A handler called for every offence report.
@@ -80,7 +80,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Offences {
trait Store for Module<T: Config> as Offences {
/// The primary structure that holds all offence records keyed by report identifiers.
Reports get(fn reports):
map hasher(twox_64_concat) ReportIdOf<T>
@@ -116,7 +116,7 @@ decl_event!(
);
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn on_initialize(now: T::BlockNumber) -> Weight {
@@ -158,7 +158,7 @@ decl_module! {
}
}
impl<T: Trait, O: Offence<T::IdentificationTuple>>
impl<T: Config, O: Offence<T::IdentificationTuple>>
ReportOffence<T::AccountId, T::IdentificationTuple, O> for Module<T>
where
T::IdentificationTuple: Clone,
@@ -210,7 +210,7 @@ where
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Tries (without checking) to report an offence. Stores them in [`DeferredOffences`] in case
/// it fails. Returns false in case it has to store the offence.
fn report_or_store_offence(
@@ -293,7 +293,7 @@ impl<T: Trait> Module<T> {
}
}
struct TriageOutcome<T: Trait> {
struct TriageOutcome<T: Config> {
/// Other reports for the same report kinds.
concurrent_offenders: Vec<OffenceDetails<T::AccountId, T::IdentificationTuple>>,
}
@@ -304,13 +304,13 @@ struct TriageOutcome<T: Trait> {
/// This struct is responsible for aggregating storage writes and the underlying storage should not
/// accessed directly meanwhile.
#[must_use = "The changes are not saved without called `save`"]
struct ReportIndexStorage<T: Trait, O: Offence<T::IdentificationTuple>> {
struct ReportIndexStorage<T: Config, O: Offence<T::IdentificationTuple>> {
opaque_time_slot: OpaqueTimeSlot,
concurrent_reports: Vec<ReportIdOf<T>>,
same_kind_reports: Vec<(O::TimeSlot, ReportIdOf<T>)>,
}
impl<T: Trait, O: Offence<T::IdentificationTuple>> ReportIndexStorage<T, O> {
impl<T: Config, O: Offence<T::IdentificationTuple>> ReportIndexStorage<T, O> {
/// Preload indexes from the storage for the specific `time_slot` and the kind of the offence.
fn load(time_slot: &O::TimeSlot) -> Self {
let opaque_time_slot = time_slot.encode();
+3 -3
View File
@@ -20,7 +20,7 @@
#![cfg(test)]
use std::cell::RefCell;
use crate::{Module, Trait};
use crate::{Module, Config};
use codec::Encode;
use sp_runtime::Perbill;
use sp_staking::{
@@ -95,7 +95,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -127,7 +127,7 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl Trait for Runtime {
impl Config for Runtime {
type Event = TestEvent;
type IdentificationTuple = u64;
type OnOffenceHandler = OnOffenceHandler;
+1 -1
View File
@@ -342,7 +342,7 @@ fn weight_soft_limit_is_used() {
new_test_ext().execute_with(|| {
set_can_report(false);
// Only 2 can fit in one block
set_offence_weight(<mock::Runtime as Trait>::WeightSoftLimit::get() / 2);
set_offence_weight(<mock::Runtime as Config>::WeightSoftLimit::get() / 2);
// Queue 3 offences
// #1
+9 -9
View File
@@ -27,15 +27,15 @@ use crate::Module as Proxy;
const SEED: u32 = 0;
fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}
fn add_proxies<T: Trait>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(), &'static str> {
fn add_proxies<T: Config>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(), &'static str> {
let caller = maybe_who.unwrap_or_else(|| whitelisted_caller());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
for i in 0..n {
@@ -49,7 +49,7 @@ fn add_proxies<T: Trait>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(),
Ok(())
}
fn add_announcements<T: Trait>(
fn add_announcements<T: Config>(
n: u32,
maybe_who: Option<T::AccountId>,
maybe_real: Option<T::AccountId>
@@ -91,7 +91,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(RawEvent::ProxyExecuted(Ok(())).into())
@@ -106,7 +106,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&delegate, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(delegate.clone()).into(),
real.clone(),
@@ -126,7 +126,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
@@ -147,7 +147,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
@@ -169,7 +169,7 @@ benchmarks! {
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
add_announcements::<T>(a, Some(caller.clone()), None)?;
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call: <T as Config>::Call = frame_system::Call::<T>::remark(vec![]).into();
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
verify {
+20 -20
View File
@@ -23,7 +23,7 @@
//! wish to execute some duration prior to execution happens. In this case, the target account may
//! reject the announcement and in doing so, veto the execution.
//!
//! - [`proxy::Trait`](./trait.Trait.html)
//! - [`proxy::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -33,7 +33,7 @@
//! ### Dispatchable Functions
//!
//! [`Call`]: ./enum.Call.html
//! [`Trait`]: ./trait.Trait.html
//! [`Config`]: ./trait.Config.html
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -55,17 +55,17 @@ use frame_system::{self as system, ensure_signed};
use frame_support::dispatch::DispatchError;
pub use weights::WeightInfo;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// Configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The overarching call type.
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
+ GetDispatchInfo + From<frame_system::Call<Self>> + IsSubType<Call<Self>>
+ IsType<<Self as frame_system::Trait>::Call>;
+ IsType<<Self as frame_system::Config>::Call>;
/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;
@@ -74,7 +74,7 @@ pub trait Trait: frame_system::Trait {
/// The instance filter determines whether a given call may be proxied under this type.
///
/// IMPORTANT: `Default` must be provided and MUST BE the the *most permissive* value.
type ProxyType: Parameter + Member + Ord + PartialOrd + InstanceFilter<<Self as Trait>::Call>
type ProxyType: Parameter + Member + Ord + PartialOrd + InstanceFilter<<Self as Config>::Call>
+ Default;
/// The base amount of currency needed to reserve for creating a proxy.
@@ -137,10 +137,10 @@ pub struct Announcement<AccountId, Hash, BlockNumber> {
height: BlockNumber,
}
type CallHashOf<T> = <<T as Trait>::CallHasher as Hash>::Output;
type CallHashOf<T> = <<T as Config>::CallHasher as Hash>::Output;
decl_storage! {
trait Store for Module<T: Trait> as Proxy {
trait Store for Module<T: Config> as Proxy {
/// The set of account proxies. Maps the account which has delegated to the accounts
/// which are being delegated to, together with the amount held on deposit.
pub Proxies get(fn proxies): map hasher(twox_64_concat) T::AccountId
@@ -153,7 +153,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// There are too many proxies registered or too many announcements pending.
TooMany,
/// Proxy registration not found.
@@ -174,8 +174,8 @@ decl_error! {
decl_event! {
/// Events type.
pub enum Event<T> where
AccountId = <T as frame_system::Trait>::AccountId,
ProxyType = <T as Trait>::ProxyType,
AccountId = <T as frame_system::Config>::AccountId,
ProxyType = <T as Config>::ProxyType,
Hash = CallHashOf<T>,
{
/// A proxy was executed correctly, with the given \[result\].
@@ -189,7 +189,7 @@ decl_event! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// Deposit one of this module's events by using the default implementation.
@@ -239,7 +239,7 @@ decl_module! {
fn proxy(origin,
real: T::AccountId,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
let who = ensure_signed(origin)?;
let def = Self::find_proxy(&real, &who, force_proxy_type)?;
@@ -509,7 +509,7 @@ decl_module! {
delegate: T::AccountId,
real: T::AccountId,
force_proxy_type: Option<T::ProxyType>,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
ensure_signed(origin)?;
let def = Self::find_proxy(&real, &delegate, force_proxy_type)?;
@@ -525,7 +525,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Calculate the address of an anonymous account.
///
@@ -680,12 +680,12 @@ impl<T: Trait> Module<T> {
fn do_proxy(
def: ProxyDefinition<T::AccountId, T::ProxyType, T::BlockNumber>,
real: T::AccountId,
call: <T as Trait>::Call,
call: <T as Config>::Call,
) {
// This is a freshly authenticated new account, the origin restrictions doesn't apply.
let mut origin: T::Origin = frame_system::RawOrigin::Signed(real).into();
origin.add_filter(move |c: &<T as frame_system::Trait>::Call| {
let c = <T as Trait>::Call::from_ref(c);
origin.add_filter(move |c: &<T as frame_system::Config>::Call| {
let c = <T as Config>::Call::from_ref(c);
// We make sure the proxy call does access this pallet to change modify proxies.
match c.is_sub_type() {
// Proxy call cannot add or remove a proxy with more permissions than it already has.
@@ -714,7 +714,7 @@ pub mod migration {
/// `ProxyDefinition` which additionally included a `BlockNumber` delay value. This function,
/// simply takes any existing proxies using the old tuple format, and migrates it to the new
/// struct by setting the delay to zero.
pub fn migrate_to_time_delayed_proxies<T: Trait>() -> Weight {
pub fn migrate_to_time_delayed_proxies<T: Config>() -> Weight {
Proxies::<T>::translate::<(Vec<(T::AccountId, T::ProxyType)>, BalanceOf<T>), _>(
|_, (targets, deposit)| Some((
targets.into_iter()
+4 -4
View File
@@ -61,7 +61,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type Origin = Origin;
type Index = u64;
@@ -91,7 +91,7 @@ impl frame_system::Trait for Test {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = TestEvent;
@@ -100,7 +100,7 @@ impl pallet_balances::Trait for Test {
type AccountStore = System;
type WeightInfo = ();
}
impl pallet_utility::Trait for Test {
impl pallet_utility::Config for Test {
type Event = TestEvent;
type Call = Call;
type WeightInfo = ();
@@ -143,7 +143,7 @@ impl Filter<Call> for BaseFilter {
}
}
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
type Currency = Balances;
+1 -1
View File
@@ -58,7 +58,7 @@ pub trait WeightInfo {
/// Weights for pallet_proxy using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn proxy(p: u32, ) -> Weight {
(32_194_000 as Weight)
.saturating_add((215_000 as Weight).saturating_mul(p as Weight))
@@ -39,10 +39,10 @@
//! ```
//! use frame_support::{decl_module, dispatch, traits::Randomness};
//!
//! pub trait Trait: frame_system::Trait {}
//! pub trait Config: frame_system::Config {}
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! #[weight = 0]
//! pub fn random_module_example(origin) -> dispatch::DispatchResult {
//! let _random_value = <pallet_randomness_collective_flip::Module<T>>::random(&b"my context"[..]);
@@ -63,18 +63,18 @@ use frame_support::{
};
use safe_mix::TripletMix;
use codec::Encode;
use frame_system::Trait;
use frame_system::Config;
const RANDOM_MATERIAL_LEN: u32 = 81;
fn block_number_to_index<T: Trait>(block_number: T::BlockNumber) -> usize {
fn block_number_to_index<T: Config>(block_number: T::BlockNumber) -> usize {
// on_initialize is called on the first block after genesis
let index = (block_number - 1u32.into()) % RANDOM_MATERIAL_LEN.into();
index.try_into().ok().expect("Something % 81 is always smaller than usize; qed")
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn on_initialize(block_number: T::BlockNumber) -> Weight {
let parent_hash = <frame_system::Module<T>>::parent_hash();
@@ -91,7 +91,7 @@ decl_module! {
}
decl_storage! {
trait Store for Module<T: Trait> as RandomnessCollectiveFlip {
trait Store for Module<T: Config> as RandomnessCollectiveFlip {
/// Series of block headers from the last 81 blocks that acts as random seed material. This
/// is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
/// the oldest hash.
@@ -99,7 +99,7 @@ decl_storage! {
}
}
impl<T: Trait> Randomness<T::Hash> for Module<T> {
impl<T: Config> Randomness<T::Hash> for Module<T> {
/// This randomness uses a low-influence function, drawing upon the block hashes from the
/// previous 81 blocks. Its result for any given subject will be known far in advance by anyone
/// observing the chain. Any block producer has significant influence over their block hashes
@@ -157,7 +157,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
+10 -10
View File
@@ -17,7 +17,7 @@
//! # Recovery Pallet
//!
//! - [`recovery::Trait`](./trait.Trait.html)
//! - [`recovery::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -172,12 +172,12 @@ mod mock;
mod tests;
type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
/// Configuration trait.
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// The overarching call type.
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo> + GetDispatchInfo;
@@ -237,7 +237,7 @@ pub struct RecoveryConfig<BlockNumber, Balance, AccountId> {
}
decl_storage! {
trait Store for Module<T: Trait> as Recovery {
trait Store for Module<T: Config> as Recovery {
/// The set of recoverable accounts and their recovery configuration.
pub Recoverable get(fn recovery_config):
map hasher(twox_64_concat) T::AccountId
@@ -262,7 +262,7 @@ decl_storage! {
decl_event! {
/// Events type.
pub enum Event<T> where
AccountId = <T as system::Trait>::AccountId,
AccountId = <T as system::Config>::AccountId,
{
/// A recovery process has been set up for an \[account\].
RecoveryCreated(AccountId),
@@ -284,7 +284,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// User is not allowed to make a call on behalf of this account
NotAllowed,
/// Threshold must be greater than zero
@@ -321,7 +321,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// The base amount of currency needed to reserve for creating a recovery configuration.
@@ -361,7 +361,7 @@ decl_module! {
)]
fn as_recovered(origin,
account: T::AccountId,
call: Box<<T as Trait>::Call>
call: Box<<T as Config>::Call>
) -> DispatchResult {
let who = ensure_signed(origin)?;
// Check `who` is allowed to make a call on behalf of `account`
@@ -677,7 +677,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Check that friends list is sorted and has no duplicates.
fn is_sorted_and_unique(friends: &Vec<T::AccountId>) -> bool {
friends.windows(2).all(|w| w[0] < w[1])
+3 -3
View File
@@ -58,7 +58,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = Call;
@@ -90,7 +90,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
@@ -107,7 +107,7 @@ parameter_types! {
pub const RecoveryDeposit: u64 = 10;
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
type Currency = Balances;
@@ -31,7 +31,7 @@ use frame_system::Module as System;
const BLOCK_NUMBER: u32 = 2;
// Add `n` named items to the schedule
fn fill_schedule<T: Trait> (when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
fn fill_schedule<T: Config> (when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
// Essentially a no-op call.
let call = frame_system::Call::set_storage(vec![]);
for i in 0..n {
+50 -50
View File
@@ -18,7 +18,7 @@
//! # Scheduler
//! A module for scheduling dispatches.
//!
//! - [`scheduler::Trait`](./trait.Trait.html)
//! - [`scheduler::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -29,7 +29,7 @@
//! may be named or anonymous and may be canceled.
//!
//! **NOTE:** The scheduled calls will be dispatched with the default filter
//! for the origin: namely `frame_system::Trait::BaseCallFilter` for all origin
//! for the origin: namely `frame_system::Config::BaseCallFilter` for all origin
//! except root which will get no filter. And not the filter contained in origin
//! use to call `fn schedule`.
//!
@@ -70,27 +70,27 @@ pub use weights::WeightInfo;
/// pallet is dependent on specific other pallets, then their configuration traits
/// should be added to our implied traits list.
///
/// `system::Trait` should always be included in our implied traits.
pub trait Trait: system::Trait {
/// `system::Config` should always be included in our implied traits.
pub trait Config: system::Config {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;
/// The aggregated origin which the dispatch will take.
type Origin: OriginTrait<PalletsOrigin =
Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Trait>::Origin>;
Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Config>::Origin>;
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + Clone + Eq;
/// The aggregated call type.
type Call: Parameter + Dispatchable<Origin=<Self as Trait>::Origin> + GetDispatchInfo + From<system::Call<Self>>;
type Call: Parameter + Dispatchable<Origin=<Self as Config>::Origin> + GetDispatchInfo + From<system::Call<Self>>;
/// The maximum weight that may be scheduled per block for any dispatchables of less priority
/// than `schedule::HARD_DEADLINE`.
type MaximumWeight: Get<Weight>;
/// Required origin to schedule or cancel calls.
type ScheduleOrigin: EnsureOrigin<<Self as system::Trait>::Origin>;
type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
/// The maximum number of scheduled calls in the queue for a single block.
/// Not strictly enforced, but used for weight estimation.
@@ -150,10 +150,10 @@ impl Default for Releases {
}
decl_storage! {
trait Store for Module<T: Trait> as Scheduler {
trait Store for Module<T: Config> as Scheduler {
/// Items to be executed, indexed by the block number that they should be executed on.
pub Agenda: map hasher(twox_64_concat) T::BlockNumber
=> Vec<Option<Scheduled<<T as Trait>::Call, T::BlockNumber, T::PalletsOrigin, T::AccountId>>>;
=> Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, T::PalletsOrigin, T::AccountId>>>;
/// Lookup from identity to the block number and index of the task.
Lookup: map hasher(twox_64_concat) Vec<u8> => Option<TaskAddress<T::BlockNumber>>;
@@ -166,7 +166,7 @@ decl_storage! {
}
decl_event!(
pub enum Event<T> where <T as system::Trait>::BlockNumber {
pub enum Event<T> where <T as system::Config>::BlockNumber {
/// Scheduled some task. \[when, index\]
Scheduled(BlockNumber, u32),
/// Canceled some task. \[when, index\]
@@ -177,7 +177,7 @@ decl_event!(
);
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Failed to schedule a call
FailedToSchedule,
/// Cannot find the scheduled call.
@@ -191,7 +191,7 @@ decl_error! {
decl_module! {
/// Scheduler module declaration.
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
pub struct Module<T: Config> for enum Call where origin: <T as system::Config>::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -210,10 +210,10 @@ decl_module! {
when: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_schedule(DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call)?;
}
@@ -230,7 +230,7 @@ decl_module! {
#[weight = T::WeightInfo::cancel(T::MaxScheduledPerBlock::get())]
fn cancel(origin, when: T::BlockNumber, index: u32) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
}
@@ -250,10 +250,10 @@ decl_module! {
when: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_schedule_named(
id, DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call
)?;
@@ -272,7 +272,7 @@ decl_module! {
#[weight = T::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get())]
fn cancel_named(origin, id: Vec<u8>) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_cancel_named(Some(origin.caller().clone()), id)?;
}
@@ -286,10 +286,10 @@ decl_module! {
after: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_schedule(
DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call
)?;
@@ -306,10 +306,10 @@ decl_module! {
after: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
call: Box<<T as Trait>::Call>,
call: Box<<T as Config>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let origin = <T as Config>::Origin::from(origin);
Self::do_schedule_named(
id, DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call
)?;
@@ -347,7 +347,7 @@ decl_module! {
*cumulative_weight = cumulative_weight
.saturating_add(s.call.get_dispatch_info().weight);
let origin = <<T as Trait>::Origin as From<T::PalletsOrigin>>::from(
let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
s.origin.clone()
).into();
@@ -415,7 +415,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Migrate storage format from V1 to V2.
/// Return true if migration is performed.
pub fn migrate_v1_to_t2() -> bool {
@@ -423,7 +423,7 @@ impl<T: Trait> Module<T> {
StorageVersion::put(Releases::V2);
Agenda::<T>::translate::<
Vec<Option<ScheduledV1<<T as Trait>::Call, T::BlockNumber>>>, _
Vec<Option<ScheduledV1<<T as Config>::Call, T::BlockNumber>>>, _
>(|_, agenda| Some(
agenda
.into_iter()
@@ -447,7 +447,7 @@ impl<T: Trait> Module<T> {
/// Helper to migrate scheduler when the pallet origin type has changed.
pub fn migrate_origin<OldOrigin: Into<T::PalletsOrigin> + codec::Decode>() {
Agenda::<T>::translate::<
Vec<Option<Scheduled<<T as Trait>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>, _
Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>, _
>(|_, agenda| Some(
agenda
.into_iter()
@@ -485,7 +485,7 @@ impl<T: Trait> Module<T> {
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: <T as Trait>::Call
call: <T as Config>::Call
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
let when = Self::resolve_time(when)?;
@@ -569,7 +569,7 @@ impl<T: Trait> Module<T> {
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: <T as Trait>::Call,
call: <T as Config>::Call,
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
// ensure id it is unique
if Lookup::<T>::contains_key(&id) {
@@ -657,7 +657,7 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
impl<T: Config> schedule::Anon<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin> for Module<T> {
type Address = TaskAddress<T::BlockNumber>;
fn schedule(
@@ -665,7 +665,7 @@ impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrig
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: <T as Trait>::Call
call: <T as Config>::Call
) -> Result<Self::Address, DispatchError> {
Self::do_schedule(when, maybe_periodic, priority, origin, call)
}
@@ -686,7 +686,7 @@ impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrig
}
}
impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
impl<T: Config> schedule::Named<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin> for Module<T> {
type Address = TaskAddress<T::BlockNumber>;
fn schedule_named(
@@ -695,7 +695,7 @@ impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOri
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: <T as Trait>::Call,
call: <T as Config>::Call,
) -> Result<Self::Address, ()> {
Self::do_schedule_named(id, when, maybe_periodic, priority, origin, call).map_err(|_| ())
}
@@ -746,8 +746,8 @@ mod tests {
pub fn log() -> Vec<(OriginCaller, u32)> {
LOG.with(|log| log.borrow().clone())
}
pub trait Trait: system::Trait {
type Event: From<Event> + Into<<Self as system::Trait>::Event>;
pub trait Config: system::Config {
type Event: From<Event> + Into<<Self as system::Config>::Event>;
}
decl_event! {
pub enum Event {
@@ -755,10 +755,10 @@ mod tests {
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call
pub struct Module<T: Config> for enum Call
where
origin: <T as system::Trait>::Origin,
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
origin: <T as system::Config>::Origin,
<T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
{
fn deposit_event() = default;
@@ -816,7 +816,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl system::Trait for Test {
impl system::Config for Test {
type BaseCallFilter = BaseFilter;
type Origin = Origin;
type Call = Call;
@@ -843,7 +843,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl logger::Trait for Test {
impl logger::Config for Test {
type Event = ();
}
parameter_types! {
@@ -854,7 +854,7 @@ mod tests {
pub const One: u64 = 1;
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type Origin = Origin;
type PalletsOrigin = OriginCaller;
@@ -889,7 +889,7 @@ mod tests {
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call));
run_to_block(3);
assert!(logger::log().is_empty());
@@ -905,7 +905,7 @@ mod tests {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
assert_ok!(Scheduler::do_schedule(DispatchTime::After(3), None, 127, root(), call));
run_to_block(5);
@@ -922,7 +922,7 @@ mod tests {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::After(0), None, 127, root(), call));
// Will trigger on the next block.
run_to_block(3);
@@ -960,7 +960,7 @@ mod tests {
fn reschedule_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert_eq!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call).unwrap(), (4, 0));
run_to_block(3);
@@ -985,7 +985,7 @@ mod tests {
fn reschedule_named_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert_eq!(Scheduler::do_schedule_named(
1u32.encode(), DispatchTime::At(4), None, 127, root(), call
).unwrap(), (4, 0));
@@ -1012,7 +1012,7 @@ mod tests {
fn reschedule_named_perodic_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(logger::Call::log(42, 1000));
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert_eq!(Scheduler::do_schedule_named(
1u32.encode(), DispatchTime::At(4), Some((3, 3)), 127, root(), call
).unwrap(), (4, 0));
@@ -1203,10 +1203,10 @@ mod tests {
#[test]
fn on_initialize_weight_is_correct() {
new_test_ext().execute_with(|| {
let base_weight: Weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 2);
let base_weight: Weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 2);
let base_multiplier = 0;
let named_multiplier = <Test as frame_system::Trait>::DbWeight::get().writes(1);
let periodic_multiplier = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 1);
let named_multiplier = <Test as frame_system::Config>::DbWeight::get().writes(1);
let periodic_multiplier = <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 1);
// Named
assert_ok!(
+1 -1
View File
@@ -52,7 +52,7 @@ pub trait WeightInfo {
/// Weights for pallet_scheduler using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn schedule(s: u32, ) -> Weight {
(35_029_000 as Weight)
.saturating_add((77_000 as Weight).saturating_mul(s as Weight))
+13 -13
View File
@@ -37,7 +37,7 @@
//! from the `Pool` and `Members`; the entity is immediately replaced
//! by the next highest scoring candidate in the pool, if available.
//!
//! - [`scored_pool::Trait`](./trait.Trait.html)
//! - [`scored_pool::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -58,10 +58,10 @@
//! use frame_system::ensure_signed;
//! use pallet_scored_pool::{self as scored_pool};
//!
//! pub trait Trait: scored_pool::Trait {}
//! pub trait Config: scored_pool::Config {}
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! #[weight = 0]
//! pub fn candidate(origin) -> dispatch::DispatchResult {
//! let who = ensure_signed(origin)?;
@@ -103,8 +103,8 @@ use frame_support::{
use frame_system::{ensure_root, ensure_signed};
use sp_runtime::traits::{AtLeast32Bit, MaybeSerializeDeserialize, Zero, StaticLookup};
type BalanceOf<T, I> = <<T as Trait<I>>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type PoolT<T, I> = Vec<(<T as frame_system::Trait>::AccountId, Option<<T as Trait<I>>::Score>)>;
type BalanceOf<T, I> = <<T as Config<I>>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type PoolT<T, I> = Vec<(<T as frame_system::Config>::AccountId, Option<<T as Config<I>>::Score>)>;
/// The enum is supplied when refreshing the members set.
/// Depending on the enum variant the corresponding associated
@@ -116,7 +116,7 @@ enum ChangeReceiver {
MembershipChanged,
}
pub trait Trait<I=DefaultInstance>: frame_system::Trait {
pub trait Config<I=DefaultInstance>: frame_system::Config {
/// The currency used for deposits.
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
@@ -125,7 +125,7 @@ pub trait Trait<I=DefaultInstance>: frame_system::Trait {
AtLeast32Bit + Clone + Copy + Default + FullCodec + MaybeSerializeDeserialize + Debug;
/// The overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
// The deposit which is reserved from candidates if they want to
// start a candidacy. The deposit gets returned when the candidacy is
@@ -156,7 +156,7 @@ pub trait Trait<I=DefaultInstance>: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as ScoredPool {
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as ScoredPool {
/// The current pool of candidates, stored as an ordered Vec
/// (ordered descending by score, `None` last, highest first).
Pool get(fn pool) config(): PoolT<T, I>;
@@ -204,7 +204,7 @@ decl_storage! {
decl_event!(
pub enum Event<T, I=DefaultInstance> where
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
{
/// The given member was removed. See the transaction for who.
MemberRemoved,
@@ -225,7 +225,7 @@ decl_event!(
decl_error! {
/// Error for the scored-pool module.
pub enum Error for Module<T: Trait<I>, I: Instance> {
pub enum Error for Module<T: Config<I>, I: Instance> {
/// Already a member.
AlreadyInPool,
/// Index out of bounds.
@@ -236,7 +236,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance>
pub struct Module<T: Config<I>, I: Instance=DefaultInstance>
for enum Call
where origin: T::Origin
{
@@ -275,7 +275,7 @@ decl_module! {
// can be inserted as last element in pool, since entities with
// `None` are always sorted to the end.
<Pool<T, I>>::append((who.clone(), Option::<<T as Trait<I>>::Score>::None));
<Pool<T, I>>::append((who.clone(), Option::<<T as Config<I>>::Score>::None));
<CandidateExists<T, I>>::insert(&who, true);
@@ -382,7 +382,7 @@ decl_module! {
}
}
impl<T: Trait<I>, I: Instance> Module<T, I> {
impl<T: Config<I>, I: Instance> Module<T, I> {
/// Fetches the `MemberCount` highest scoring members from
/// `Pool` and puts them into `Members`.
+3 -3
View File
@@ -49,7 +49,7 @@ ord_parameter_types! {
pub const ScoreOrigin: u64 = 3;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -77,7 +77,7 @@ impl frame_system::Trait for Test {
type SystemWeightInfo = ();
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = ();
@@ -114,7 +114,7 @@ impl InitializeMembers<u64> for TestChangeMembers {
}
}
impl Trait for Test {
impl Config for Test {
type Event = ();
type KickOrigin = EnsureSignedBy<KickOrigin, u64>;
type MembershipInitialized = TestChangeMembers;

Some files were not shown because too many files have changed in this diff Show More