Allow where bounds on decl_module! and decl_storage! (#3000)

* Introduces a `where` bound to `decl_macro!` and `decl_storage!`

* More fixes

* Adds documentation
This commit is contained in:
Bastian Köcher
2019-07-03 21:07:39 +02:00
committed by GitHub
parent 5dc8792d8f
commit e9864b94a3
6 changed files with 328 additions and 99 deletions
@@ -139,6 +139,14 @@ use proc_macro::TokenStream;
/// Accessing the structure no requires the instance as generic parameter:
/// * `Foo::<I>` if the value type is not generic
/// * `Foo::<T, I>` if the value type is generic
///
/// ## Where clause
///
/// This macro supports a where clause which will be replicated to all generated types.
///
/// ```nocompile
/// trait Store for Module<T: Trait> as Example where T::AccountId: std::fmt::Display {}
/// ```
#[proc_macro]
pub fn decl_storage(input: TokenStream) -> TokenStream {
storage::transformation::decl_storage_impl(input)
@@ -47,6 +47,7 @@ pub(crate) struct Impls<'a, I: Iterator<Item=syn::Meta>> {
pub cratename: &'a syn::Ident,
pub name: &'a syn::Ident,
pub attrs: I,
pub where_clause: &'a Option<syn::WhereClause>,
}
impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
@@ -62,6 +63,7 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
prefix,
name,
attrs,
where_clause,
..
} = self;
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
@@ -94,19 +96,21 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
quote!{ #prefix.as_bytes() }
};
let (struct_trait, impl_trait, trait_and_instance) = if ext::type_contains_ident(
let (struct_trait, impl_trait, trait_and_instance, where_clause) = if ext::type_contains_ident(
value_type, traitinstance
) {
(
quote!(#traitinstance: #traittype, #instance #bound_instantiable #equal_default_instance),
quote!(#traitinstance: #traittype, #instance #bound_instantiable),
quote!(#traitinstance, #instance),
where_clause.clone(),
)
} else {
(
quote!(#instance #bound_instantiable #equal_default_instance),
quote!(#instance #bound_instantiable),
quote!(#instance)
quote!(#instance),
None,
)
};
@@ -115,10 +119,10 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
#( #[ #attrs ] )*
#visibility struct #name<#struct_trait>(
#scrate::rstd::marker::PhantomData<(#trait_and_instance)>
);
) #where_clause;
impl<#impl_trait> #scrate::storage::hashed::generator::StorageValue<#typ>
for #name<#trait_and_instance>
for #name<#trait_and_instance> #where_clause
{
type Query = #value_type;
@@ -167,6 +171,7 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
prefix,
name,
attrs,
where_clause,
..
} = self;
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
@@ -201,19 +206,22 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
quote!{ #prefix.as_bytes() }
};
let (struct_trait, impl_trait, trait_and_instance) = if ext::type_contains_ident(value_type, traitinstance)
|| ext::type_contains_ident(kty, traitinstance)
{
let trait_required = ext::type_contains_ident(value_type, traitinstance)
|| ext::type_contains_ident(kty, traitinstance);
let (struct_trait, impl_trait, trait_and_instance, where_clause) = if trait_required {
(
quote!(#traitinstance: #traittype, #instance #bound_instantiable #equal_default_instance),
quote!(#traitinstance: #traittype, #instance #bound_instantiable),
quote!(#traitinstance, #instance),
where_clause.clone(),
)
} else {
(
quote!(#instance #bound_instantiable #equal_default_instance),
quote!(#instance #bound_instantiable),
quote!(#instance)
quote!(#instance),
None,
)
};
@@ -222,10 +230,10 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
#( #[ #attrs ] )*
#visibility struct #name<#struct_trait>(
#scrate::rstd::marker::PhantomData<(#trait_and_instance)>
);
) #where_clause;
impl<#impl_trait>
#scrate::storage::hashed::generator::StorageMap<#kty, #typ> for #name<#trait_and_instance>
impl<#impl_trait> #scrate::storage::hashed::generator::StorageMap<#kty, #typ>
for #name<#trait_and_instance> #where_clause
{
type Query = #value_type;
@@ -270,7 +278,7 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
}
impl<#impl_trait> #scrate::storage::hashed::generator::AppendableStorageMap<#kty, #typ>
for #name<#trait_and_instance>
for #name<#trait_and_instance> #where_clause
{}
}
}
@@ -287,6 +295,7 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
prefix,
name,
attrs,
where_clause,
..
} = self;
@@ -298,7 +307,9 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
} = instance_opts;
let final_prefix = if let Some(instance) = instance {
let const_name = syn::Ident::new(&format!("{}{}", PREFIX_FOR, name.to_string()), proc_macro2::Span::call_site());
let const_name = Ident::new(
&format!("{}{}", PREFIX_FOR, name.to_string()), proc_macro2::Span::call_site()
);
quote!{ #instance::#const_name.as_bytes() }
} else {
quote!{ #prefix.as_bytes() }
@@ -306,7 +317,9 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
// make sure to use different prefix for head and elements.
let final_head_key = if let Some(instance) = instance {
let const_name = syn::Ident::new(&format!("{}{}", HEAD_KEY_FOR, name.to_string()), proc_macro2::Span::call_site());
let const_name = Ident::new(
&format!("{}{}", HEAD_KEY_FOR, name.to_string()), proc_macro2::Span::call_site()
);
quote!{ #instance::#const_name.as_bytes() }
} else {
let final_head_key = format!("head of {}", prefix);
@@ -316,8 +329,10 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
let option_simple_1 = option_unwrap(is_option);
let name_lowercase = name.to_string().to_lowercase();
let inner_module = syn::Ident::new(&format!("__linked_map_details_for_{}_do_not_use", name_lowercase), name.span());
let linkage = syn::Ident::new(&format!("__LinkageFor{}DoNotUse", name), name.span());
let inner_module = Ident::new(
&format!("__linked_map_details_for_{}_do_not_use", name_lowercase), name.span()
);
let linkage = Ident::new(&format!("__LinkageFor{}DoNotUse", name), name.span());
let phantom_data = quote! { #scrate::rstd::marker::PhantomData };
let as_map = quote!{ <Self as #scrate::storage::hashed::generator::StorageMap<#kty, #typ>> };
let put_or_insert = quote! {
@@ -337,23 +352,35 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
}
};
let (struct_trait, impl_trait, trait_and_instance, trait_lifetime) = if ext::type_contains_ident(
value_type,
traitinstance
) || ext::type_contains_ident(kty, traitinstance)
{
let trait_required = ext::type_contains_ident(value_type, traitinstance)
|| ext::type_contains_ident(kty, traitinstance);
let (struct_trait, impl_trait, trait_and_instance) = if trait_required {
(
quote!(#traitinstance: #traittype, #instance #bound_instantiable #equal_default_instance),
quote!(#traitinstance: #traittype, #instance #bound_instantiable),
quote!(#traitinstance, #instance),
quote!(#traitinstance: 'static),
)
} else {
(
quote!(#instance #bound_instantiable #equal_default_instance),
quote!(#instance #bound_instantiable),
quote!(#instance),
quote!()
)
};
let (where_clause, trait_where_clause) = if trait_required {
(
where_clause.clone(),
where_clause.clone().map(|mut wc| {
wc.predicates.push(syn::parse_quote!(#traitinstance: 'static));
wc
}).or_else(|| syn::parse_quote!(where #traitinstance: 'static)),
)
} else {
(
None,
None,
)
};
@@ -390,8 +417,8 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
pub _data: #phantom_data<V>,
}
impl<'a, S: #scrate::HashedStorage<#scrate::#hasher>, #impl_trait>
Iterator for Enumerator<'a, S, #kty, (#typ, #trait_and_instance)>
impl<'a, S: #scrate::HashedStorage<#scrate::#hasher>, #impl_trait> Iterator
for Enumerator<'a, S, #kty, (#typ, #trait_and_instance)> #where_clause
{
type Item = (#kty, #typ);
@@ -442,7 +469,9 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
#( #[ #attrs ] )*
#visibility struct #name<#struct_trait>(#phantom_data<(#trait_and_instance)>);
impl<#impl_trait> self::#inner_module::Utils<#trait_and_instance> for #name<#trait_and_instance> {
impl<#impl_trait> self::#inner_module::Utils<#trait_and_instance>
for #name<#trait_and_instance> #where_clause
{
fn remove_linkage<S: #scrate::HashedStorage<#scrate::#hasher>>(
linkage: self::#inner_module::Linkage<#kty>,
storage: &mut S,
@@ -529,8 +558,8 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
#structure
impl<#impl_trait>
#scrate::storage::hashed::generator::StorageMap<#kty, #typ> for #name<#trait_and_instance>
impl<#impl_trait> #scrate::storage::hashed::generator::StorageMap<#kty, #typ>
for #name<#trait_and_instance> #where_clause
{
type Query = #value_type;
@@ -605,10 +634,8 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
}
}
impl<#impl_trait>
#scrate::storage::hashed::generator::EnumerableStorageMap<#kty, #typ> for #name<#trait_and_instance>
where
#trait_lifetime
impl<#impl_trait> #scrate::storage::hashed::generator::EnumerableStorageMap<#kty, #typ>
for #name<#trait_and_instance> #trait_where_clause
{
fn head<S: #scrate::HashedStorage<#scrate::#hasher>>(storage: &S) -> Option<#kty> {
use self::#inner_module::Utils;
@@ -654,13 +681,16 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
name,
attrs,
instance_opts,
where_clause,
..
} = self;
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
let option_simple_1 = option_unwrap(is_option);
let as_double_map = quote!{ <Self as #scrate::storage::unhashed::generator::StorageDoubleMap<#k1ty, #k2ty, #typ>> };
let as_double_map = quote!{
<Self as #scrate::storage::unhashed::generator::StorageDoubleMap<#k1ty, #k2ty, #typ>>
};
let mutate_impl = if !is_option {
quote!{
@@ -683,26 +713,30 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
} = instance_opts;
let final_prefix = if let Some(instance) = instance {
let const_name = syn::Ident::new(&format!("{}{}", PREFIX_FOR, name.to_string()), proc_macro2::Span::call_site());
let const_name = Ident::new(
&format!("{}{}", PREFIX_FOR, name.to_string()), proc_macro2::Span::call_site()
);
quote!{ #instance::#const_name.as_bytes() }
} else {
quote!{ #prefix.as_bytes() }
};
let (struct_trait, impl_trait, trait_and_instance) = if ext::type_contains_ident(value_type, traitinstance)
|| ext::type_contains_ident(k1ty, traitinstance)
|| ext::type_contains_ident(k2ty, traitinstance)
let (struct_trait, impl_trait, trait_and_instance, where_clause) = if ext::type_contains_ident(
value_type, traitinstance
) || ext::type_contains_ident(k1ty, traitinstance) || ext::type_contains_ident(k2ty, traitinstance)
{
(
quote!(#traitinstance: #traittype, #instance #bound_instantiable #equal_default_instance),
quote!(#traitinstance: #traittype, #instance #bound_instantiable),
quote!(#traitinstance, #instance),
where_clause.clone(),
)
} else {
(
quote!(#instance #bound_instantiable #equal_default_instance),
quote!(#instance #bound_instantiable),
quote!(#instance)
quote!(#instance),
None,
)
};
@@ -712,8 +746,8 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
#visibility struct #name<#struct_trait>
(#scrate::rstd::marker::PhantomData<(#trait_and_instance)>);
impl<#impl_trait>
#scrate::storage::unhashed::generator::StorageDoubleMap<#k1ty, #k2ty, #typ> for #name<#trait_and_instance>
impl<#impl_trait> #scrate::storage::unhashed::generator::StorageDoubleMap<#k1ty, #k2ty, #typ>
for #name<#trait_and_instance> #where_clause
{
type Query = #value_type;
@@ -65,6 +65,7 @@ struct StorageDefinition {
pub mod_gt_token: Token![>],
pub as_token: Token![as],
pub crate_ident: Ident,
pub where_clause: Option<syn::WhereClause>,
pub content: ext::Braces<ext::Punctuated<DeclStorageLine, Token![;]>>,
pub extra_genesis: ext::Opt<AddExtraGenesis>,
}
@@ -27,6 +27,7 @@ use proc_macro2::{TokenStream as TokenStream2, Span};
use syn::{
Ident,
GenericParam,
WhereClause,
spanned::Spanned,
parse::{
Error,
@@ -68,6 +69,7 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
crate_ident: cratename,
content: ext::Braces { content: storage_lines, ..},
extra_genesis,
where_clause,
..
} = def;
@@ -110,6 +112,7 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
&instance_opts,
&storage_lines,
&extra_genesis.inner,
&where_clause,
));
let decl_storage_items = decl_storage_items(
&scrate,
@@ -118,6 +121,7 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
&instance_opts,
&cratename,
&storage_lines,
&where_clause,
);
let decl_store_items = decl_store_items(
@@ -140,6 +144,7 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
&traittype,
&instance_opts,
&storage_lines,
&where_clause,
);
let InstanceOpts {
@@ -156,10 +161,14 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
#decl_store_items
}
#store_default_struct
impl<#traitinstance: #traittype, #instance #bound_instantiable> #storetype for #module_ident<#traitinstance, #instance> {
impl<#traitinstance: #traittype, #instance #bound_instantiable> #storetype
for #module_ident<#traitinstance, #instance> #where_clause
{
#impl_store_items
}
impl<#traitinstance: 'static + #traittype, #instance #bound_instantiable> #module_ident<#traitinstance, #instance> {
impl<#traitinstance: 'static + #traittype, #instance #bound_instantiable>
#module_ident<#traitinstance, #instance> #where_clause
{
#impl_store_fns
#[doc(hidden)]
pub fn store_metadata_functions() -> &'static [#scrate::metadata::StorageEntryMetadata] {
@@ -184,6 +193,7 @@ fn decl_store_extra_genesis(
instance_opts: &InstanceOpts,
storage_lines: &ext::Punctuated<DeclStorageLine, Token![;]>,
extra_genesis: &Option<AddExtraGenesis>,
where_clause: &Option<syn::WhereClause>,
) -> Result<TokenStream2> {
let InstanceOpts {
@@ -479,7 +489,26 @@ fn decl_store_extra_genesis(
let impl_trait = quote!(BuildModuleGenesisStorage<#traitinstance, #inherent_instance>);
let builders_clone_bound = quote!( #( #builders_clone_bound: Clone ),* );
let extend_where_clause = |to_extend: &mut WhereClause| {
if let Some(where_clause) = where_clause {
to_extend.predicates.extend(where_clause.predicates.iter().cloned());
}
};
let mut genesis_where_clause: WhereClause = syn::parse_quote!(
where #( #builders_clone_bound: Clone ),*
);
let mut fn_where_clause = genesis_where_clause.clone();
let mut build_storage_where_clause = genesis_where_clause.clone();
extend_where_clause(&mut build_storage_where_clause);
if is_trait_needed {
extend_where_clause(&mut genesis_where_clause);
} else if assimilate_require_generic {
extend_where_clause(&mut fn_where_clause);
}
let res = quote!{
#[derive(#scrate::Serialize, #scrate::Deserialize)]
@@ -487,13 +516,13 @@ fn decl_store_extra_genesis(
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
#serde_bug_bound
pub struct GenesisConfig#fparam_struct {
pub struct GenesisConfig#fparam_struct #genesis_where_clause {
#config_field
#genesis_extrafields
}
#[cfg(feature = "std")]
impl#fparam_impl Default for GenesisConfig#sparam {
impl#fparam_impl Default for GenesisConfig#sparam #genesis_where_clause {
fn default() -> Self {
GenesisConfig {
#config_field_default
@@ -503,14 +532,14 @@ fn decl_store_extra_genesis(
}
#[cfg(feature = "std")]
impl#fparam_impl GenesisConfig#sparam where #builders_clone_bound {
impl#fparam_impl GenesisConfig#sparam #genesis_where_clause {
pub fn build_storage #fn_generic (self) -> std::result::Result<
(
#scrate::runtime_primitives::StorageOverlay,
#scrate::runtime_primitives::ChildrenStorageOverlay,
),
String
> {
> #fn_where_clause {
let mut storage = Default::default();
let mut child_storage = Default::default();
self.assimilate_storage::<#fn_traitinstance>(&mut storage, &mut child_storage)?;
@@ -522,7 +551,7 @@ fn decl_store_extra_genesis(
self,
r: &mut #scrate::runtime_primitives::StorageOverlay,
c: &mut #scrate::runtime_primitives::ChildrenStorageOverlay,
) -> std::result::Result<(), String> {
) -> std::result::Result<(), String> #fn_where_clause {
let storage = r;
#builders
@@ -535,7 +564,7 @@ fn decl_store_extra_genesis(
#[cfg(feature = "std")]
impl#build_storage_impl #scrate::runtime_primitives::#impl_trait
for GenesisConfig#sparam where #builders_clone_bound
for GenesisConfig#sparam #build_storage_where_clause
{
fn build_module_genesis_storage(
self,
@@ -589,6 +618,7 @@ fn decl_storage_items(
instance_opts: &InstanceOpts,
cratename: &Ident,
storage_lines: &ext::Punctuated<DeclStorageLine, Token![;]>,
where_clause: &Option<WhereClause>,
) -> TokenStream2 {
let mut impls = TokenStream2::new();
@@ -728,6 +758,7 @@ fn decl_storage_items(
prefix: build_prefix(cratename, name),
name,
attrs,
where_clause,
};
let implementation = match kind {
@@ -899,6 +930,7 @@ fn store_functions_to_metadata (
traittype: &syn::TypeParamBound,
instance_opts: &InstanceOpts,
storage_lines: &ext::Punctuated<DeclStorageLine, Token![;]>,
where_clause: &Option<WhereClause>,
) -> (TokenStream2, TokenStream2) {
let InstanceOpts {
@@ -1008,12 +1040,18 @@ fn store_functions_to_metadata (
let def_get = quote! {
#[doc(hidden)]
pub struct #struct_name<#traitinstance, #instance #bound_instantiable #equal_default_instance>(pub #scrate::rstd::marker::PhantomData<(#traitinstance #comma_instance)>);
pub struct #struct_name<
#traitinstance, #instance #bound_instantiable #equal_default_instance
>(pub #scrate::rstd::marker::PhantomData<(#traitinstance #comma_instance)>);
#[cfg(feature = "std")]
#[allow(non_upper_case_globals)]
static #cache_name: #scrate::once_cell::sync::OnceCell<#scrate::rstd::vec::Vec<u8>> = #scrate::once_cell::sync::OnceCell::INIT;
#[cfg(feature = "std")]
impl<#traitinstance: #traittype, #instance #bound_instantiable> #scrate::metadata::DefaultByte for #struct_name<#traitinstance, #instance> {
impl<#traitinstance: #traittype, #instance #bound_instantiable> #scrate::metadata::DefaultByte
for #struct_name<#traitinstance, #instance> #where_clause
{
fn default_byte(&self) -> #scrate::rstd::vec::Vec<u8> {
use #scrate::codec::Encode;
#cache_name.get_or_init(|| {
@@ -1022,8 +1060,11 @@ fn store_functions_to_metadata (
}).clone()
}
}
#[cfg(not(feature = "std"))]
impl<#traitinstance: #traittype, #instance #bound_instantiable> #scrate::metadata::DefaultByte for #struct_name<#traitinstance, #instance> {
impl<#traitinstance: #traittype, #instance #bound_instantiable> #scrate::metadata::DefaultByte
for #struct_name<#traitinstance, #instance> #where_clause
{
fn default_byte(&self) -> #scrate::rstd::vec::Vec<u8> {
use #scrate::codec::Encode;
let def_val: #value_type = #default;
+161 -37
View File
@@ -183,6 +183,28 @@ impl<T> Parameter for T where T: Codec + Clone + Eq {}
/// # fn main() {}
/// ```
///
/// ## Where clause
///
/// Besides the default `origin: T::Origin`, you can also pass other bounds to the module declaration.
/// This where bound will be replicated to all types generated by this macro. The chaining of multiple
/// trait bounds with `+` is not supported. If multiple bounds for one type are required, it needs to
/// be split up into multiple bounds.
///
/// ```
/// # #[macro_use]
/// # extern crate srml_support;
/// # use srml_support::dispatch::Result;
/// # use srml_system::{self as system, ensure_signed};
/// pub trait Trait: system::Trait where Self::AccountId: From<u32> {}
///
/// decl_module! {
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
/// // Your implementation
/// }
/// }
/// # fn main() {}
/// ```
///
/// ## Reserved Functions
///
/// The following are reserved function signatures:
@@ -206,15 +228,21 @@ macro_rules! decl_module {
// Entry point #1.
(
$(#[$attr:meta])*
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)*
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 $(, $where_ty:ty: $where_bound:path )* {
$( $t:tt )*
}
) => {
$crate::decl_module!(@normalize
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
pub struct $mod_type<
$trait_instance: $trait_name $(<I>, I: $instantiable $(= $module_default_instance)?)?
>
for enum $call_type where origin: $origin_type, system = system
{ $( $where_ty: $where_bound ),* }
{}
{}
{}
@@ -227,15 +255,25 @@ macro_rules! decl_module {
// Entry point #2.
(
$(#[$attr:meta])*
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 {
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
$(, $where_ty:ty: $where_bound:path )*
{
$($t:tt)*
}
) => {
$crate::decl_module!(@normalize
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
pub struct $mod_type<
$trait_instance: $trait_name $(<I>, I: $instantiable $( = $module_default_instance )? )?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $where_ty: $where_bound ),* }
{}
{}
{}
@@ -251,6 +289,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{}
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -265,6 +304,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* () = default; }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -278,6 +318,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{}
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -294,6 +335,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* ($( $param_name: $param ),* ) { $( $impl )* } }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -307,6 +349,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{}
@@ -321,6 +364,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ fn on_finalize( $( $param_name : $param ),* ) { $( $impl )* } }
@@ -334,6 +378,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{}
@@ -352,6 +397,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{}
{ $( $on_finalize:tt )* }
@@ -366,6 +412,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ fn on_initialize( $( $param_name : $param ),* ) { $( $impl )* } }
{ $( $on_finalize )* }
@@ -379,6 +426,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{}
{ $( $on_finalize:tt )* }
@@ -400,6 +448,7 @@ macro_rules! decl_module {
$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?
>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -416,6 +465,7 @@ macro_rules! decl_module {
$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -434,6 +484,7 @@ macro_rules! decl_module {
$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?
>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -451,6 +502,7 @@ macro_rules! decl_module {
$( <I>, $instance: $instantiable $(= $module_default_instance)? )?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -473,6 +525,7 @@ macro_rules! decl_module {
$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?
>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -492,6 +545,7 @@ macro_rules! decl_module {
$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -517,6 +571,7 @@ macro_rules! decl_module {
$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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -535,6 +590,7 @@ macro_rules! decl_module {
$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?
>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -554,6 +610,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -578,6 +635,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -602,6 +660,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -619,6 +678,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -640,6 +700,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
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
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -653,6 +714,7 @@ macro_rules! decl_module {
for enum $call_type where origin: $origin_type, system = $system {
$( $dispatchables )*
}
{ $( $other_where_bounds )* }
{ $( $deposit_event )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
@@ -684,14 +746,18 @@ macro_rules! decl_module {
(@impl_deposit_event
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path)?>;
$system:ident;
{ $( $other_where_bounds:tt )* }
) => {};
(@impl_deposit_event
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
$system:ident;
{ $( $other_where_bounds:tt )* }
$vis:vis fn deposit_event$(<$event_trait_instance:ident $(, $event_instance:ident)?>)?() = default;
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
$vis fn deposit_event(event: Event$(<$event_trait_instance $(, $event_instance)?>)?) {
<$system::Module<$trait_instance>>::deposit_event(
<$trait_instance as $trait_name$(<$instance>)?>::Event::from(event).into()
@@ -703,9 +769,12 @@ macro_rules! decl_module {
(@impl_deposit_event
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
$system:ident;
{ $( $other_where_bounds:tt )* }
$vis:vis fn deposit_event($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
$vis fn deposit_event($param: $param_ty) {
$( $impl )*
}
@@ -714,11 +783,12 @@ macro_rules! decl_module {
(@impl_on_initialize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
{ $( $other_where_bounds:tt )* }
fn on_initialize() { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
}
@@ -726,11 +796,12 @@ macro_rules! decl_module {
(@impl_on_initialize
$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) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_initialize($param: $param_ty) { $( $impl )* }
}
@@ -738,20 +809,22 @@ macro_rules! decl_module {
(@impl_on_initialize
$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::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
(@impl_on_finalize
$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::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
}
@@ -759,11 +832,12 @@ macro_rules! decl_module {
(@impl_on_finalize
$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::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn on_finalize($param: $param_ty) { $( $impl )* }
}
@@ -771,21 +845,23 @@ macro_rules! decl_module {
(@impl_on_finalize
$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::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
}
};
(@impl_offchain
$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::runtime_primitives::traits::OffchainWorker<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn generate_extrinsics(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
}
@@ -793,11 +869,12 @@ macro_rules! decl_module {
(@impl_offchain
$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::runtime_primitives::traits::OffchainWorker<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{
fn generate_extrinsics($param: $param_ty) { $( $impl )* }
}
@@ -805,10 +882,11 @@ macro_rules! decl_module {
(@impl_offchain
$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::runtime_primitives::traits::OffchainWorker<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
for $module<$trait_instance$(, $instance)?> where $( $other_where_bounds )*
{}
};
@@ -884,6 +962,7 @@ macro_rules! decl_module {
$( #[$attr:meta] )*
$call_type:ident;
<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
{ $( $other_where_bounds:tt )* }
{ $( $generated_variants:tt )* }
{ $( $current_params:tt )* }
variant $fn_name:ident;
@@ -897,6 +976,7 @@ macro_rules! decl_module {
$( #[$attr] )*
$call_type;
<$trait_instance: $trait_name $(<I>, $instance: $instantiable $(= $module_default_instance)? )?>
{ $( $other_where_bounds )* }
{ $( $generated_variants )* }
{
$( $current_params )*
@@ -914,6 +994,7 @@ macro_rules! decl_module {
$( #[$attr:meta] )*
$call_type:ident;
<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
{ $( $other_where_bounds:tt )* }
{ $( $generated_variants:tt )* }
{ $( $current_params:tt )* }
variant $fn_name:ident;
@@ -926,6 +1007,7 @@ macro_rules! decl_module {
$( #[$attr] )*
$call_type;
<$trait_instance: $trait_name $(<I>, $instance: $instantiable $(= $module_default_instance)? )?>
{ $( $other_where_bounds )* }
{ $( $generated_variants )* }
{
$( $current_params )*
@@ -941,6 +1023,7 @@ macro_rules! decl_module {
$( #[$attr:meta] )*
$call_type:ident;
<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
{ $( $other_where_bounds:tt )* }
{ $( $generated_variants:tt )* }
{ $( $current_params:tt )* }
variant $fn_name:ident;
@@ -955,6 +1038,7 @@ macro_rules! decl_module {
$( #[$attr] )*
$call_type;
<$trait_instance: $trait_name $(<I>, $instance: $instantiable $(= $module_default_instance)? )?>
{ $( $other_where_bounds )* }
{
$( $generated_variants )*
#[allow(non_camel_case_types)]
@@ -975,12 +1059,15 @@ macro_rules! decl_module {
$( #[$attr:meta] )*
$call_type:ident;
<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
{ $( $other_where_bounds:tt )* }
{ $( $generated_variants:tt )* }
{}
) => {
#[derive($crate::codec::Encode, $crate::codec::Decode)]
$( #[$attr] )*
pub enum $call_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $( = $module_default_instance)?)?> {
pub enum $call_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $( = $module_default_instance)?)?>
where $( $other_where_bounds )*
{
#[doc(hidden)]
#[codec(skip)]
__PhantomItem($crate::rstd::marker::PhantomData<($trait_instance $(, $instance)?)>, $crate::dispatch::Never),
@@ -1006,6 +1093,7 @@ macro_rules! decl_module {
{ $($fn_instance:ident: $fn_instantiable:path)? }
)*
}
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
@@ -1020,36 +1108,43 @@ macro_rules! decl_module {
pub struct $mod_type<
$trait_instance: $trait_name
$(<I>, $instance: $instantiable $( = $module_default_instance)?)?
>($crate::rstd::marker::PhantomData<($trait_instance $(, $instance)?)>);
>($crate::rstd::marker::PhantomData<($trait_instance $(, $instance)?)>) where
$( $other_where_bounds )*;
$crate::decl_module! {
@impl_on_initialize
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $on_initialize )*
}
$crate::decl_module! {
@impl_on_finalize
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $on_finalize )*
}
$crate::decl_module! {
@impl_offchain
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
{ $( $other_where_bounds )* }
$( $offchain )*
}
$crate::decl_module! {
@impl_deposit_event
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
$system;
{ $( $other_where_bounds )* }
$( $deposit_event )*
}
/// Can also be called using [`Call`].
///
/// [`Call`]: enum.Call.html
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
$(
$crate::decl_module! {
@impl_function
@@ -1069,6 +1164,7 @@ macro_rules! decl_module {
$( #[$attr] )*
$call_type;
<$trait_instance: $trait_name $(<I>, $instance: $instantiable $(= $module_default_instance)? )?>
{ $( $other_where_bounds )* }
{}
{}
$(
@@ -1083,7 +1179,7 @@ macro_rules! decl_module {
// Implement weight calculation function for Call
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Weighable
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn weight(&self, _len: usize) -> $crate::dispatch::Weight {
match self {
@@ -1096,7 +1192,7 @@ 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 $(<I>, $instance: $instantiable)?> $crate::dispatch::Clone
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn clone(&self) -> Self {
match *self {
@@ -1109,7 +1205,7 @@ macro_rules! decl_module {
}
}
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::PartialEq
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn eq(&self, _other: &Self) -> bool {
match *self {
@@ -1131,12 +1227,12 @@ macro_rules! decl_module {
}
}
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Eq
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{}
#[cfg(feature = "std")]
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::fmt::Debug
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn fmt(
&self,
@@ -1156,7 +1252,7 @@ macro_rules! decl_module {
}
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Dispatchable
for $call_type<$trait_instance $(, $instance)?>
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
type Trait = $trait_instance;
type Origin = $origin_type;
@@ -1176,12 +1272,14 @@ macro_rules! decl_module {
}
}
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Callable<$trait_instance>
for $mod_type<$trait_instance $(, $instance)?>
for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
type Call = $call_type<$trait_instance $(, $instance)?>;
}
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
#[doc(hidden)]
pub fn dispatch<D: $crate::dispatch::Dispatchable<Trait = $trait_instance>>(
d: D,
@@ -1191,11 +1289,19 @@ macro_rules! decl_module {
}
}
$crate::__dispatch_impl_metadata! {
$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 )*); )*}
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>
{ $( $other_where_bounds )* }
$call_type $origin_type
{
$(
$(#[doc = $doc_attr])*
fn $fn_name($from $(, $(#[$codec_attr])* $param_name : $param )*);
)*
}
}
$crate::__impl_module_constants_metadata ! {
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>
{ $( $other_where_bounds )* }
$( $constants )*
}
}
@@ -1265,9 +1371,12 @@ macro_rules! impl_outer_dispatch {
macro_rules! __dispatch_impl_metadata {
(
$mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>
{ $( $other_where_bounds:tt )* }
$($rest:tt)*
) => {
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?> {
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $mod_type<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
#[doc(hidden)]
pub fn call_functions() -> &'static [$crate::dispatch::FunctionMetadata] {
$crate::__call_to_functions!($($rest)*)
@@ -1283,6 +1392,7 @@ macro_rules! __impl_module_constants_metadata {
// Without instance
(
$mod_type:ident<$trait_instance:ident: $trait_name:ident>
{ $( $other_where_bounds:tt )* }
$(
$( #[doc = $doc_attr:tt] )*
$name:ident: $type:ty = $value:expr;
@@ -1292,6 +1402,7 @@ macro_rules! __impl_module_constants_metadata {
$crate::__impl_module_constants_metadata! {
GENERATE_CODE
$mod_type<$trait_instance: $trait_name>
{ $( $other_where_bounds )* }
$(
$( #[doc = $doc_attr] )*
[< $name DefaultByteGetter >]
@@ -1303,6 +1414,7 @@ macro_rules! __impl_module_constants_metadata {
// With instance
(
$mod_type:ident<$trait_instance:ident: $trait_name:ident<I>, $instance:ident: $instantiable:path>
{ $( $other_where_bounds:tt )* }
$(
$( #[doc = $doc_attr:tt] )*
$name:ident: $type:ty = $value:expr;
@@ -1312,6 +1424,7 @@ macro_rules! __impl_module_constants_metadata {
$crate::__impl_module_constants_metadata! {
GENERATE_CODE
$mod_type<$trait_instance: $trait_name<I>, $instance: $instantiable>
{ $( $other_where_bounds )* }
$(
$( #[doc = $doc_attr] )*
[< $name DefaultByteGetter >]
@@ -1323,6 +1436,7 @@ macro_rules! __impl_module_constants_metadata {
// Do the code generation
(GENERATE_CODE
$mod_type:ident<$trait_instance:ident: $trait_name:ident $(<I>, $instance:ident: $instantiable:path)?>
{ $( $other_where_bounds:tt )* }
$(
$( #[doc = $doc_attr:tt] )*
$default_byte_name:ident
@@ -1334,7 +1448,7 @@ macro_rules! __impl_module_constants_metadata {
)*
) => {
impl<$trait_instance: 'static + $trait_name $(<I>, $instance: $instantiable)?>
$mod_type<$trait_instance $(, $instance)?>
$mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
#[doc(hidden)]
pub fn module_constants_metadata() -> &'static [$crate::dispatch::ModuleConstantMetadata] {
@@ -1391,14 +1505,16 @@ macro_rules! __impl_module_constants_metadata {
macro_rules! __call_to_functions {
(
$call_type:ident $origin_type:ty
{$(
{
$(
$(#[doc = $doc_attr:tt])*
fn $fn_name:ident($from:ident
$(
, $(#[$codec_attr:ident])* $param_name:ident : $param:ty
)*
);
)*}
)*
}
) => {
$crate::__functions_to_metadata!(0; $origin_type;; $(
fn $fn_name( $($(#[$codec_attr])* $param_name: $param ),* );
@@ -1523,7 +1639,7 @@ mod tests {
use super::*;
use crate::runtime_primitives::traits::{OnInitialize, OnFinalize};
pub trait Trait: Sized {
pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> {
type Origin;
type BlockNumber: Into<u32>;
type Call: From<Call<Self>>;
@@ -1532,13 +1648,17 @@ mod tests {
pub mod system {
use super::Result;
pub trait Trait {
type AccountId;
}
pub fn ensure_root<R>(_: R) -> Result {
Ok(())
}
}
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, T::AccountId: From<u32> {
/// Hi, this is a comment.
fn aux_0(_origin) -> Result { unreachable!() }
fn aux_1(_origin, #[compact] _data: u32) -> Result { unreachable!() }
@@ -1641,6 +1761,10 @@ mod tests {
}
}
impl system::Trait for TraitImpl {
type AccountId = u32;
}
#[test]
fn module_json_metadata() {
let metadata = Module::<TraitImpl>::call_functions();
+31 -10
View File
@@ -37,14 +37,18 @@ pub trait Currency {}
mod module1 {
use super::*;
pub trait Trait<I>: system::Trait {
pub trait Trait<I>: system::Trait where <Self as system::Trait>::BlockNumber: From<u32> {
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
type Origin: From<Origin<Self, I>>;
type SomeParameter: Get<u32>;
type GenericType: Default + Clone + parity_codec::Codec;
}
srml_support::decl_module! {
pub struct Module<T: Trait<I>, I: InstantiableThing> for enum Call where origin: <T as system::Trait>::Origin {
pub struct Module<T: Trait<I>, I: InstantiableThing> for enum Call where
origin: <T as system::Trait>::Origin,
T::BlockNumber: From<u32>
{
fn offchain_worker() {}
fn deposit_event<T, I>() = default;
@@ -56,11 +60,20 @@ mod module1 {
}
srml_support::decl_storage! {
trait Store for Module<T: Trait<I>, I: InstantiableThing> as Module1 {
pub Value config(value): u64;
trait Store for Module<T: Trait<I>, I: InstantiableThing> as Module1 where
T::BlockNumber: From<u32> + std::fmt::Display
{
pub Value config(value): T::GenericType;
pub Map: map u32 => u64;
pub LinkedMap: linked_map u32 => u64;
}
add_extra_genesis {
config(test) : T::BlockNumber;
build(|_, _, config: &Self| {
println!("{}", config.test);
});
}
}
srml_support::decl_event! {
@@ -72,14 +85,16 @@ mod module1 {
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Origin<T: Trait<I>, I> {
pub enum Origin<T: Trait<I>, I> where T::BlockNumber: From<u32> {
Members(u32),
_Phantom(std::marker::PhantomData<(T, I)>),
}
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"12345678";
impl<T: Trait<I>, I: InstantiableThing> ProvideInherent for Module<T, I> {
impl<T: Trait<I>, I: InstantiableThing> ProvideInherent for Module<T, I> where
T::BlockNumber: From<u32>
{
type Call = Call<T, I>;
type Error = MakeFatalError<RuntimeString>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
@@ -88,7 +103,7 @@ mod module1 {
unimplemented!();
}
fn check_inherent(_call: &Self::Call, _data: &InherentData) -> std::result::Result<(), Self::Error> {
fn check_inherent(_: &Self::Call, _: &InherentData) -> std::result::Result<(), Self::Error> {
unimplemented!();
}
}
@@ -109,7 +124,9 @@ mod module2 {
impl<T: Trait<I>, I: Instance> Currency for Module<T, I> {}
srml_support::decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as system::Trait>::Origin {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Trait>::Origin
{
fn deposit_event<T, I>() = default;
}
}
@@ -176,11 +193,13 @@ impl module1::Trait<module1::Instance1> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type GenericType = u32;
}
impl module1::Trait<module1::Instance2> for Runtime {
type Event = Event;
type Origin = Origin;
type SomeParameter = SomeValue;
type GenericType = u32;
}
impl module2::Trait for Runtime {
type Amount = u16;
@@ -228,10 +247,10 @@ srml_support::construct_runtime!(
{
System: system::{Module, Call, Event},
Module1_1: module1::<Instance1>::{
Module, Call, Storage, Event<T>, Config, Origin<T>, Inherent
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module1_2: module1::<Instance2>::{
Module, Call, Storage, Event<T>, Config, Origin<T>, Inherent
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module2: module2::{Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent},
Module2_1: module2::<Instance1>::{
@@ -255,9 +274,11 @@ fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
GenesisConfig{
module1_Instance1: Some(module1::GenesisConfig {
value: 3,
test: 2,
}),
module1_Instance2: Some(module1::GenesisConfig {
value: 4,
test: 5,
}),
module2: Some(module2::GenesisConfig {
value: 4,