mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 22:07:58 +00:00
Implement parameterisable modules (#1800)
* first implementation
* remove done comment
* origin done
* impl log for instance
* impl inherent for instance
* Fix wasm build + full example build
this requires parity codec implements codec for core::marker::PhantomData
* patch parity-codec link to github branch
* improve internal names and fix instance prefix
* Fix in macros
* add test modules for support
this allow to test for construct_runtime as well.
The reason to have put that in another crate is:
* if we put test in `tests/` dir of srml/support then decl_storage fails to get
srml-support access because it believes it is inside srml-support
crate and so derive access to `quote!{ crate }` but this is wrong
(and I don't see any way to prevent that, and it only bother us so I
don't think that matters that much)
* if we put test inside lib.rs then contruct_runtime cannot be used
because it call some macros that are defined with macros
(decl_outer_event and decl_outer_origin) and thus rustc complains.
* defaultinstance to its own struct to avoid errors
* enforce <T, I> for Event and Config, impl test
* add origin, log, inherent to test
* test more code generation
* basic storage test
* fix typo
* rename a few imports and field
* delete wip test in example and runtime
* change default prefix to make it backward compatible with test
* rename Instance to I and Instantiable to Instance
note: the name of generic parameter I is only enforce by decl_module!
and this could be rewritten
* doc
* clean old TODOs
* update parity-codec to 3.2
* update node impl version + builds
* fix warning
* fix unrelated grandpa test
* refactor code
This commit is contained in:
@@ -91,20 +91,28 @@ impl<T> Parameter for T where T: Codec + Clone + Eq {}
|
||||
///
|
||||
/// The `on_initialise` and `on_finalise` functions are special, since it can either take no
|
||||
/// parameters, or one parameter, which has the runtime's block number type.
|
||||
///
|
||||
/// ### Module with instances
|
||||
///
|
||||
/// decl_module! support modules with instances with the following syntax: (DefaultInstance type is
|
||||
/// optionnal)
|
||||
/// ```nocompile
|
||||
/// pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {}
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! decl_module {
|
||||
// Macro transformations (to convert invocations with incomplete parameters to the canonical
|
||||
// form)
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty {
|
||||
$($t:tt)*
|
||||
}
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = system
|
||||
{}
|
||||
{}
|
||||
@@ -115,14 +123,14 @@ macro_rules! decl_module {
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident {
|
||||
$($t:tt)*
|
||||
}
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{}
|
||||
{}
|
||||
@@ -134,21 +142,21 @@ macro_rules! decl_module {
|
||||
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{}
|
||||
{ $( $on_initialise:tt )* }
|
||||
{ $( $on_finalise:tt )* }
|
||||
[ $($t:tt)* ]
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident>)* () = default;
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* () = default;
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $vis fn deposit_event $(<$dpeg>)* () = default; }
|
||||
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* () = default; }
|
||||
{ $( $on_initialise )* }
|
||||
{ $( $on_finalise )* }
|
||||
[ $($t)* ]
|
||||
@@ -157,23 +165,23 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{}
|
||||
{ $( $on_initialise:tt )* }
|
||||
{ $( $on_finalise:tt )* }
|
||||
[ $($t:tt)* ]
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident>)* (
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* (
|
||||
$($param_name:ident : $param:ty),*
|
||||
) { $( $impl:tt )* }
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $vis fn deposit_event $(<$dpeg>)* ($( $param_name: $param ),* ) { $( $impl )* } }
|
||||
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* ($( $param_name: $param ),* ) { $( $impl )* } }
|
||||
{ $( $on_initialise )* }
|
||||
{ $( $on_finalise )* }
|
||||
[ $($t)* ]
|
||||
@@ -182,7 +190,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -194,7 +202,7 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $deposit_event )* }
|
||||
{ $( $on_initialise )* }
|
||||
@@ -205,7 +213,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{}
|
||||
@@ -217,7 +225,7 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $deposit_event )* }
|
||||
{ fn on_initialise( $( $param_name : $param ),* ) { $( $impl )* } }
|
||||
@@ -228,7 +236,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -242,7 +250,7 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $deposit_event )* }
|
||||
{ $( $on_initialise )* }
|
||||
@@ -253,13 +261,14 @@ macro_rules! decl_module {
|
||||
$fn_vis fn $fn_name(
|
||||
$origin $( , $(#[$codec_attr])* $param_name : $param )*
|
||||
) $( -> $result )* { $( $impl )* }
|
||||
{ $($instance: $instantiable)? }
|
||||
]
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -279,7 +288,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -299,7 +308,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -313,7 +322,7 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $deposit_event )* }
|
||||
{ $( $on_initialise )* }
|
||||
@@ -324,13 +333,14 @@ macro_rules! decl_module {
|
||||
$fn_vis fn $fn_name(
|
||||
root $( , $(#[$codec_attr])* $param_name : $param )*
|
||||
) $( -> $result )* { $( $impl )* }
|
||||
{ $($instance: $instantiable)? }
|
||||
]
|
||||
$($rest)*
|
||||
);
|
||||
};
|
||||
(@normalize
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
|
||||
{ $( $deposit_event:tt )* }
|
||||
{ $( $on_initialise:tt )* }
|
||||
@@ -339,7 +349,7 @@ macro_rules! decl_module {
|
||||
) => {
|
||||
decl_module!(@imp
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name>
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system {
|
||||
$($t)*
|
||||
}
|
||||
@@ -354,62 +364,46 @@ macro_rules! decl_module {
|
||||
|
||||
(@call
|
||||
root
|
||||
$mod_type:ident $trait_instance:ident $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ]
|
||||
$mod_type:ident<$trait_instance:ident $(, $instance:ident)?> $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ]
|
||||
) => {
|
||||
{
|
||||
$system::ensure_root($origin)?;
|
||||
<$mod_type<$trait_instance>>::$fn_name( $( $param_name ),* )
|
||||
<$mod_type<$trait_instance $(, $instance)?>>::$fn_name( $( $param_name ),* )
|
||||
}
|
||||
};
|
||||
(@call
|
||||
$ingore:ident
|
||||
$mod_type:ident $trait_instance:ident $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ]
|
||||
$mod_type:ident<$trait_instance:ident $(, $instance:ident)?> $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ]
|
||||
) => {
|
||||
<$mod_type<$trait_instance>>::$fn_name( $origin $(, $param_name )* )
|
||||
<$mod_type<$trait_instance $(, $instance)?>>::$fn_name( $origin $(, $param_name )* )
|
||||
};
|
||||
|
||||
// no `deposit_event` function wanted
|
||||
(@impl_deposit_event
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path)?>;
|
||||
$system:ident;
|
||||
) => {};
|
||||
|
||||
// Non-generic event
|
||||
(@impl_deposit_event
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$system:ident;
|
||||
$vis:vis fn deposit_event() = default;
|
||||
$vis:vis fn deposit_event$(<$event_trait_instance:ident $(, $event_instance:ident)?>)?() = default;
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
$vis fn deposit_event(event: Event) {
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> {
|
||||
$vis fn deposit_event(event: Event$(<$event_trait_instance $(, $event_instance)?>)?) {
|
||||
<$system::Module<$trait_instance>>::deposit_event(
|
||||
<$trait_instance as $trait_name>::Event::from(event).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Generic event
|
||||
(@impl_deposit_event
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$system:ident;
|
||||
$vis:vis fn deposit_event<$ignore:ident>() = default;
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
$vis fn deposit_event(event: Event<$trait_instance>) {
|
||||
<$system::Module<$trait_instance>>::deposit_event(
|
||||
<$trait_instance as $trait_name>::Event::from(event).into()
|
||||
<$trait_instance as $trait_name$(<$instance>)?>::Event::from(event).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_deposit_event
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$system:ident;
|
||||
$vis:vis fn deposit_event($param:ident : $param_ty:ty) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> {
|
||||
$vis fn deposit_event($param: $param_ty) {
|
||||
$( $impl )*
|
||||
}
|
||||
@@ -417,74 +411,74 @@ macro_rules! decl_module {
|
||||
};
|
||||
|
||||
(@impl_on_initialise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
fn on_initialise() { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{
|
||||
fn on_initialise(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_on_initialise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
fn on_initialise($param:ident : $param_ty:ty) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{
|
||||
fn on_initialise($param: $param_ty) { $( $impl )* }
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_on_initialise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{}
|
||||
};
|
||||
|
||||
(@impl_on_finalise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
fn on_finalise() { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{
|
||||
fn on_finalise(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_on_finalise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
fn on_finalise($param:ident : $param_ty:ty) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{
|
||||
fn on_finalise($param: $param_ty) { $( $impl )* }
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_on_finalise
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name>
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
|
||||
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
|
||||
for $module<$trait_instance>
|
||||
for $module<$trait_instance$(, $instance)?>
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
root;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -498,7 +492,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
root;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -513,7 +507,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
$ignore:ident;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -531,7 +525,7 @@ macro_rules! decl_module {
|
||||
};
|
||||
|
||||
(@impl_function
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$origin_ty:ty;
|
||||
$ignore:ident;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -549,13 +543,14 @@ macro_rules! decl_module {
|
||||
|
||||
(@imp
|
||||
$(#[$attr:meta])*
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
|
||||
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
|
||||
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident {
|
||||
$(
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$fn_vis:vis fn $fn_name:ident(
|
||||
$from:ident $( , $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
|
||||
) $( -> $result:ty )* { $( $impl:tt )* }
|
||||
{ $($fn_instance:ident: $fn_instantiable:path)? }
|
||||
)*
|
||||
}
|
||||
{ $( $deposit_event:tt )* }
|
||||
@@ -569,29 +564,29 @@ macro_rules! decl_module {
|
||||
// serde-derive for when we attempt to derive `Deserialize` on these types,
|
||||
// in a situation where we've imported `srml_support` as another name.
|
||||
#[cfg(feature = "std")]
|
||||
pub struct $mod_type<$trait_instance: $trait_name>(::std::marker::PhantomData<$trait_instance>);
|
||||
pub struct $mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable $( = $module_default_instance)?)?>(::std::marker::PhantomData<($trait_instance $(, $instance)?)>);
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub struct $mod_type<$trait_instance: $trait_name>(::core::marker::PhantomData<$trait_instance>);
|
||||
pub struct $mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable $( = $module_default_instance)?)?>(::core::marker::PhantomData<($trait_instance $(, $instance)?)>);
|
||||
|
||||
decl_module! {
|
||||
@impl_on_initialise
|
||||
$mod_type<$trait_instance: $trait_name>;
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
|
||||
$( $on_initialise )*
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@impl_on_finalise
|
||||
$mod_type<$trait_instance: $trait_name>;
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
|
||||
$( $on_finalise )*
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@impl_deposit_event
|
||||
$mod_type<$trait_instance: $trait_name>;
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
|
||||
$system;
|
||||
$( $deposit_event )*
|
||||
}
|
||||
@@ -599,11 +594,11 @@ macro_rules! decl_module {
|
||||
/// Can also be called using [`Call`].
|
||||
///
|
||||
/// [`Call`]: enum.Call.html
|
||||
impl<$trait_instance: $trait_name> $mod_type<$trait_instance> {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
|
||||
$(
|
||||
decl_module! {
|
||||
@impl_function
|
||||
$mod_type<$trait_instance: $trait_name>;
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $fn_instance: $fn_instantiable)?>;
|
||||
$origin_type;
|
||||
$from;
|
||||
$(#[doc = $doc_attr])*
|
||||
@@ -616,9 +611,9 @@ macro_rules! decl_module {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
$(#[$attr])*
|
||||
pub enum $call_type<$trait_instance: $trait_name> {
|
||||
pub enum $call_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $( = $module_default_instance)?)?> {
|
||||
#[doc(hidden)]
|
||||
__PhantomItem(::std::marker::PhantomData<$trait_instance>, $crate::dispatch::Never),
|
||||
__PhantomItem(::std::marker::PhantomData<($trait_instance $(, $instance)?)>, $crate::dispatch::Never),
|
||||
$(
|
||||
#[allow(non_camel_case_types)]
|
||||
$(#[doc = $doc_attr])*
|
||||
@@ -628,9 +623,9 @@ macro_rules! decl_module {
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
$(#[$attr])*
|
||||
pub enum $call_type<$trait_instance: $trait_name> {
|
||||
pub enum $call_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $( = $module_default_instance)?)?> {
|
||||
#[doc(hidden)]
|
||||
__PhantomItem(::core::marker::PhantomData<$trait_instance>, $crate::dispatch::Never),
|
||||
__PhantomItem(::core::marker::PhantomData<($trait_instance $(, $instance)?)>, $crate::dispatch::Never),
|
||||
$(
|
||||
#[allow(non_camel_case_types)]
|
||||
$(#[doc = $doc_attr])*
|
||||
@@ -640,8 +635,8 @@ macro_rules! decl_module {
|
||||
|
||||
// manual implementation of clone/eq/partialeq because using derive erroneously requires
|
||||
// clone/eq/partialeq from T.
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Clone
|
||||
for $call_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Clone
|
||||
for $call_type<$trait_instance $(, $instance)?>
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
match *self {
|
||||
@@ -653,8 +648,8 @@ macro_rules! decl_module {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::PartialEq
|
||||
for $call_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::PartialEq
|
||||
for $call_type<$trait_instance $(, $instance)?>
|
||||
{
|
||||
fn eq(&self, _other: &Self) -> bool {
|
||||
match *self {
|
||||
@@ -675,13 +670,13 @@ macro_rules! decl_module {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Eq
|
||||
for $call_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Eq
|
||||
for $call_type<$trait_instance $(, $instance)?>
|
||||
{}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::fmt::Debug
|
||||
for $call_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::fmt::Debug
|
||||
for $call_type<$trait_instance $(, $instance)?>
|
||||
{
|
||||
fn fmt(&self, _f: &mut $crate::dispatch::fmt::Formatter) -> $crate::dispatch::result::Result<(), $crate::dispatch::fmt::Error> {
|
||||
match *self {
|
||||
@@ -697,20 +692,20 @@ macro_rules! decl_module {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Decode for $call_type<$trait_instance> {
|
||||
fn decode<I: $crate::dispatch::Input>(input: &mut I) -> Option<Self> {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Decode for $call_type<$trait_instance $(, $instance)?> {
|
||||
fn decode<Input: $crate::dispatch::Input>(input: &mut Input) -> Option<Self> {
|
||||
let _input_id = input.read_byte()?;
|
||||
$crate::__impl_decode!(input; _input_id; 0; $call_type; $( fn $fn_name( $( $(#[$codec_attr on type $param])* $param_name ),* ); )*)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Encode for $call_type<$trait_instance> {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Encode for $call_type<$trait_instance $(, $instance)?> {
|
||||
fn encode_to<W: $crate::dispatch::Output>(&self, _dest: &mut W) {
|
||||
$crate::__impl_encode!(_dest; *self; 0; $call_type; $( fn $fn_name( $( $(#[$codec_attr on type $param])* $param_name ),* ); )*);
|
||||
}
|
||||
}
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Dispatchable
|
||||
for $call_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Dispatchable
|
||||
for $call_type<$trait_instance $(, $instance)?>
|
||||
{
|
||||
type Trait = $trait_instance;
|
||||
type Origin = $origin_type;
|
||||
@@ -721,7 +716,7 @@ macro_rules! decl_module {
|
||||
$crate::decl_module!(
|
||||
@call
|
||||
$from
|
||||
$mod_type $trait_instance $fn_name _origin $system [ $( $param_name ),* ]
|
||||
$mod_type<$trait_instance $(, $fn_instance)?> $fn_name _origin $system [ $( $param_name ),* ]
|
||||
)
|
||||
},
|
||||
)*
|
||||
@@ -729,20 +724,20 @@ macro_rules! decl_module {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<$trait_instance: $trait_name> $crate::dispatch::Callable
|
||||
for $mod_type<$trait_instance>
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Callable
|
||||
for $mod_type<$trait_instance $(, $instance)?>
|
||||
{
|
||||
type Call = $call_type<$trait_instance>;
|
||||
type Call = $call_type<$trait_instance $(, $instance)?>;
|
||||
}
|
||||
|
||||
impl<$trait_instance: $trait_name> $mod_type<$trait_instance> {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
|
||||
#[doc(hidden)]
|
||||
pub fn dispatch<D: $crate::dispatch::Dispatchable<Trait = $trait_instance>>(d: D, origin: D::Origin) -> $crate::dispatch::Result {
|
||||
d.dispatch(origin)
|
||||
}
|
||||
}
|
||||
$crate::__dispatch_impl_metadata! {
|
||||
$mod_type $trait_instance $trait_name $call_type $origin_type
|
||||
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $call_type $origin_type
|
||||
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $(#[$codec_attr])* $param_name : $param )*); )*}
|
||||
}
|
||||
}
|
||||
@@ -949,10 +944,10 @@ macro_rules! __impl_outer_dispatch_common {
|
||||
#[doc(hidden)]
|
||||
macro_rules! __dispatch_impl_metadata {
|
||||
(
|
||||
$mod_type:ident $trait_instance:ident $trait_name:ident
|
||||
$mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $mod_type<$trait_instance> {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
|
||||
#[doc(hidden)]
|
||||
pub fn call_functions() -> &'static [$crate::dispatch::FunctionMetadata] {
|
||||
$crate::__call_to_functions!($($rest)*)
|
||||
|
||||
@@ -88,16 +88,48 @@ pub use srml_metadata::{EventMetadata, DecodeDifferent, OuterEventMetadata, FnEn
|
||||
/// ```
|
||||
///
|
||||
/// The syntax for generic events requires the `where`.
|
||||
///
|
||||
/// # Generic Event with Instance Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[macro_use]
|
||||
/// extern crate srml_support;
|
||||
/// extern crate parity_codec as codec;
|
||||
/// #[macro_use]
|
||||
/// extern crate parity_codec;
|
||||
/// #[macro_use]
|
||||
/// extern crate serde_derive;
|
||||
///
|
||||
///# struct DefaultInstance;
|
||||
///# trait Instance {}
|
||||
///# impl Instance for DefaultInstance {}
|
||||
/// trait Trait<I: Instance=DefaultInstance> {
|
||||
/// type Balance;
|
||||
/// type Token;
|
||||
/// }
|
||||
///
|
||||
/// // For module with instances, DefaultInstance is optionnal
|
||||
/// decl_event!(
|
||||
/// pub enum Event<T, I: Instance = DefaultInstance> where
|
||||
/// <T as Trait>::Balance,
|
||||
/// <T as Trait>::Token
|
||||
/// {
|
||||
/// Message(Balance, Token),
|
||||
/// }
|
||||
/// );
|
||||
///# fn main() {}
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! decl_event {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum Event<$evt_generic_param:ident> where
|
||||
pub enum Event<$evt_generic_param:ident $(, $instance:ident $(: $instantiable:ident)? $( = $event_default_instance:path)? )?> where
|
||||
$( $tt:tt )*
|
||||
) => {
|
||||
$crate::__decl_generic_event!(
|
||||
$( #[ $attr ] )*;
|
||||
$evt_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $( $tt )* };
|
||||
);
|
||||
};
|
||||
@@ -138,11 +170,13 @@ macro_rules! __decl_generic_event {
|
||||
(
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $( $tt:tt )* };
|
||||
) => {
|
||||
$crate::__decl_generic_event!(@format_generic
|
||||
$( #[ $attr ] )*;
|
||||
$event_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $( $tt )* };
|
||||
{};
|
||||
);
|
||||
@@ -151,12 +185,14 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $generic_rename:ident = $generic_type:ty, $($rest:tt)* };
|
||||
{$( $parsed:tt)*};
|
||||
) => {
|
||||
$crate::__decl_generic_event!(@format_generic
|
||||
$( #[ $attr ] )*;
|
||||
$event_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $($rest)* };
|
||||
{ $($parsed)*, $generic_rename = $generic_type };
|
||||
);
|
||||
@@ -165,12 +201,14 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ <$generic:ident as $trait:path>::$trait_type:ident, $($rest:tt)* };
|
||||
{$($parsed:tt)*};
|
||||
) => {
|
||||
$crate::__decl_generic_event!(@format_generic
|
||||
$( #[ $attr ] )*;
|
||||
$event_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $($rest)* };
|
||||
{ $($parsed)*, $trait_type = <$generic as $trait>::$trait_type };
|
||||
);
|
||||
@@ -179,6 +217,7 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $generic_type:ty, $($rest:tt)* };
|
||||
{$($parsed:tt)*};
|
||||
) => {
|
||||
@@ -188,12 +227,14 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ <$generic:ident as $trait:path>::$trait_type:ident { $( $events:tt )* } };
|
||||
{$( $parsed:tt)*};
|
||||
) => {
|
||||
$crate::__decl_generic_event!(@generate
|
||||
$( #[ $attr ] )*;
|
||||
$event_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $($events)* };
|
||||
{ $($parsed)*, $trait_type = <$generic as $trait>::$trait_type};
|
||||
);
|
||||
@@ -202,12 +243,14 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $generic_rename:ident = $generic_type:ty { $( $events:tt )* } };
|
||||
{$( $parsed:tt)*};
|
||||
) => {
|
||||
$crate::__decl_generic_event!(@generate
|
||||
$(#[$attr])*;
|
||||
$event_generic_param;
|
||||
$($instance $( = $event_default_instance)? )?;
|
||||
{ $($events)* };
|
||||
{ $($parsed)*, $generic_rename = $generic_type};
|
||||
);
|
||||
@@ -216,6 +259,7 @@ macro_rules! __decl_generic_event {
|
||||
(@format_generic
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $generic_type:ty { $( $events:tt )* } };
|
||||
{$( $parsed:tt)*};
|
||||
) => {
|
||||
@@ -224,6 +268,7 @@ macro_rules! __decl_generic_event {
|
||||
(@generate
|
||||
$(#[$attr:meta])*;
|
||||
$event_generic_param:ident;
|
||||
$($instance:ident $( = $event_default_instance:path)? )?;
|
||||
{ $( $events:tt )* };
|
||||
{ ,$( $generic_param:ident = $generic_type:ty ),* };
|
||||
) => {
|
||||
@@ -231,20 +276,22 @@ macro_rules! __decl_generic_event {
|
||||
///
|
||||
/// [`RawEvent`]: enum.RawEvent.html
|
||||
/// [`Trait`]: trait.Trait.html
|
||||
pub type Event<$event_generic_param> = RawEvent<$( $generic_type ),*>;
|
||||
pub type Event<$event_generic_param $(, $instance $( = $event_default_instance)? )?> = RawEvent<$( $generic_type ),* $(, $instance)? >;
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
$(#[$attr])*
|
||||
pub enum RawEvent<$( $generic_param ),*> {
|
||||
pub enum RawEvent<$( $generic_param ),* $(, $instance)? > {
|
||||
#[doc(hidden)]
|
||||
$(PhantomData($crate::rstd::marker::PhantomData<$instance>),)?
|
||||
$(
|
||||
$events
|
||||
)*
|
||||
}
|
||||
impl<$( $generic_param ),*> From<RawEvent<$( $generic_param ),*>> for () {
|
||||
fn from(_: RawEvent<$( $generic_param ),*>) -> () { () }
|
||||
impl<$( $generic_param ),* $(, $instance)? > From<RawEvent<$( $generic_param ),* $(, $instance)?>> for () {
|
||||
fn from(_: RawEvent<$( $generic_param ),* $(, $instance)?>) -> () { () }
|
||||
}
|
||||
impl<$( $generic_param ),*> RawEvent<$( $generic_param ),*> {
|
||||
impl<$( $generic_param ),* $(, $instance)?> RawEvent<$( $generic_param ),* $(, $instance)?> {
|
||||
#[allow(dead_code)]
|
||||
pub fn metadata() -> &'static [$crate::event::EventMetadata] {
|
||||
$crate::__events_to_metadata!(; $( $events )* )
|
||||
@@ -297,7 +344,7 @@ macro_rules! impl_outer_event {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident {
|
||||
$( $rest:tt $( <$t:ident> )*, )*
|
||||
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
|
||||
}
|
||||
) => {
|
||||
$crate::impl_outer_event!(
|
||||
@@ -305,14 +352,14 @@ macro_rules! impl_outer_event {
|
||||
$name;
|
||||
$runtime;
|
||||
system;
|
||||
Modules { $( $rest $(<$t>)*, )* };
|
||||
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
|
||||
;
|
||||
);
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident where system = $system:ident {
|
||||
$( $rest:tt $( <$t:ident> )*, )*
|
||||
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
|
||||
}
|
||||
) => {
|
||||
$crate::impl_outer_event!(
|
||||
@@ -320,7 +367,7 @@ macro_rules! impl_outer_event {
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest $(<$t>)*, )* };
|
||||
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
|
||||
;
|
||||
);
|
||||
};
|
||||
@@ -330,18 +377,18 @@ macro_rules! impl_outer_event {
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
Modules {
|
||||
$module:ident<T>,
|
||||
$( $rest:tt $( <$t:ident> )*, )*
|
||||
$module:ident<T $(, $instance:path)? >,
|
||||
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
|
||||
};
|
||||
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
|
||||
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
|
||||
) => {
|
||||
$crate::impl_outer_event!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest $(<$t>)*, )* };
|
||||
$( $module_name::Event $( <$generic_param> )*, )* $module::Event<$runtime>,;
|
||||
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
|
||||
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )* $module::Event<$runtime $(, $instance)? >,;
|
||||
);
|
||||
};
|
||||
(
|
||||
@@ -351,17 +398,17 @@ macro_rules! impl_outer_event {
|
||||
$system:ident;
|
||||
Modules {
|
||||
$module:ident,
|
||||
$( $rest:tt, )*
|
||||
$( $rest:tt )*
|
||||
};
|
||||
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
|
||||
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
|
||||
) => {
|
||||
$crate::impl_outer_event!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest, )* };
|
||||
$( $module_name::Event $( <$generic_param> )*, )* $module::Event,;
|
||||
Modules { $( $rest )* };
|
||||
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )* $module::Event,;
|
||||
);
|
||||
};
|
||||
|
||||
@@ -373,7 +420,7 @@ macro_rules! impl_outer_event {
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
Modules {};
|
||||
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
|
||||
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
|
||||
) => {
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
@@ -383,7 +430,7 @@ macro_rules! impl_outer_event {
|
||||
pub enum $name {
|
||||
system($system::Event),
|
||||
$(
|
||||
$module_name( $module_name::Event $( <$generic_param> )* ),
|
||||
$module_name( $module_name::Event $( <$generic_param $(, $generic_instance)? > )* ),
|
||||
)*
|
||||
}
|
||||
impl From<$system::Event> for $name {
|
||||
@@ -392,8 +439,8 @@ macro_rules! impl_outer_event {
|
||||
}
|
||||
}
|
||||
$(
|
||||
impl From<$module_name::Event $( <$generic_param> )*> for $name {
|
||||
fn from(x: $module_name::Event $( <$generic_param> )*) -> Self {
|
||||
impl From<$module_name::Event $( <$generic_param $(, $generic_instance)? > )*> for $name {
|
||||
fn from(x: $module_name::Event $( <$generic_param $(, $generic_instance)? > )*) -> Self {
|
||||
$name::$module_name(x)
|
||||
}
|
||||
}
|
||||
@@ -402,7 +449,7 @@ macro_rules! impl_outer_event {
|
||||
$runtime;
|
||||
$name;
|
||||
$system;
|
||||
$( $module_name::Event $( <$generic_param> )*, )*;
|
||||
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )*;
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -414,7 +461,7 @@ macro_rules! __impl_outer_event_json_metadata {
|
||||
$runtime:ident;
|
||||
$event_name:ident;
|
||||
$system:ident;
|
||||
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
|
||||
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
|
||||
) => {
|
||||
impl $runtime {
|
||||
#[allow(dead_code)]
|
||||
@@ -427,7 +474,7 @@ macro_rules! __impl_outer_event_json_metadata {
|
||||
, (
|
||||
stringify!($module_name),
|
||||
$crate::event::FnEncode(
|
||||
$module_name::Event $( ::<$generic_param> )* ::metadata
|
||||
$module_name::Event $( ::<$generic_param $(, $generic_instance)? > )* ::metadata
|
||||
)
|
||||
)
|
||||
)*
|
||||
@@ -442,7 +489,7 @@ macro_rules! __impl_outer_event_json_metadata {
|
||||
#[allow(dead_code)]
|
||||
$crate::paste::item!{
|
||||
pub fn [< __module_events_ $module_name >] () -> &'static [$crate::event::EventMetadata] {
|
||||
$module_name::Event $( ::<$generic_param> )* ::metadata()
|
||||
$module_name::Event $( ::<$generic_param $(, $generic_instance)? > )* ::metadata()
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
@@ -64,6 +64,21 @@ pub use runtime_io::print;
|
||||
#[doc(inline)]
|
||||
pub use srml_support_procedural::decl_storage;
|
||||
|
||||
pub mod lazy {
|
||||
use spin::Once;
|
||||
|
||||
pub struct Lazy<T: Sync>(Once<T>);
|
||||
|
||||
impl <T: Sync> Lazy<T> {
|
||||
pub const INIT: Self = Lazy(Once::INIT);
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get<F>(&'static self, builder: F) -> &T where F: FnOnce() -> T {
|
||||
self.0.call_once(builder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fail {
|
||||
( $y:expr ) => {{
|
||||
|
||||
@@ -52,17 +52,17 @@ macro_rules! __runtime_modules_to_metadata {
|
||||
(
|
||||
$runtime: ident;
|
||||
$( $metadata:expr ),*;
|
||||
$mod:ident::$module:ident $(with)+ $($kw:ident)*,
|
||||
$mod:ident::$module:ident $( < $instance:ident > )? $(with)+ $($kw:ident)*,
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::__runtime_modules_to_metadata!(
|
||||
$runtime;
|
||||
$( $metadata, )* $crate::metadata::ModuleMetadata {
|
||||
name: $crate::metadata::DecodeDifferent::Encode(stringify!($mod)),
|
||||
prefix: $crate::__runtime_modules_to_metadata_calls_storagename!($mod, $module, $runtime, $(with $kw)*),
|
||||
storage: $crate::__runtime_modules_to_metadata_calls_storage!($mod, $module, $runtime, $(with $kw)*),
|
||||
calls: $crate::__runtime_modules_to_metadata_calls_call!($mod, $module, $runtime, $(with $kw)*),
|
||||
event: $crate::__runtime_modules_to_metadata_calls_event!($mod, $module, $runtime, $(with $kw)*),
|
||||
prefix: $crate::__runtime_modules_to_metadata_calls_storagename!($mod, $module $( <$instance> )?, $runtime, $(with $kw)*),
|
||||
storage: $crate::__runtime_modules_to_metadata_calls_storage!($mod, $module $( <$instance> )?, $runtime, $(with $kw)*),
|
||||
calls: $crate::__runtime_modules_to_metadata_calls_call!($mod, $module $( <$instance> )?, $runtime, $(with $kw)*),
|
||||
event: $crate::__runtime_modules_to_metadata_calls_event!($mod, $module $( <$instance> )?, $runtime, $(with $kw)*),
|
||||
};
|
||||
$( $rest )*
|
||||
)
|
||||
@@ -81,7 +81,7 @@ macro_rules! __runtime_modules_to_metadata_calls_call {
|
||||
// skip system
|
||||
(
|
||||
system,
|
||||
$skip_module: ident,
|
||||
$skip_module: ident $( <$instance:ident> )?,
|
||||
$skip_runtime: ident,
|
||||
with Call
|
||||
$(with $kws:ident)*
|
||||
@@ -90,29 +90,29 @@ macro_rules! __runtime_modules_to_metadata_calls_call {
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with Call
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
Some($crate::metadata::DecodeDifferent::Encode(
|
||||
$crate::metadata::FnEncode(
|
||||
$mod::$module::<$runtime>::call_functions
|
||||
$mod::$module::<$runtime $(, $mod::$instance )?>::call_functions
|
||||
)
|
||||
))
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with $_:ident
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
$crate::__runtime_modules_to_metadata_calls_call!( $mod, $module, $runtime, $(with $kws)* );
|
||||
$crate::__runtime_modules_to_metadata_calls_call!( $mod, $module $( <$instance> )?, $runtime, $(with $kws)* );
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
) => {
|
||||
None
|
||||
@@ -125,7 +125,7 @@ macro_rules! __runtime_modules_to_metadata_calls_call {
|
||||
macro_rules! __runtime_modules_to_metadata_calls_event {
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with Event
|
||||
$(with $kws:ident)*
|
||||
@@ -133,23 +133,23 @@ macro_rules! __runtime_modules_to_metadata_calls_event {
|
||||
Some($crate::metadata::DecodeDifferent::Encode(
|
||||
$crate::metadata::FnEncode(
|
||||
$crate::paste::expr!{
|
||||
$runtime:: [< __module_events_ $mod >]
|
||||
$runtime:: [< __module_events_ $mod $(_ $instance)?>]
|
||||
}
|
||||
)
|
||||
))
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with $_:ident
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
$crate::__runtime_modules_to_metadata_calls_event!( $mod, $module, $runtime, $(with $kws)* );
|
||||
$crate::__runtime_modules_to_metadata_calls_event!( $mod, $module $( <$instance> )?, $runtime, $(with $kws)* );
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
) => {
|
||||
None
|
||||
@@ -161,29 +161,29 @@ macro_rules! __runtime_modules_to_metadata_calls_event {
|
||||
macro_rules! __runtime_modules_to_metadata_calls_storagename {
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with Storage
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
$crate::metadata::DecodeDifferent::Encode(
|
||||
$crate::metadata::FnEncode(
|
||||
$mod::$module::<$runtime>::store_metadata_name
|
||||
$mod::$module::<$runtime $(, $mod::$instance )?>::store_metadata_name
|
||||
)
|
||||
)
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with $_:ident
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
$crate::__runtime_modules_to_metadata_calls_storagename!( $mod, $module, $runtime, $(with $kws)* );
|
||||
$crate::__runtime_modules_to_metadata_calls_storagename!( $mod, $module $( <$instance> )?, $runtime, $(with $kws)* );
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
) => {
|
||||
$crate::metadata::DecodeDifferent::Encode(
|
||||
@@ -197,29 +197,29 @@ macro_rules! __runtime_modules_to_metadata_calls_storagename {
|
||||
macro_rules! __runtime_modules_to_metadata_calls_storage {
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with Storage
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
Some($crate::metadata::DecodeDifferent::Encode(
|
||||
$crate::metadata::FnEncode(
|
||||
$mod::$module::<$runtime>::store_metadata_functions
|
||||
$mod::$module::<$runtime $(, $mod::$instance )?>::store_metadata_functions
|
||||
)
|
||||
))
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
with $_:ident
|
||||
$(with $kws:ident)*
|
||||
) => {
|
||||
$crate::__runtime_modules_to_metadata_calls_storage!( $mod, $module, $runtime, $(with $kws)* );
|
||||
$crate::__runtime_modules_to_metadata_calls_storage!( $mod, $module $( <$instance> )?, $runtime, $(with $kws)* );
|
||||
};
|
||||
(
|
||||
$mod: ident,
|
||||
$module: ident,
|
||||
$module: ident $( <$instance:ident> )?,
|
||||
$runtime: ident,
|
||||
) => {
|
||||
None
|
||||
|
||||
@@ -28,34 +28,20 @@ macro_rules! impl_outer_origin {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident {
|
||||
$( $module:ident $( <$generic:ident> )* ),* $(,)*
|
||||
$( $module:ident $( <$generic:ident $(, $instance:path )? > )? ),* $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::impl_outer_origin! {
|
||||
$(#[$attr])*
|
||||
pub enum $name for $runtime where system = system {
|
||||
$( $module $( <$generic> )*, )*
|
||||
$( $module $( <$generic $(, $instance )? > )?, )*
|
||||
}
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident where system = $system:ident {}
|
||||
) => {
|
||||
$crate::impl_outer_origin!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { };
|
||||
;
|
||||
);
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident where system = $system:ident {
|
||||
$module:ident,
|
||||
$( $rest_module:ident $( <$rest_generic:ident> )* ),* $(,)*
|
||||
$( $module:ident $( <$generic:ident $(, $instance:path )?> )? ),* $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::impl_outer_origin!(
|
||||
@@ -63,64 +49,30 @@ macro_rules! impl_outer_origin {
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest_module $( <$rest_generic> )*, )* };
|
||||
$module;
|
||||
);
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub enum $name:ident for $runtime:ident where system = $system:ident {
|
||||
$module:ident<T>,
|
||||
$( $rest_module:ident $( <$rest_generic:ident> )* ),* $(,)*
|
||||
}
|
||||
) => {
|
||||
$crate::impl_outer_origin!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest_module $( <$rest_generic> )*, )* };
|
||||
$module<$runtime>;
|
||||
Modules { $( $module $( <$generic $(, $instance )? > )*, )* };
|
||||
);
|
||||
};
|
||||
|
||||
// Replace generic param with runtime
|
||||
|
||||
(
|
||||
$(#[$attr:meta])*;
|
||||
$name:ident;
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
Modules {
|
||||
$module:ident,
|
||||
$( $rest_module:ident $( <$rest_generic:ident> )*, )*
|
||||
$module:ident $( <T $(, $instance:path )? > )?,
|
||||
$( $rest_module:tt )*
|
||||
};
|
||||
$( $parsed_module:ident $( <$generic_param:ident> )* ),*;
|
||||
$( $parsed:tt )*
|
||||
) => {
|
||||
$crate::impl_outer_origin!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest_module $( <$rest_generic> )*, )* };
|
||||
$( $parsed_module $( <$generic_param> )* ),*, $module;
|
||||
);
|
||||
};
|
||||
(
|
||||
$(#[$attr:meta])*;
|
||||
$name:ident;
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
Modules {
|
||||
$module:ident<T>,
|
||||
$( $rest_module:ident $( <$rest_generic:ident> )*, )*
|
||||
};
|
||||
$( $parsed_module:ident $( <$generic_param:ident> )* ),*;
|
||||
) => {
|
||||
$crate::impl_outer_origin!(
|
||||
$( #[$attr] )*;
|
||||
$name;
|
||||
$runtime;
|
||||
$system;
|
||||
Modules { $( $rest_module $( <$rest_generic> )*, )* };
|
||||
$( $parsed_module $( <$generic_param> )* ),*, $module<$runtime>;
|
||||
Modules { $( $rest_module )* };
|
||||
$( $parsed )* $module $( <$runtime $(, $instance )? > )?,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -131,8 +83,8 @@ macro_rules! impl_outer_origin {
|
||||
$name:ident;
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
Modules {};
|
||||
$( $module:ident $( <$generic_param:ident> )* ),*;
|
||||
Modules { };
|
||||
$( $module:ident $( <$generic_param:ident $(, $generic_instance:path )? > )* ,)*
|
||||
) => {
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
@@ -142,7 +94,7 @@ macro_rules! impl_outer_origin {
|
||||
pub enum $name {
|
||||
system($system::Origin<$runtime>),
|
||||
$(
|
||||
$module($module::Origin $( <$generic_param> )* ),
|
||||
$module($module::Origin $( <$generic_param $(, $generic_instance )? > )* ),
|
||||
)*
|
||||
#[allow(dead_code)]
|
||||
Void($crate::Void)
|
||||
@@ -175,13 +127,13 @@ macro_rules! impl_outer_origin {
|
||||
}
|
||||
}
|
||||
$(
|
||||
impl From<$module::Origin $( <$generic_param> )*> for $name {
|
||||
fn from(x: $module::Origin $( <$generic_param> )*) -> Self {
|
||||
impl From<$module::Origin $( <$generic_param $(, $generic_instance )? > )*> for $name {
|
||||
fn from(x: $module::Origin $( <$generic_param $(, $generic_instance )? > )*) -> Self {
|
||||
$name::$module(x)
|
||||
}
|
||||
}
|
||||
impl Into<Option<$module::Origin $( <$generic_param> )*>> for $name {
|
||||
fn into(self) -> Option<$module::Origin $( <$generic_param> )*> {
|
||||
impl Into<Option<$module::Origin $( <$generic_param $(, $generic_instance )? > )*>> for $name {
|
||||
fn into(self) -> Option<$module::Origin $( <$generic_param $(, $generic_instance )? > )*> {
|
||||
if let $name::$module(l) = self {
|
||||
Some(l)
|
||||
} else {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user