Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,28 +1265,30 @@ macro_rules! decl_module {
};

(@impl_on_initialize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn on_initialize() -> $return:ty { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) -> $return {
fn on_initialize(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) -> $return {
$crate::sp_tracing::enter_span!("on_initialize");
{ $( $impl )* }
}
}
};

(@impl_on_initialize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn on_initialize($param:ident : $param_ty:ty) -> $return:ty { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize($param: $param_ty) -> $return {
Expand All @@ -1297,11 +1299,12 @@ macro_rules! decl_module {
};

(@impl_on_initialize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnInitialize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
Expand Down Expand Up @@ -1362,28 +1365,30 @@ macro_rules! decl_module {
};

(@impl_on_finalize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn on_finalize() { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) {
fn on_finalize(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) {
$crate::sp_tracing::enter_span!("on_finalize");
{ $( $impl )* }
}
}
};

(@impl_on_finalize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn on_finalize($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize($param: $param_ty) {
Expand All @@ -1394,48 +1399,52 @@ macro_rules! decl_module {
};

(@impl_on_finalize
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OnFinalize<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
}
};

(@impl_offchain
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn offchain_worker() { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn offchain_worker(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
fn offchain_worker(_block_number_not_used: <$trait_instance as $system::Trait>::BlockNumber) { $( $impl )* }
}
};

(@impl_offchain
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn offchain_worker($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn offchain_worker($param: $param_ty) { $( $impl )* }
}
};

(@impl_offchain
{ $system:ident }
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<$trait_instance::BlockNumber>
impl<$trait_instance: $system::Trait + $trait_name$(<I>, $instance: $instantiable)?>
$crate::traits::OffchainWorker<<$trait_instance as $system::Trait>::BlockNumber>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
Expand Down Expand Up @@ -1635,6 +1644,7 @@ macro_rules! decl_module {

$crate::decl_module! {
@impl_on_initialize
{ $system }
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $on_initialize )*
Expand All @@ -1649,13 +1659,15 @@ macro_rules! decl_module {

$crate::decl_module! {
@impl_on_finalize
{ $system }
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $on_finalize )*
}

$crate::decl_module! {
@impl_offchain
{ $system }
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $offchain )*
Expand Down Expand Up @@ -2345,9 +2357,7 @@ mod tests {
IntegrityTest,
};

pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> {
type BlockNumber: Into<u32>;
}
pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> { }

pub mod system {
use codec::{Encode, Decode};
Expand All @@ -2357,6 +2367,7 @@ mod tests {
type Call;
type BaseCallFilter;
type Origin: crate::traits::OriginTrait<Call = Self::Call>;
type BlockNumber: Into<u32>;
}

#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
Expand Down Expand Up @@ -2480,10 +2491,7 @@ mod tests {
];

pub struct TraitImpl {}

impl Trait for TraitImpl {
type BlockNumber = u32;
}
impl Trait for TraitImpl { }

type Test = Module<TraitImpl>;

Expand All @@ -2502,6 +2510,7 @@ mod tests {
type AccountId = u32;
type Call = OuterCall;
type BaseCallFilter = ();
type BlockNumber = u32;
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ pub trait Trait {

frame_support::decl_module! {
/// Some test module
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}
4 changes: 2 additions & 2 deletions frame/support/test/tests/construct_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod module1 {

frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call
where origin: <T as system::Trait>::Origin
where origin: <T as system::Trait>::Origin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Expand All @@ -67,7 +67,7 @@ mod module2 {

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call
where origin: <T as system::Trait>::Origin
where origin: <T as system::Trait>::Origin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
fn integrity_test() {}

fn integrity_test() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: `integrity_test` can only be passed once as input.
--> $DIR/reserved_keyword_two_times_integrity_test.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
3 | | fn integrity_test() {}
4 | |
5 | | fn integrity_test() {}
Expand All @@ -16,7 +16,7 @@ error[E0601]: `main` function not found in crate `$CRATE`
--> $DIR/reserved_keyword_two_times_integrity_test.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
3 | | fn integrity_test() {}
4 | |
5 | | fn integrity_test() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
fn on_initialize() -> Weight {
0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: `on_initialize` can only be passed once as input.
--> $DIR/reserved_keyword_two_times_on_initialize.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
3 | | fn on_initialize() -> Weight {
4 | | 0
... |
Expand All @@ -16,7 +16,7 @@ error[E0601]: `main` function not found in crate `$CRATE`
--> $DIR/reserved_keyword_two_times_on_initialize.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin {
2 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {
3 | | fn on_initialize() -> Weight {
4 | | 0
... |
Expand Down
8 changes: 4 additions & 4 deletions frame/support/test/tests/decl_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod tests {
use codec::{Encode, Decode, EncodeLike};

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

pub trait Trait {
Expand Down Expand Up @@ -420,7 +420,7 @@ mod test2 {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

type PairOf<T> = (T, T);
Expand Down Expand Up @@ -455,7 +455,7 @@ mod test3 {
type BlockNumber;
}
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}
frame_support::decl_storage! {
trait Store for Module<T: Trait> as Test {
Expand Down Expand Up @@ -485,7 +485,7 @@ mod test_append_and_len {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Trait {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

frame_support::decl_storage!{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Trait {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

frame_support::decl_storage!{
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/decl_storage_ui/get_duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Trait {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

frame_support::decl_storage!{
Expand Down
6 changes: 4 additions & 2 deletions frame/support/test/tests/final_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod no_instance {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

frame_support::decl_storage!{
Expand All @@ -50,11 +50,13 @@ mod no_instance {
}

mod instance {
use super::no_instance;

pub trait Trait<I = DefaultInstance>: super::no_instance::Trait {}

frame_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance>
for enum Call where origin: T::Origin {}
for enum Call where origin: T::Origin, system=no_instance {}
}

frame_support::decl_storage!{
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/genesisconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Trait {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}

frame_support::decl_storage! {
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mod module3 {
}

frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {}
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin, system=system {}
}
}

Expand Down
Loading