Implement a proper generic resolution in decl_storage! (#2913)

* Add failing test case

* move storage maps to blake2_128 (#2268)

* remove default hash, introduce twox_128 and blake2

* use blake2_128 & create ext_blake2_128

* refactor code

* add benchmark

* factorize generator

* fix

* parameterizable hasher

* some fix

* fix

* fix

* fix

* metadata

* fix

* remove debug print

* map -> blake2_256

* fix test

* fix test

* Apply suggestions from code review

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* impl twox 128 concat (#2353)

* impl twox_128_concat

* comment addressed

* fix

* impl twox_128->64_concat

* fix test

* Fix compilation and cleanup some docs

* Lol

* Remove traits from storage types that are not generic

* Get instance test almost working as wanted

* Make `srml-support-test` compile again :)

* Fixes test of srml-support

* Fix compilation

* Break some lines

* Remove incorrect macro match arm

* Integrates review feedback

* Update documentation

* Fix compilation
This commit is contained in:
Bastian Köcher
2019-06-27 13:40:22 +02:00
committed by GitHub
parent 23ea5d1795
commit 62b7c05def
55 changed files with 1441 additions and 860 deletions
+84 -32
View File
@@ -321,17 +321,15 @@ macro_rules! __events_to_metadata {
}
/// Constructs an Event type for a runtime. This is usually called automatically by the
/// construct_runtime macro. See also __create_decl_macro.
/// construct_runtime macro.
#[macro_export]
macro_rules! impl_outer_event {
// Macro transformations (to convert invocations with incomplete parameters to the canonical
// form)
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident {
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
$( $rest_event_without_system:tt )*
}
) => {
$crate::impl_outer_event!(
@@ -339,14 +337,14 @@ macro_rules! impl_outer_event {
$name;
$runtime;
system;
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
Modules { $( $rest_event_without_system )* };
;
);
};
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident where system = $system:ident {
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
$( $rest_event_with_system:tt )*
}
) => {
$crate::impl_outer_event!(
@@ -354,30 +352,74 @@ macro_rules! impl_outer_event {
$name;
$runtime;
$system;
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
Modules { $( $rest_event_with_system )* };
;
);
};
// Generic + Instance
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident<T $(, $instance:path)? >,
$( $rest:tt $( <$t:ident $(, $rest_instance:path)? > )*, )*
$module:ident $instance:ident<T>,
$( $rest_event_generic_instance:tt )*
};
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $rest $(<$t $(, $rest_instance)? >)*, )* };
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )* $module::Event<$runtime $(, $instance)? >,;
Modules { $( $rest_event_generic_instance )* };
$( $module_name::Event $( <$generic_param> )? $( { $generic_instance } )?, )* $module::Event<$runtime>{ $instance },;
);
};
// Instance
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident $instance:ident,
$( $rest_event_instance:tt )*
};
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $rest_event_instance )* };
$( $module_name::Event $( <$generic_param> )* $( { $generic_instance } )?, )* $module::Event { $instance },;
);
};
// Generic
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident<T>,
$( $rest_event_generic:tt )*
};
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $rest_event_generic )* };
$( $module_name::Event $( <$generic_param> )? $( { $generic_instance } )?, )* $module::Event<$runtime>,;
);
};
// No Generic and no Instance
(
$(#[$attr:meta])*;
$name:ident;
@@ -385,30 +427,30 @@ macro_rules! impl_outer_event {
$system:ident;
Modules {
$module:ident,
$( $rest:tt )*
$( $rest_event_no_generic_no_instance:tt )*
};
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $rest )* };
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )* $module::Event,;
Modules { $( $rest_event_no_generic_no_instance )* };
$( $module_name::Event $( <$generic_param> )? $( { $generic_instance } )?, )* $module::Event,;
);
};
// The main macro expansion that actually renders the Event enum code.
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {};
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::paste::item! {
// 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))]
@@ -417,7 +459,9 @@ macro_rules! impl_outer_event {
pub enum $name {
system($system::Event),
$(
$module_name( $module_name::Event $( <$generic_param $(, $generic_instance)? > )* ),
[< $module_name $(_ $generic_instance )? >](
$module_name::Event < $( $generic_param )? $(, $module_name::$generic_instance )? >
),
)*
}
impl From<$system::Event> for $name {
@@ -426,17 +470,22 @@ macro_rules! impl_outer_event {
}
}
$(
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)
impl From<$module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >> for $name {
fn from(x: $module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >) -> Self {
$name::[< $module_name $(_ $generic_instance )? >](x)
}
}
)*
}
$crate::__impl_outer_event_json_metadata!(
$runtime;
$name;
$system;
$( $module_name::Event $( <$generic_param $(, $generic_instance)? > )*, )*;
$(
$module_name::Event
< $( $generic_param )? $(, $module_name::$generic_instance )? >
$( $generic_instance )?,
)*;
);
}
}
@@ -448,7 +497,7 @@ macro_rules! __impl_outer_event_json_metadata {
$runtime:ident;
$event_name:ident;
$system:ident;
$( $module_name:ident::Event $( <$generic_param:ident $(, $generic_instance:path)? > )*, )*;
$( $module_name:ident::Event < $( $generic_params:path ),* > $( $instance:ident )?, )*;
) => {
impl $runtime {
#[allow(dead_code)]
@@ -461,7 +510,7 @@ macro_rules! __impl_outer_event_json_metadata {
, (
stringify!($module_name),
$crate::event::FnEncode(
$module_name::Event $( ::<$generic_param $(, $generic_instance)? > )* ::metadata
$module_name::Event ::< $( $generic_params ),* > ::metadata
)
)
)*
@@ -472,14 +521,17 @@ macro_rules! __impl_outer_event_json_metadata {
pub fn __module_events_system() -> &'static [$crate::event::EventMetadata] {
system::Event::metadata()
}
$(
#[allow(dead_code)]
$crate::paste::item!{
pub fn [< __module_events_ $module_name >] () -> &'static [$crate::event::EventMetadata] {
$module_name::Event $( ::<$generic_param $(, $generic_instance)? > )* ::metadata()
$crate::paste::item! {
$(
#[allow(dead_code)]
pub fn [< __module_events_ $module_name $( _ $instance )? >] () ->
&'static [$crate::event::EventMetadata]
{
$module_name::Event ::< $( $generic_params ),* > ::metadata()
}
}
)*
)*
}
}
}
}
+7 -8
View File
@@ -34,7 +34,9 @@ pub use once_cell;
pub use paste;
pub use sr_primitives as runtime_primitives;
pub use self::storage::hashed::generator::{HashedStorage, Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat};
pub use self::storage::hashed::generator::{
HashedStorage, Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat
};
pub use self::storage::unhashed::generator::UnhashedStorage;
#[macro_use]
@@ -239,7 +241,6 @@ mod tests {
use super::*;
use codec::Codec;
use runtime_io::{with_externalities, Blake2Hasher};
use runtime_primitives::BuildStorage;
pub use srml_metadata::{
DecodeDifferent, StorageMetadata, StorageFunctionMetadata,
StorageFunctionType, StorageFunctionModifier,
@@ -258,9 +259,7 @@ mod tests {
use super::Trait;
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 {}
}
}
use self::module::Module;
@@ -286,10 +285,10 @@ mod tests {
}
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
GenesisConfig::default().build_storage().unwrap().0.into()
}
type Map = Data<Test>;
type Map = Data;
#[test]
fn linked_map_basic_insert_remove_should_work() {
@@ -372,7 +371,7 @@ mod tests {
#[test]
fn double_map_basic_insert_remove_remove_prefix_should_work() {
with_externalities(&mut new_test_ext(), || {
type DoubleMap = DataDM<Test>;
type DoubleMap = DataDM;
// initialized during genesis
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
+112 -40
View File
@@ -24,24 +24,24 @@ macro_rules! impl_outer_origin {
// Macro transformations (to convert invocations with incomplete parameters to the canonical
// form)
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident {
$( $module:ident $( <$generic:ident $(, $instance:path )? > )? ),* $(,)?
$( $rest_without_system:tt )*
}
) => {
$crate::impl_outer_origin! {
$(#[$attr])*
pub enum $name for $runtime where system = system {
$( $module $( <$generic $(, $instance )? > )?, )*
$( $rest_without_system )*
}
}
};
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident where system = $system:ident {
$( $module:ident $( <$generic:ident $(, $instance:path )?> )? ),* $(,)?
$( $rest_with_system:tt )*
}
) => {
$crate::impl_outer_origin!(
@@ -49,20 +49,41 @@ macro_rules! impl_outer_origin {
$name;
$runtime;
$system;
Modules { $( $module $( <$generic $(, $instance )? > )*, )* };
Modules { $( $rest_with_system )* };
);
};
// Replace generic param with runtime
// Generic + Instance
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident $( <T $(, $instance:path )? > )?,
$( $rest_module:tt )*
$module:ident $instance:ident <T>
$(, $( $rest_module:tt )* )?
};
$( $parsed:tt )*
) => {
$crate::impl_outer_origin!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $( $rest_module )* )? };
$( $parsed )* $module <$runtime> { $instance },
);
};
// Instance
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident $instance:ident
$(, $rest_module:tt )*
};
$( $parsed:tt )*
) => {
@@ -72,33 +93,80 @@ macro_rules! impl_outer_origin {
$runtime;
$system;
Modules { $( $rest_module )* };
$( $parsed )* $module $( <$runtime $(, $instance )? > )?,
$( $parsed )* $module { $instance },
);
};
// Generic
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident <T>
$(, $( $rest_module:tt )* )?
};
$( $parsed:tt )*
) => {
$crate::impl_outer_origin!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $( $rest_module )* )? };
$( $parsed )* $module <$runtime>,
);
};
// No Generic and no Instance
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules {
$module:ident
$(, $( $rest_module:tt )* )?
};
$( $parsed:tt )*
) => {
$crate::impl_outer_origin!(
$( #[$attr] )*;
$name;
$runtime;
$system;
Modules { $( $( $rest_module )* )? };
$( $parsed )* $module,
);
};
// The main macro expansion that actually renders the Origin enum code.
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
$system:ident;
Modules { };
$( $module:ident $( <$generic_param:ident $(, $generic_instance:path )? > )* ,)*
$( $module:ident $( < $generic:ident > )? $( { $generic_instance:ident } )? ,)*
) => {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum $name {
system($system::Origin<$runtime>),
$(
$module($module::Origin $( <$generic_param $(, $generic_instance )? > )* ),
)*
#[allow(dead_code)]
Void($crate::Void)
$crate::paste::item! {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum $name {
system($system::Origin<$runtime>),
$(
[< $module $( _ $generic_instance )? >]
($module::Origin < $( $generic, )? $( $module::$generic_instance )? > ),
)*
#[allow(dead_code)]
Void($crate::Void)
}
}
#[allow(dead_code)]
impl $name {
pub const NONE: Self = $name::system($system::RawOrigin::None);
@@ -127,23 +195,27 @@ macro_rules! impl_outer_origin {
}
}
$(
impl From<$module::Origin $( <$generic_param $(, $generic_instance )? > )*> for $name {
fn from(x: $module::Origin $( <$generic_param $(, $generic_instance )? > )*) -> Self {
$name::$module(x)
$crate::paste::item! {
impl From<$module::Origin < $( $generic )? $(, $module::$generic_instance )? > > for $name {
fn from(x: $module::Origin < $( $generic )? $(, $module::$generic_instance )? >) -> Self {
$name::[< $module $( _ $generic_instance )? >](x)
}
}
}
impl Into<$crate::rstd::result::Result<
$module::Origin $( <$generic_param $(, $generic_instance )? > )*,
$name
>> for $name {
fn into(self) -> $crate::rstd::result::Result<
$module::Origin $( <$generic_param $(, $generic_instance )? > )*,
Self
> {
if let $name::$module(l) = self {
Ok(l)
} else {
Err(self)
impl Into<
$crate::rstd::result::Result<
$module::Origin < $( $generic )? $(, $module::$generic_instance )? >,
$name,
>>
for $name {
fn into(self) -> $crate::rstd::result::Result<
$module::Origin < $( $generic )? $(, $module::$generic_instance )? >,
Self,
> {
if let $name::[< $module $( _ $generic_instance )? >](l) = self {
Ok(l)
} else {
Err(self)
}
}
}
}
+58 -89
View File
@@ -61,9 +61,9 @@
/// - `Module`
/// - `Call`
/// - `Storage`
/// - `Event` or `Event<T>` (if the event is generic) or `Event<T, I>` (if also over instance)
/// - `Origin` or `Origin<T>` (if the origin is generic) or `Origin<T, I>` (if also over instance)
/// - `Config` or `Config<T>` (if the config is generic) or `Config<T, I>` (if also over instance)
/// - `Event` or `Event<T>` (if the event is generic)
/// - `Origin` or `Origin<T>` (if the origin is generic)
/// - `Config` or `Config<T>` (if the config is generic)
/// - `Inherent $( (CALL) )*` - If the module provides/can check inherents. The optional parameter
/// is for modules that use a `Call` from a different module as
/// inherent.
@@ -101,6 +101,7 @@ macro_rules! construct_runtime {
$( $rest )*
);
};
// No modules given, expand to the default module set.
(
{ $( $preset:tt )* };
{ $( $expanded:tt )* };
@@ -114,6 +115,7 @@ macro_rules! construct_runtime {
$( $rest )*
);
};
// `default` identifier given, expand to default + given extra modules
(
{ $( $preset:tt )* };
{ $( $expanded:tt )* };
@@ -121,7 +123,7 @@ macro_rules! construct_runtime {
default
$(,
$modules:ident
$( <$modules_generic:ident $(, $modules_instance:ident)?> )*
$( <$modules_generic:ident> )*
$( ( $( $modules_args:ident ),* ) )*
)*
},
@@ -129,21 +131,24 @@ macro_rules! construct_runtime {
) => {
$crate::construct_runtime!(
{ $( $preset )* };
{ $( $expanded )* };
$name: $module::{
Module, Call, Storage, Event<T>, Config<T>
$(,
$modules $( <$modules_generic $(, $modules_instance)?> )*
$( ( $( $modules_args ),* ) )*
)*
},
{
$( $expanded )*
$name: $module::{
Module, Call, Storage, Event<T>, Config<T>
$(,
$modules $( <$modules_generic> )*
$( ( $( $modules_args ),* ) )*
)*
},
};
$( $rest )*
);
};
// Take all modules as given by the user.
(
{ $( $preset:tt )* };
{ $( $expanded:tt )* };
$name:ident: $module:ident::{
$name:ident: $module:ident :: $( < $module_instance:ident >:: )? {
$(
$modules:ident
$( <$modules_generic:ident> )*
@@ -156,7 +161,7 @@ macro_rules! construct_runtime {
{ $( $preset )* };
{
$( $expanded )*
$name: $module::{
$name: $module:: $( < $module_instance >:: )? {
$(
$modules $( <$modules_generic> )*
$( ( $( $modules_args ),* ) )*
@@ -166,35 +171,7 @@ macro_rules! construct_runtime {
$( $rest )*
);
};
( // Instance module: we indicate the generic instance `I` with the full instance path
{ $( $preset:tt )* };
{ $( $expanded:tt )* };
$name:ident: $module:ident ::< $module_instance:ident >::{
$(
$modules:ident
$( <$modules_generic:ident $(, $modules_instance:ident )?> )*
$( ( $( $modules_args:ident ),* ) )*
),*
},
$( $rest:tt )*
) => {
$crate::construct_runtime!(
{ $( $preset )* };
{
$( $expanded )*
$name: $module::<$module_instance>::{
$(
$modules $( <$modules_generic $(, $modules_instance=$module::$module_instance)?> )*
$( ( $( $modules_args ),* ) )*
),*
},
};
$( $rest )*
);
};
// The main macro expansion that actually renders the Runtime code.
(
{
$runtime:ident;
@@ -207,7 +184,7 @@ macro_rules! construct_runtime {
$name:ident: $module:ident :: $( < $module_instance:ident >:: )? {
$(
$modules:ident
$( <$modules_generic:ident $(, I=$modules_instance:path)?> )*
$( <$modules_generic:ident> )*
$( ( $( $modules_args:ident ),* ) )*
),*
},
@@ -223,19 +200,20 @@ macro_rules! construct_runtime {
impl $crate::runtime_primitives::traits::GetRuntimeBlockType for $runtime {
type RuntimeBlock = $block;
}
$crate::__decl_instance_import!(
$( $( $module < $module_instance > )? )*
);
$crate::__decl_outer_event!(
$runtime;
$(
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* }
$name: $module:: $( < $module_instance >:: )? {
$( $modules $( <$modules_generic> )* ),*
}
),*
);
$crate::__decl_outer_origin!(
$runtime;
$(
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* }
$name: $module:: $( < $module_instance >:: )? {
$( $modules $( <$modules_generic> )* ),*
}
),*
);
$crate::__decl_all_modules!(
@@ -265,7 +243,7 @@ macro_rules! construct_runtime {
{};
$(
$name: $module:: $( < $module_instance >:: )? {
$( $modules $( <$modules_generic $(, $modules_instance)?> )* ),*
$( $modules $( <$modules_generic> )* ),*
},
)*
);
@@ -307,7 +285,7 @@ macro_rules! __create_decl_macro {
(
$runtime:ident;
$d( $name:ident : $module:ident:: $d( < $module_instance:ident >:: )? {
$d( $modules:ident $d( <$modules_generic:ident $d(, $modules_instance:path)?> ),* ),*
$d( $modules:ident $d( <$modules_generic:ident> ),* ),*
}),*
) => {
$d crate::$macro_name!(@inner
@@ -316,7 +294,7 @@ macro_rules! __create_decl_macro {
{};
$d(
$name: $module:: $d( < $module_instance >:: )? {
$d( $modules $d( <$modules_generic $d(, $modules_instance)?> )* ),*
$d( $modules $d( <$modules_generic> )* ),*
},
)*
);
@@ -342,7 +320,7 @@ macro_rules! __create_decl_macro {
$d( $system:ident )?;
{ $d( $parsed:tt )* };
$name:ident : $module:ident:: < $module_instance:ident >:: {
$macro_enum_name <$event_generic:ident, $event_instance:path> $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
$macro_enum_name <$event_generic:ident> $d(, $ingore:ident $d( <$ignor:ident> )* )*
},
$d( $rest:tt )*
) => {
@@ -351,33 +329,17 @@ macro_rules! __create_decl_macro {
$d( $system )?;
{
$d( $parsed )*
$module $module_instance <$event_generic, $event_instance>,
$module $module_instance <$event_generic>,
};
$d( $rest )*
);
};
(@inner
$runtime:ident;
$d( $system:ident )?;
{ $d( $parsed:tt )* };
$name:ident : $module:ident:: < $module_instance:ident >:: {
$macro_enum_name $d( <$event_generic:ident> )* $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
},
$d( $rest:tt )*
) => {
compile_error!{concat!{
"Module `", stringify!{$name}, "` must have `", stringify!{$macro_enum_name}, "<T, I>`",
" but has `", stringify!{$macro_enum_name} $d(, "<", stringify!{$event_generic}, ">")*, "`",
": Instantiated modules must have ", stringify!{$macro_enum_name},
" generic over instance to be able to convert to outer ", stringify!{$macro_enum_name}
}}
};
(@inner
$runtime:ident;
$d( $system:ident )?;
{ $d( $parsed:tt )* };
$name:ident : $module:ident:: {
$macro_enum_name $d( <$event_generic:ident $d(, $event_instance:path)?> )* $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
$macro_enum_name $d( <$event_generic:ident> )* $d(, $ignore:ident $d( <$ignor:ident> )* )*
},
$d( $rest:tt )*
) => {
@@ -386,7 +348,7 @@ macro_rules! __create_decl_macro {
$d( $system )?;
{
$d( $parsed )*
$module $d( <$event_generic $d(, $event_instance)?> )*,
$module $d( <$event_generic> )*,
};
$d( $rest )*
);
@@ -396,7 +358,7 @@ macro_rules! __create_decl_macro {
$d( $system:ident )?;
{ $d( $parsed:tt )* };
$name:ident : $module:ident:: $d( < $module_instance:ident >:: )? {
$ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* $d(, $modules:ident $d( <$modules_generic:ident $d(, $modules_instance:path)?> )* )*
$ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )*
},
$d( $rest:tt )*
) => {
@@ -404,7 +366,7 @@ macro_rules! __create_decl_macro {
$runtime;
$d( $system )?;
{ $d( $parsed )* };
$name: $module:: $d( < $module_instance >:: )? { $d( $modules $d( <$modules_generic $d(, $modules_instance)?> )* ),* },
$name: $module:: $d( < $module_instance >:: )? { $d( $modules $d( <$modules_generic> )* ),* },
$d( $rest )*
);
};
@@ -425,16 +387,13 @@ macro_rules! __create_decl_macro {
(@inner
$runtime:ident;
$system:ident;
{ $d( $parsed_modules:ident $d( $instance:ident )? $d( <$parsed_generic:ident $d(, $parsed_instance_full_path:path)?> )* ,)* };
{ $d( $parsed_modules:ident $d( $instance:ident )? $d( <$parsed_generic:ident> )? ,)* };
) => {
$d crate::paste::item! {
$d crate::$macro_outer_name! {
pub enum $macro_enum_name for $runtime where system = $system {
$d(
[< $parsed_modules $d(_ $instance )? >] $d( <$parsed_generic $d(, $parsed_instance_full_path)?> )*,
)*
}
$d crate::$macro_outer_name! {
pub enum $macro_enum_name for $runtime where system = $system {
$d(
$parsed_modules $d( $instance )? $d( <$parsed_generic> )?,
)*
}
}
}
@@ -668,7 +627,7 @@ macro_rules! __decl_runtime_metadata {
}
}
/// A private macro that generates GenesisConfig for the runtime. See impl_outer_config macro.
/// A private macro that generates GenesisConfig for the runtime. See `impl_outer_config!` macro.
#[macro_export]
#[doc(hidden)]
macro_rules! __decl_outer_config {
@@ -676,7 +635,8 @@ macro_rules! __decl_outer_config {
$runtime:ident;
{ $( $parsed:tt )* };
$name:ident: $module:ident:: $( < $module_instance:ident >:: )? {
Config $(< $config_generic:ident $(, $config_instance:path)?>)? $(, $modules:ident $( <$modules_generic:ident $(, $modules_instance:path)?> )* )*
Config $( <$config_generic:ident> )?
$(, $modules:ident $( <$modules_generic:ident> )* )*
},
$( $rest:tt )*
) => {
@@ -684,7 +644,7 @@ macro_rules! __decl_outer_config {
$runtime;
{
$( $parsed )*
$module::$name $( $module_instance )? $(<$config_generic $(, $config_instance)?>)?,
$module::$name $( $module_instance )? $( <$config_generic> )?,
};
$( $rest )*
);
@@ -693,14 +653,15 @@ macro_rules! __decl_outer_config {
$runtime:ident;
{ $( $parsed:tt )* };
$name:ident: $module:ident:: $( < $module_instance:ident >:: )? {
$ignore:ident $( <$ignor:ident $(, $ignore_instance:path)?> )* $(, $modules:ident $( <$modules_generic:ident $(, $modules_instance:path)?> )* )*
$ingore:ident $( <$ignore_gen:ident> )*
$(, $modules:ident $( <$modules_generic:ident> )* )*
},
$( $rest:tt )*
) => {
$crate::__decl_outer_config!(
$runtime;
{ $( $parsed )* };
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* },
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic> )* ),* },
$( $rest )*
);
};
@@ -718,13 +679,21 @@ macro_rules! __decl_outer_config {
};
(
$runtime:ident;
{$( $parsed_modules:ident :: $parsed_name:ident $( $parsed_instance:ident )? $( < $parsed_generic:ident $(, $parsed_instance_full_path:path)? > )* ,)* };
{
$(
$parsed_modules:ident :: $parsed_name:ident $( $parsed_instance:ident )?
$(
<$parsed_generic:ident>
)*
,)*
};
) => {
$crate::paste::item! {
$crate::runtime_primitives::impl_outer_config!(
pub struct GenesisConfig for $runtime {
$(
[< $parsed_name Config >] => [< $parsed_modules $( _ $parsed_instance)? >] $( < $parsed_generic $(, $parsed_instance_full_path)? > )*,
[< $parsed_name Config >] =>
$parsed_modules $( $parsed_instance )? $( <$parsed_generic> )*,
)*
}
);
@@ -346,7 +346,7 @@ mod tests {
// getters: pub / $default
// we need at least one type which uses T, otherwise GenesisConfig will complain.
GETU32 get(u32_getter): T::Origin;
pub PUBGETU32 get(pub_u32_getter) build(|config: &GenesisConfig<T>| config.u32_getter_with_config): u32;
pub PUBGETU32 get(pub_u32_getter) build(|config: &GenesisConfig| config.u32_getter_with_config): u32;
GETU32WITHCONFIG get(u32_getter_with_config) config(): u32;
pub PUBGETU32WITHCONFIG get(pub_u32_getter_with_config) config(): u32;
GETU32MYDEF get(u32_getter_mydef): Option<u32> = Some(4);
@@ -716,7 +716,7 @@ mod tests {
#[test]
fn check_genesis_config() {
let config = GenesisConfig::<TraitImpl>::default();
let config = GenesisConfig::default();
assert_eq!(config.u32_getter_with_config, 0u32);
assert_eq!(config.pub_u32_getter_with_config, 0u32);
@@ -820,13 +820,13 @@ mod test_map_vec_append {
use runtime_io::{with_externalities, TestExternalities};
with_externalities(&mut TestExternalities::default(), || {
let _ = <MapVec<Test>>::append(1, &[1, 2, 3]);
let _ = <MapVec<Test>>::append(1, &[4, 5]);
assert_eq!(<MapVec<Test>>::get(1), vec![1, 2, 3, 4, 5]);
let _ = MapVec::append(1, &[1, 2, 3]);
let _ = MapVec::append(1, &[4, 5]);
assert_eq!(MapVec::get(1), vec![1, 2, 3, 4, 5]);
let _ = <JustVec<Test>>::append(&[1, 2, 3]);
let _ = <JustVec<Test>>::append(&[4, 5]);
assert_eq!(<JustVec<Test>>::get(), vec![1, 2, 3, 4, 5]);
let _ = JustVec::append(&[1, 2, 3]);
let _ = JustVec::append(&[4, 5]);
assert_eq!(JustVec::get(), vec![1, 2, 3, 4, 5]);
});
}
}