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
+49 -49
View File
@@ -72,9 +72,9 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # #[macro_use]
/// # extern crate frame_support;
/// # use frame_support::dispatch;
/// # use frame_system::{Trait, ensure_signed};
/// # use frame_system::{Config, ensure_signed};
/// 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 {
///
/// // Private functions are dispatchable, but not available to other
/// // FRAME pallets.
@@ -98,7 +98,7 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
///
/// The declaration is set with the header where:
///
/// * `Module`: The struct generated by the macro, with type `Trait`.
/// * `Module`: The struct generated by the macro, with type `Config`.
/// * `Call`: The enum generated for every pallet, which implements [`Callable`](./dispatch/trait.Callable.html).
/// * `origin`: Alias of `T::Origin`, declared by the [`impl_outer_origin!`](./macro.impl_outer_origin.html) macro.
/// * `Result`: The expected return type from pallet functions.
@@ -114,9 +114,9 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # #[macro_use]
/// # extern crate frame_support;
/// # use frame_support::dispatch;
/// # use frame_system::{Trait, ensure_signed};
/// # use frame_system::{Config, ensure_signed};
/// 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]
/// fn my_long_function(origin) -> dispatch::DispatchResult {
/// // Your implementation
@@ -149,9 +149,9 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # #[macro_use]
/// # extern crate frame_support;
/// # use frame_support::dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo};
/// # use frame_system::{Trait, ensure_signed};
/// # use frame_system::{Config, ensure_signed};
/// 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 = 1_000_000]
/// fn my_long_function(origin, do_expensive_calc: bool) -> DispatchResultWithPostInfo {
/// ensure_signed(origin).map_err(|e| e.with_weight(100_000))?;
@@ -178,9 +178,9 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # #[macro_use]
/// # extern crate frame_support;
/// # use frame_support::transactional;
/// # use frame_system::Trait;
/// # use 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]
/// #[transactional]
/// fn my_short_function(origin) {
@@ -199,9 +199,9 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # #[macro_use]
/// # extern crate frame_support;
/// # use frame_support::dispatch;
/// # use frame_system::{Trait, ensure_signed, ensure_root};
/// # use frame_system::{Config, ensure_signed, ensure_root};
/// 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]
/// fn my_privileged_function(origin) -> dispatch::DispatchResult {
/// ensure_root(origin)?;
@@ -236,10 +236,10 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # pub struct DefaultInstance;
/// # pub trait Instance: 'static {}
/// # impl Instance for DefaultInstance {}
/// pub trait Trait<I: Instance=DefaultInstance>: frame_system::Trait {}
/// pub trait Config<I: Instance=DefaultInstance>: frame_system::Config {}
///
/// 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 {
/// // Your implementation
/// }
/// }
@@ -261,10 +261,10 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # extern crate frame_support;
/// # use frame_support::dispatch;
/// # use frame_system::{self as system, ensure_signed};
/// pub trait Trait: system::Trait where Self::AccountId: From<u32> {}
/// pub trait Config: system::Config where Self::AccountId: From<u32> {}
///
/// decl_module! {
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
/// // Your implementation
/// }
/// }
@@ -1272,11 +1272,11 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn on_initialize() -> $return:ty { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) -> $return {
fn on_initialize(_block_number_not_used: <$trait_instance as $system::Config>::BlockNumber) -> $return {
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_initialize"));
{ $( $impl )* }
}
@@ -1289,8 +1289,8 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn on_initialize($param:ident : $param_ty:ty) -> $return:ty { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize($param: $param_ty) -> $return {
@@ -1305,8 +1305,8 @@ macro_rules! decl_module {
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
@@ -1326,10 +1326,10 @@ macro_rules! decl_module {
let result: $return = (|| { $( $impl )* })();
$crate::crate_to_pallet_version!()
.put_into_storage::<<$trait_instance as $system::Trait>::PalletInfo, Self>();
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
let additional_write = <
<$trait_instance as $system::Trait>::DbWeight as $crate::traits::Get<_>
<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>
>::get().writes(1);
result.saturating_add(additional_write)
@@ -1350,10 +1350,10 @@ macro_rules! decl_module {
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade"));
$crate::crate_to_pallet_version!()
.put_into_storage::<<$trait_instance as $system::Trait>::PalletInfo, Self>();
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
<
<$trait_instance as $system::Trait>::DbWeight as $crate::traits::Get<_>
<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>
>::get().writes(1)
}
}
@@ -1394,11 +1394,11 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn on_finalize() { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) {
fn on_finalize(_block_number_not_used: <$trait_instance as $system::Config>::BlockNumber) {
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_finalize"));
{ $( $impl )* }
}
@@ -1411,8 +1411,8 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn on_finalize($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize($param: $param_ty) {
@@ -1427,8 +1427,8 @@ macro_rules! decl_module {
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
}
@@ -1440,11 +1440,11 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn offchain_worker() { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn offchain_worker(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) { $( $impl )* }
fn offchain_worker(_block_number_not_used: <$trait_instance as $system::Config>::BlockNumber) { $( $impl )* }
}
};
@@ -1454,8 +1454,8 @@ macro_rules! decl_module {
{ $( $other_where_bounds:tt )* }
fn offchain_worker($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn offchain_worker($param: $param_ty) { $( $impl )* }
@@ -1467,8 +1467,8 @@ macro_rules! decl_module {
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
impl<$trait_instance: $system::Config + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Config>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
@@ -1824,7 +1824,7 @@ macro_rules! decl_module {
fn storage_version() -> Option<$crate::traits::PalletVersion> {
let key = $crate::traits::PalletVersion::storage_key::<
<$trait_instance as $system::Trait>::PalletInfo, Self
<$trait_instance as $system::Config>::PalletInfo, Self
>().expect("Every active pallet has a name in the runtime; qed");
$crate::storage::unhashed::get(&key)
@@ -1837,7 +1837,7 @@ macro_rules! decl_module {
{
fn on_genesis() {
$crate::crate_to_pallet_version!()
.put_into_storage::<<$trait_instance as $system::Trait>::PalletInfo, Self>();
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
}
}
@@ -2019,7 +2019,7 @@ macro_rules! impl_outer_dispatch {
}
impl $crate::dispatch::Dispatchable for $call_type {
type Origin = $origin;
type Trait = $call_type;
type Config = $call_type;
type Info = $crate::weights::DispatchInfo;
type PostInfo = $crate::weights::PostDispatchInfo;
fn dispatch(
@@ -2412,12 +2412,12 @@ mod tests {
IntegrityTest, Get,
};
pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> { }
pub trait Config: system::Config + Sized where Self::AccountId: From<u32> { }
pub mod system {
use super::*;
pub trait Trait: 'static {
pub trait Config: 'static {
type AccountId;
type Call;
type BaseCallFilter;
@@ -2443,11 +2443,11 @@ mod tests {
}
}
pub type Origin<T> = RawOrigin<<T as Trait>::AccountId>;
pub type Origin<T> = RawOrigin<<T as Config>::AccountId>;
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = system, T::AccountId: From<u32> {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = system, T::AccountId: From<u32> {
/// Hi, this is a comment.
#[weight = 0]
fn aux_0(_origin) -> DispatchResult { unreachable!() }
@@ -2548,7 +2548,7 @@ mod tests {
];
pub struct TraitImpl {}
impl Trait for TraitImpl { }
impl Config for TraitImpl { }
type Test = Module<TraitImpl>;
@@ -2562,7 +2562,7 @@ mod tests {
}
}
impl system::Trait for TraitImpl {
impl system::Config for TraitImpl {
type Origin = OuterOrigin;
type AccountId = u32;
type Call = OuterCall;