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;
+3 -3
View File
@@ -39,7 +39,7 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
/// #
/// decl_error! {
/// /// Errors that can occur in my module.
/// pub enum MyError for Module<T: Trait> {
/// pub enum MyError for Module<T: Config> {
/// /// Hey this is an error message that indicates bla.
/// MyCoolErrorMessage,
/// /// You are just not cool enough for my module!
@@ -47,13 +47,13 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
/// }
/// }
///
/// # use frame_system::Trait;
/// # use frame_system::Config;
///
/// // You need to register the error type in `decl_module!` as well to make the error
/// // exported in the metadata.
///
/// 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 = MyError<T>;
///
/// #[weight = 0]
+35 -35
View File
@@ -37,7 +37,7 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
/// # Generic Event Example:
///
/// ```rust
/// trait Trait {
/// trait Config {
/// type Balance;
/// type Token;
/// }
@@ -45,7 +45,7 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
/// mod event1 {
/// // Event that specifies the generic parameter explicitly (`Balance`).
/// frame_support::decl_event!(
/// pub enum Event<T> where Balance = <T as super::Trait>::Balance {
/// pub enum Event<T> where Balance = <T as super::Config>::Balance {
/// Message(Balance),
/// }
/// );
@@ -56,7 +56,7 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
/// // If no name for the generic parameter is specified explicitly,
/// // the name will be taken from the type name of the trait.
/// frame_support::decl_event!(
/// pub enum Event<T> where <T as super::Trait>::Balance {
/// pub enum Event<T> where <T as super::Config>::Balance {
/// Message(Balance),
/// }
/// );
@@ -65,7 +65,7 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
/// mod event3 {
/// // And we even support declaring multiple generic parameters!
/// frame_support::decl_event!(
/// pub enum Event<T> where <T as super::Trait>::Balance, <T as super::Trait>::Token {
/// pub enum Event<T> where <T as super::Config>::Balance, <T as super::Config>::Token {
/// Message(Balance, Token),
/// }
/// );
@@ -82,7 +82,7 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
///# struct DefaultInstance;
///# trait Instance {}
///# impl Instance for DefaultInstance {}
/// trait Trait<I: Instance=DefaultInstance> {
/// trait Config<I: Instance=DefaultInstance> {
/// type Balance;
/// type Token;
/// }
@@ -90,8 +90,8 @@ pub use frame_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnE
/// // For module with instances, DefaultInstance is optional
/// frame_support::decl_event!(
/// pub enum Event<T, I: Instance = DefaultInstance> where
/// <T as Trait>::Balance,
/// <T as Trait>::Token
/// <T as Config>::Balance,
/// <T as Config>::Token
/// {
/// Message(Balance, Token),
/// }
@@ -258,10 +258,10 @@ macro_rules! __decl_generic_event {
{ $( $events:tt )* };
{ ,$( $generic_param:ident = $generic_type:ty ),* };
) => {
/// [`RawEvent`] specialized for the configuration [`Trait`]
/// [`RawEvent`] specialized for the configuration [`Config`]
///
/// [`RawEvent`]: enum.RawEvent.html
/// [`Trait`]: trait.Trait.html
/// [`Config`]: trait.Config.html
pub type Event<$event_generic_param $(, $instance $( = $event_default_instance)? )?> = RawEvent<$( $generic_type ),* $(, $instance)? >;
#[derive(
@@ -551,7 +551,7 @@ mod tests {
use codec::{Encode, Decode};
mod system {
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
@@ -559,7 +559,7 @@ mod tests {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
decl_event!(
@@ -570,7 +570,7 @@ mod tests {
}
mod system_renamed {
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
@@ -578,7 +578,7 @@ mod tests {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
decl_event!(
@@ -591,17 +591,17 @@ mod tests {
mod event_module {
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
decl_event!(
/// Event without renaming the generic parameter `Balance` and `Origin`.
pub enum Event<T> where <T as Trait>::Balance, <T as system::Trait>::Origin
pub enum Event<T> where <T as Config>::Balance, <T as system::Config>::Origin
{
/// Hi, I am a comment.
TestEvent(Balance, Origin),
@@ -614,19 +614,19 @@ mod tests {
mod event_module2 {
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
decl_event!(
/// Event with renamed generic parameter
pub enum Event<T> where
BalanceRenamed = <T as Trait>::Balance,
OriginRenamed = <T as system::Trait>::Origin
BalanceRenamed = <T as Config>::Balance,
OriginRenamed = <T as system::Config>::Origin
{
TestEvent(BalanceRenamed),
TestOrigin(OriginRenamed),
@@ -645,19 +645,19 @@ mod tests {
mod event_module4 {
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
decl_event!(
/// Event finish formatting on an unnamed one with trailing comma
pub enum Event<T> where
<T as Trait>::Balance,
<T as system::Trait>::Origin,
<T as Config>::Balance,
<T as system::Config>::Origin,
{
TestEvent(Balance, Origin),
}
@@ -667,19 +667,19 @@ mod tests {
mod event_module5 {
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
decl_event!(
/// Event finish formatting on an named one with trailing comma
pub enum Event<T> where
BalanceRenamed = <T as Trait>::Balance,
OriginRenamed = <T as system::Trait>::Origin,
BalanceRenamed = <T as Config>::Balance,
OriginRenamed = <T as system::Config>::Origin,
{
TestEvent(BalanceRenamed, OriginRenamed),
TrailingCommaInArgs(
@@ -714,37 +714,37 @@ mod tests {
}
}
impl event_module::Trait for TestRuntime {
impl event_module::Config for TestRuntime {
type Balance = u32;
}
impl event_module2::Trait for TestRuntime {
impl event_module2::Config for TestRuntime {
type Balance = u32;
}
impl system::Trait for TestRuntime {
impl system::Config for TestRuntime {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl event_module::Trait for TestRuntime2 {
impl event_module::Config for TestRuntime2 {
type Balance = u32;
}
impl event_module2::Trait for TestRuntime2 {
impl event_module2::Config for TestRuntime2 {
type Balance = u32;
}
impl system_renamed::Trait for TestRuntime2 {
impl system_renamed::Config for TestRuntime2 {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type DbWeight = ();
}
impl system::Trait for TestRuntime2 {
impl system::Config for TestRuntime2 {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
+13 -13
View File
@@ -346,14 +346,14 @@ pub use frame_support_procedural::{
/// This is useful for type generic over runtime:
/// ```
/// # use frame_support::CloneNoBound;
/// trait Trait {
/// trait Config {
/// type C: Clone;
/// }
///
/// // Foo implements [`Clone`] because `C` bounds [`Clone`].
/// // Otherwise compilation will fail with an output telling `c` doesn't implement [`Clone`].
/// #[derive(CloneNoBound)]
/// struct Foo<T: Trait> {
/// struct Foo<T: Config> {
/// c: T::C,
/// }
/// ```
@@ -364,14 +364,14 @@ pub use frame_support_procedural::CloneNoBound;
/// This is useful for type generic over runtime:
/// ```
/// # use frame_support::{EqNoBound, PartialEqNoBound};
/// trait Trait {
/// trait Config {
/// type C: Eq;
/// }
///
/// // Foo implements [`Eq`] because `C` bounds [`Eq`].
/// // Otherwise compilation will fail with an output telling `c` doesn't implement [`Eq`].
/// #[derive(PartialEqNoBound, EqNoBound)]
/// struct Foo<T: Trait> {
/// struct Foo<T: Config> {
/// c: T::C,
/// }
/// ```
@@ -382,14 +382,14 @@ pub use frame_support_procedural::EqNoBound;
/// This is useful for type generic over runtime:
/// ```
/// # use frame_support::PartialEqNoBound;
/// trait Trait {
/// trait Config {
/// type C: PartialEq;
/// }
///
/// // Foo implements [`PartialEq`] because `C` bounds [`PartialEq`].
/// // Otherwise compilation will fail with an output telling `c` doesn't implement [`PartialEq`].
/// #[derive(PartialEqNoBound)]
/// struct Foo<T: Trait> {
/// struct Foo<T: Config> {
/// c: T::C,
/// }
/// ```
@@ -401,14 +401,14 @@ pub use frame_support_procedural::PartialEqNoBound;
/// ```
/// # use frame_support::DebugNoBound;
/// # use core::fmt::Debug;
/// trait Trait {
/// trait Config {
/// type C: Debug;
/// }
///
/// // Foo implements [`Debug`] because `C` bounds [`Debug`].
/// // Otherwise compilation will fail with an output telling `c` doesn't implement [`Debug`].
/// #[derive(DebugNoBound)]
/// struct Foo<T: Trait> {
/// struct Foo<T: Config> {
/// c: T::C,
/// }
/// ```
@@ -565,7 +565,7 @@ mod tests {
use sp_std::{marker::PhantomData, result};
use sp_io::TestExternalities;
pub trait Trait: 'static {
pub trait Config: 'static {
type BlockNumber: Codec + EncodeLike + Default;
type Origin;
type PalletInfo: crate::traits::PalletInfo;
@@ -575,16 +575,16 @@ mod tests {
mod module {
#![allow(dead_code)]
use super::Trait;
use super::Config;
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
}
use self::module::Module;
decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
pub Data get(fn data) build(|_| vec![(15u32, 42u64)]):
map hasher(twox_64_concat) u32 => u64;
pub OptionLinkedMap: map hasher(blake2_128_concat) u32 => Option<u32>;
@@ -606,7 +606,7 @@ mod tests {
}
struct Test;
impl Trait for Test {
impl Config for Test {
type BlockNumber = u32;
type Origin = u32;
type PalletInfo = ();
+19 -19
View File
@@ -27,23 +27,23 @@ pub use frame_metadata::{
/// Example:
/// ```
///# mod module0 {
///# pub trait Trait: 'static {
///# pub trait Config: 'static {
///# type Origin;
///# type BlockNumber;
///# type PalletInfo: frame_support::traits::PalletInfo;
///# type DbWeight: frame_support::traits::Get<frame_support::weights::RuntimeDbWeight>;
///# }
///# frame_support::decl_module! {
///# pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
///# pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
///# }
///#
///# frame_support::decl_storage! {
///# trait Store for Module<T: Trait> as TestStorage {}
///# trait Store for Module<T: Config> as TestStorage {}
///# }
///# }
///# use module0 as module1;
///# use module0 as module2;
///# impl module0::Trait for Runtime {
///# impl module0::Config for Runtime {
///# type Origin = u32;
///# type BlockNumber = u32;
///# type PalletInfo = ();
@@ -297,7 +297,7 @@ mod tests {
mod system {
use super::*;
pub trait Trait: 'static {
pub trait Config: 'static {
type BaseCallFilter;
const ASSOCIATED_CONST: u64 = 500;
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
@@ -311,7 +311,7 @@ mod tests {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
/// Hi, I am a comment.
const BlockNumber: T::BlockNumber = 100.into();
const GetType: T::AccountId = T::SomeValue::get().into();
@@ -341,19 +341,19 @@ mod tests {
}
}
pub type Origin<T> = RawOrigin<<T as Trait>::AccountId>;
pub type Origin<T> = RawOrigin<<T as Config>::AccountId>;
}
mod event_module {
use crate::dispatch::DispatchResult;
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_event!(
pub enum Event<T> where <T as Trait>::Balance
pub enum Event<T> where <T as Config>::Balance
{
/// Hi, I am a comment.
TestEvent(Balance),
@@ -361,7 +361,7 @@ mod tests {
);
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {
type Error = Error<T>;
#[weight = 0]
@@ -370,7 +370,7 @@ mod tests {
}
crate::decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Some user input error
UserInputError,
/// Something bad happened
@@ -383,23 +383,23 @@ mod tests {
mod event_module2 {
use super::system;
pub trait Trait: system::Trait {
pub trait Config: system::Config {
type Balance;
}
decl_event!(
pub enum Event<T> where <T as Trait>::Balance
pub enum Event<T> where <T as Config>::Balance
{
TestEvent(Balance),
}
);
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
}
crate::decl_storage! {
trait Store for Module<T: Trait> as TestStorage {
trait Store for Module<T: Config> as TestStorage {
StorageMethod : Option<u32>;
}
add_extra_genesis {
@@ -433,11 +433,11 @@ mod tests {
}
}
impl event_module::Trait for TestRuntime {
impl event_module::Config for TestRuntime {
type Balance = u32;
}
impl event_module2::Trait for TestRuntime {
impl event_module2::Config for TestRuntime {
type Balance = u32;
}
@@ -445,7 +445,7 @@ mod tests {
pub const SystemValue: u32 = 600;
}
impl system::Trait for TestRuntime {
impl system::Config for TestRuntime {
type BaseCallFilter = ();
type Origin = Origin;
type AccountId = u32;
@@ -480,7 +480,7 @@ mod tests {
struct ConstantAssociatedConstByteGetter;
impl DefaultByte for ConstantAssociatedConstByteGetter {
fn default_byte(&self) -> Vec<u8> {
<TestRuntime as system::Trait>::ASSOCIATED_CONST.encode()
<TestRuntime as system::Config>::ASSOCIATED_CONST.encode()
}
}
+20 -20
View File
@@ -181,12 +181,12 @@ macro_rules! impl_outer_origin {
index { $( $index:tt )? },
)*
) => {
// WARNING: All instance must hold the filter `frame_system::Trait::BaseCallFilter`, except
// WARNING: All instance must hold the filter `frame_system::Config::BaseCallFilter`, except
// when caller is system Root. One can use `OriginTrait::reset_filter` to do so.
#[derive(Clone)]
pub struct $name {
caller: $caller_name,
filter: $crate::sp_std::rc::Rc<Box<dyn Fn(&<$runtime as $system::Trait>::Call) -> bool>>,
filter: $crate::sp_std::rc::Rc<Box<dyn Fn(&<$runtime as $system::Config>::Call) -> bool>>,
}
#[cfg(not(feature = "std"))]
@@ -213,9 +213,9 @@ macro_rules! impl_outer_origin {
}
impl $crate::traits::OriginTrait for $name {
type Call = <$runtime as $system::Trait>::Call;
type Call = <$runtime as $system::Config>::Call;
type PalletsOrigin = $caller_name;
type AccountId = <$runtime as $system::Trait>::AccountId;
type AccountId = <$runtime as $system::Config>::AccountId;
fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static) {
let f = self.filter.clone();
@@ -227,8 +227,8 @@ macro_rules! impl_outer_origin {
fn reset_filter(&mut self) {
let filter = <
<$runtime as $system::Trait>::BaseCallFilter
as $crate::traits::Filter<<$runtime as $system::Trait>::Call>
<$runtime as $system::Config>::BaseCallFilter
as $crate::traits::Filter<<$runtime as $system::Config>::Call>
>::filter;
self.filter = $crate::sp_std::rc::Rc::new(Box::new(filter));
@@ -246,7 +246,7 @@ macro_rules! impl_outer_origin {
&self.caller
}
/// Create with system none origin and `frame-system::Trait::BaseCallFilter`.
/// Create with system none origin and `frame-system::Config::BaseCallFilter`.
fn none() -> Self {
$system::RawOrigin::None.into()
}
@@ -254,8 +254,8 @@ macro_rules! impl_outer_origin {
fn root() -> Self {
$system::RawOrigin::Root.into()
}
/// Create with system signed origin and `frame-system::Trait::BaseCallFilter`.
fn signed(by: <$runtime as $system::Trait>::AccountId) -> Self {
/// Create with system signed origin and `frame-system::Config::BaseCallFilter`.
fn signed(by: <$runtime as $system::Config>::AccountId) -> Self {
$system::RawOrigin::Signed(by).into()
}
}
@@ -280,7 +280,7 @@ macro_rules! impl_outer_origin {
// For backwards compatibility and ease of accessing these functions.
#[allow(dead_code)]
impl $name {
/// Create with system none origin and `frame-system::Trait::BaseCallFilter`.
/// Create with system none origin and `frame-system::Config::BaseCallFilter`.
pub fn none() -> Self {
<$name as $crate::traits::OriginTrait>::none()
}
@@ -288,8 +288,8 @@ macro_rules! impl_outer_origin {
pub fn root() -> Self {
<$name as $crate::traits::OriginTrait>::root()
}
/// Create with system signed origin and `frame-system::Trait::BaseCallFilter`.
pub fn signed(by: <$runtime as $system::Trait>::AccountId) -> Self {
/// Create with system signed origin and `frame-system::Config::BaseCallFilter`.
pub fn signed(by: <$runtime as $system::Config>::AccountId) -> Self {
<$name as $crate::traits::OriginTrait>::signed(by)
}
}
@@ -302,7 +302,7 @@ macro_rules! impl_outer_origin {
impl From<$system::Origin<$runtime>> for $name {
/// Convert to runtime origin:
/// * root origin is built with no filter
/// * others use `frame-system::Trait::BaseCallFilter`
/// * others use `frame-system::Config::BaseCallFilter`
fn from(x: $system::Origin<$runtime>) -> Self {
let o: $caller_name = x.into();
o.into()
@@ -335,10 +335,10 @@ macro_rules! impl_outer_origin {
}
}
}
impl From<Option<<$runtime as $system::Trait>::AccountId>> for $name {
impl From<Option<<$runtime as $system::Config>::AccountId>> for $name {
/// Convert to runtime origin with caller being system signed or none and use filter
/// `frame-system::Trait::BaseCallFilter`.
fn from(x: Option<<$runtime as $system::Trait>::AccountId>) -> Self {
/// `frame-system::Config::BaseCallFilter`.
fn from(x: Option<<$runtime as $system::Config>::AccountId>) -> Self {
<$system::Origin<$runtime>>::from(x).into()
}
}
@@ -352,7 +352,7 @@ macro_rules! impl_outer_origin {
}
impl From<$module::Origin < $( $generic )? $(, $module::$generic_instance )? > > for $name {
/// Convert to runtime origin using `frame-system::Trait::BaseCallFilter`.
/// Convert to runtime origin using `frame-system::Config::BaseCallFilter`.
fn from(x: $module::Origin < $( $generic )? $(, $module::$generic_instance )? >) -> Self {
let x: $caller_name = x.into();
x.into()
@@ -388,7 +388,7 @@ mod tests {
mod frame_system {
use super::*;
pub trait Trait {
pub trait Config {
type AccountId;
type Call;
type BaseCallFilter;
@@ -410,7 +410,7 @@ mod tests {
}
}
pub type Origin<T> = RawOrigin<<T as Trait>::AccountId>;
pub type Origin<T> = RawOrigin<<T as Config>::AccountId>;
}
mod origin_without_generic {
@@ -439,7 +439,7 @@ mod tests {
}
}
impl frame_system::Trait for TestRuntime {
impl frame_system::Config for TestRuntime {
type AccountId = u32;
type Call = u32;
type BaseCallFilter = BaseCallFilter;
@@ -425,7 +425,7 @@ mod test_iterators {
storage::{generator::StorageDoubleMap, IterableStorageDoubleMap, unhashed},
};
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
@@ -433,14 +433,14 @@ mod test_iterators {
}
crate::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
struct NoDef(u32);
crate::decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
DoubleMap: double_map hasher(blake2_128_concat) u16, hasher(twox_64_concat) u32 => u64;
}
}
@@ -325,7 +325,7 @@ mod test_iterators {
storage::{generator::StorageMap, IterableStorageMap, unhashed},
};
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
@@ -333,14 +333,14 @@ mod test_iterators {
}
crate::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
struct NoDef(u32);
crate::decl_storage! {
trait Store for Module<T: Trait> as Test {
trait Store for Module<T: Config> as Test {
Map: map hasher(blake2_128_concat) u16 => u64;
}
}
@@ -42,14 +42,14 @@ mod tests {
struct Runtime;
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
impl Trait for Runtime {
impl Config for Runtime {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
@@ -57,11 +57,11 @@ mod tests {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
}
crate::decl_storage! {
trait Store for Module<T: Trait> as Runtime {
trait Store for Module<T: Config> as Runtime {
Value get(fn value) config(): (u64, u64);
NumberMap: map hasher(identity) u32 => u64;
DoubleMap: double_map hasher(identity) u32, hasher(identity) u32 => u64;
+6 -6
View File
@@ -1653,16 +1653,16 @@ pub trait EnsureOrigin<OuterOrigin> {
/// Implemented for pallet dispatchable type by `decl_module` and for runtime dispatchable by
/// `construct_runtime` and `impl_outer_dispatch`.
pub trait UnfilteredDispatchable {
/// The origin type of the runtime, (i.e. `frame_system::Trait::Origin`).
/// The origin type of the runtime, (i.e. `frame_system::Config::Origin`).
type Origin;
/// Dispatch this call but do not check the filter in origin.
fn dispatch_bypass_filter(self, origin: Self::Origin) -> crate::dispatch::DispatchResultWithPostInfo;
}
/// Methods available on `frame_system::Trait::Origin`.
/// Methods available on `frame_system::Config::Origin`.
pub trait OriginTrait: Sized {
/// Runtime call type, as in `frame_system::Trait::Call`
/// Runtime call type, as in `frame_system::Config::Call`
type Call;
/// The caller origin, overarching type of all pallets origins.
@@ -1674,7 +1674,7 @@ pub trait OriginTrait: Sized {
/// Add a filter to the origin.
fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static);
/// Reset origin filters to default one, i.e `frame_system::Trait::BaseCallFilter`.
/// Reset origin filters to default one, i.e `frame_system::Config::BaseCallFilter`.
fn reset_filter(&mut self);
/// Replace the caller with caller from the other origin
@@ -1686,13 +1686,13 @@ pub trait OriginTrait: Sized {
/// Get the caller.
fn caller(&self) -> &Self::PalletsOrigin;
/// Create with system none origin and `frame-system::Trait::BaseCallFilter`.
/// Create with system none origin and `frame-system::Config::BaseCallFilter`.
fn none() -> Self;
/// Create with system root origin and no filter.
fn root() -> Self;
/// Create with system signed origin and `frame-system::Trait::BaseCallFilter`.
/// Create with system signed origin and `frame-system::Config::BaseCallFilter`.
fn signed(by: Self::AccountId) -> Self;
}
+13 -13
View File
@@ -39,9 +39,9 @@
//! `Yes`**.
//!
//! ```
//! # use frame_system::Trait;
//! # use 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 = 1000]
//! fn dispatching(origin) { unimplemented!() }
//! }
@@ -52,10 +52,10 @@
//! 2.1 Define weight and class, **in which case `PaysFee` would be `Yes`**.
//!
//! ```
//! # use frame_system::Trait;
//! # use frame_system::Config;
//! # use frame_support::weights::DispatchClass;
//! 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 = (1000, DispatchClass::Operational)]
//! fn dispatching(origin) { unimplemented!() }
//! }
@@ -66,10 +66,10 @@
//! 2.2 Define weight and `PaysFee`, **in which case `ClassifyDispatch` would be `Normal`**.
//!
//! ```
//! # use frame_system::Trait;
//! # use frame_system::Config;
//! # use frame_support::weights::Pays;
//! 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 = (1000, Pays::No)]
//! fn dispatching(origin) { unimplemented!() }
//! }
@@ -80,10 +80,10 @@
//! 3. Define all 3 parameters.
//!
//! ```
//! # use frame_system::Trait;
//! # use frame_system::Config;
//! # use frame_support::weights::{DispatchClass, Pays};
//! 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 = (1000, DispatchClass::Operational, Pays::No)]
//! fn dispatching(origin) { unimplemented!() }
//! }
@@ -100,10 +100,10 @@
//! all 3 are static values, providing a raw tuple is easier.
//!
//! ```
//! # use frame_system::Trait;
//! # use frame_system::Config;
//! # use frame_support::weights::{DispatchClass, FunctionOf, Pays};
//! 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 = FunctionOf(
//! // weight, function.
//! |args: (&u32, &u64)| *args.0 as u64 + args.1,
@@ -701,7 +701,7 @@ mod tests {
use crate::{decl_module, parameter_types, traits::Get};
use super::*;
pub trait Trait: 'static {
pub trait Config: 'static {
type Origin;
type Balance;
type BlockNumber;
@@ -718,7 +718,7 @@ mod tests {
};
}
impl Trait for TraitImpl {
impl Config for TraitImpl {
type Origin = u32;
type BlockNumber = u32;
type Balance = u32;
@@ -727,7 +727,7 @@ mod tests {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
// no arguments, fixed weight
#[weight = 1000]
fn f00(_origin) { unimplemented!(); }