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
+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))