Merge metadata by module (#1428)

Clean up metadata format. Merge events metadata into runtime metadata. Remove low value info (internal macro identifier and counters).
This commit is contained in:
cheme
2019-01-30 19:34:08 +01:00
committed by GitHub
parent 742f030ddd
commit ea2a03b7bb
15 changed files with 486 additions and 382 deletions
+15 -77
View File
@@ -23,8 +23,8 @@ pub use std::fmt;
pub use rstd::result;
pub use codec::{Codec, Decode, Encode, Input, Output, HasCompact, EncodeAsRef};
pub use srml_metadata::{
ModuleMetadata, FunctionMetadata, DecodeDifferent,
CallMetadata, FunctionArgumentMetadata, OuterDispatchMetadata, OuterDispatchCall
FunctionMetadata, DecodeDifferent, DecodeDifferentArray,
FunctionArgumentMetadata, OuterDispatchMetadata, OuterDispatchCall
};
/// Result of a module function call; either nothing (functions are only called for "side efeects")
@@ -175,7 +175,7 @@ macro_rules! decl_module {
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $deposit_event:tt )* }
{}
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -827,7 +827,6 @@ macro_rules! impl_outer_dispatch {
}
}
)*
__impl_outer_dispatch_metadata!($runtime; $call_type; $( $module::$camelcase, )*);
}
}
@@ -853,50 +852,6 @@ macro_rules! __impl_outer_dispatch_common {
}
}
/// Implement metadata for outer dispatch.
#[macro_export]
#[doc(hidden)]
macro_rules! __impl_outer_dispatch_metadata {
(
$runtime:ident;
$outer_name:ident;
$( $module:ident::$call:ident, )*
) => {
impl $runtime {
pub fn outer_dispatch_metadata() -> $crate::dispatch::OuterDispatchMetadata {
$crate::dispatch::OuterDispatchMetadata {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($outer_name)),
calls: __impl_outer_dispatch_metadata!(@encode_calls 0; ; $( $module::$call, )*),
}
}
}
};
(@encode_calls
$index:expr;
$( $encoded_call:expr ),*;
$module:ident::$call:ident,
$( $rest_module:ident::$rest:ident, )*
) => {
__impl_outer_dispatch_metadata!(
@encode_calls
$index + 1;
$( $encoded_call, )*
$crate::dispatch::OuterDispatchCall {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call)),
prefix: $crate::dispatch::DecodeDifferent::Encode(stringify!($module)),
index: $index,
};
$( $rest_module::$rest, )*
)
};
(@encode_calls
$index:expr;
$( $encoded_call:expr ),*;
) => {
$crate::dispatch::DecodeDifferent::Encode(&[ $( $encoded_call ),* ])
};
}
/// Implement metadata for dispatch.
#[macro_export]
#[doc(hidden)]
@@ -906,11 +861,8 @@ macro_rules! __dispatch_impl_metadata {
$($rest:tt)*
) => {
impl<$trait_instance: $trait_name> $mod_type<$trait_instance> {
pub fn metadata() -> $crate::dispatch::ModuleMetadata {
$crate::dispatch::ModuleMetadata {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($mod_type)),
call: __call_to_metadata!($($rest)*),
}
pub fn call_functions() -> &'static [$crate::dispatch::FunctionMetadata] {
__call_to_functions!($($rest)*)
}
}
}
@@ -919,7 +871,7 @@ macro_rules! __dispatch_impl_metadata {
/// Convert the list of calls into their JSON representation, joined by ",".
#[macro_export]
#[doc(hidden)]
macro_rules! __call_to_metadata {
macro_rules! __call_to_functions {
(
$call_type:ident $origin_type:ty
{$(
@@ -931,16 +883,14 @@ macro_rules! __call_to_metadata {
);
)*}
) => {
$crate::dispatch::CallMetadata {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call_type)),
functions: __functions_to_metadata!(0; $origin_type;; $(
fn $fn_name( $($(#[$codec_attr])* $param_name: $param ),* );
$( $doc_attr ),*;
)*),
}
__functions_to_metadata!(0; $origin_type;; $(
fn $fn_name( $($(#[$codec_attr])* $param_name: $param ),* );
$( $doc_attr ),*;
)*)
};
}
/// Convert a list of functions into a list of `FunctionMetadata` items.
#[macro_export]
#[doc(hidden)]
@@ -970,7 +920,7 @@ macro_rules! __functions_to_metadata{
$origin_type:ty;
$( $function_metadata:expr ),*;
) => {
$crate::dispatch::DecodeDifferent::Encode(&[ $( $function_metadata ),* ])
&[ $( $function_metadata ),* ]
}
}
@@ -986,7 +936,6 @@ macro_rules! __function_to_metadata {
$fn_id:expr;
) => {
$crate::dispatch::FunctionMetadata {
id: $fn_id,
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($fn_name)),
arguments: $crate::dispatch::DecodeDifferent::Encode(&[
$(
@@ -1048,13 +997,8 @@ mod tests {
}
}
const EXPECTED_METADATA: ModuleMetadata = ModuleMetadata {
name: DecodeDifferent::Encode("Module"),
call: CallMetadata {
name: DecodeDifferent::Encode("Call"),
functions: DecodeDifferent::Encode(&[
const EXPECTED_METADATA: &'static [FunctionMetadata] = &[
FunctionMetadata {
id: 0,
name: DecodeDifferent::Encode("aux_0"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[
@@ -1062,7 +1006,6 @@ mod tests {
])
},
FunctionMetadata {
id: 1,
name: DecodeDifferent::Encode("aux_1"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
@@ -1073,7 +1016,6 @@ mod tests {
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
id: 2,
name: DecodeDifferent::Encode("aux_2"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
@@ -1088,13 +1030,11 @@ mod tests {
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
id: 3,
name: DecodeDifferent::Encode("aux_3"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
id: 4,
name: DecodeDifferent::Encode("aux_4"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
@@ -1104,9 +1044,7 @@ mod tests {
]),
documentation: DecodeDifferent::Encode(&[]),
}
]),
},
};
];
struct TraitImpl {}
@@ -1117,7 +1055,7 @@ mod tests {
#[test]
fn module_json_metadata() {
let metadata = Module::<TraitImpl>::metadata();
let metadata = Module::<TraitImpl>::call_functions();
assert_eq!(EXPECTED_METADATA, metadata);
}
+12
View File
@@ -433,6 +433,18 @@ macro_rules! __impl_outer_event_json_metadata {
])
}
}
#[allow(dead_code)]
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> )* ::metadata()
}
}
)*
}
}
}
+2 -1
View File
@@ -50,6 +50,8 @@ pub extern crate parity_codec as codec;
#[doc(hidden)]
pub extern crate once_cell;
pub extern crate paste;
pub use self::storage::generator::Storage as GenericStorage;
#[macro_use]
@@ -72,7 +74,6 @@ mod double_map;
pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType};
pub use self::metadata::RuntimeMetadata;
pub use runtime_io::print;
pub use double_map::StorageDoubleMap;
+233 -129
View File
@@ -15,8 +15,9 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub use srml_metadata::{
DecodeDifferent, FnEncode, RuntimeMetadata, RuntimeModuleMetadata,
DefaultByteGetter,
DecodeDifferent, FnEncode, RuntimeMetadata,
ModuleMetadata, RuntimeMetadataV1,
DefaultByteGetter, RuntimeMetadataPrefixed,
};
/// Implements the metadata support for the given runtime and all its modules.
@@ -31,15 +32,15 @@ pub use srml_metadata::{
macro_rules! impl_runtime_metadata {
(
for $runtime:ident with modules
$( $rest:tt )*
$( $rest:tt )*
) => {
impl $runtime {
pub fn metadata() -> $crate::metadata::RuntimeMetadata {
$crate::metadata::RuntimeMetadata {
outer_event: Self::outer_event_metadata(),
modules: __runtime_modules_to_metadata!($runtime;; $( $rest )*),
outer_dispatch: Self::outer_dispatch_metadata(),
}
pub fn metadata() -> $crate::metadata::RuntimeMetadataPrefixed {
$crate::metadata::RuntimeMetadata::V1 (
$crate::metadata::RuntimeMetadataV1 {
modules: __runtime_modules_to_metadata!($runtime;; $( $rest )*),
}
).into()
}
}
}
@@ -51,37 +52,17 @@ macro_rules! __runtime_modules_to_metadata {
(
$runtime: ident;
$( $metadata:expr ),*;
$mod:ident::$module:ident,
$mod:ident::$module:ident $(with)+ $($kw:ident)*,
$( $rest:tt )*
) => {
__runtime_modules_to_metadata!(
$runtime;
$( $metadata, )* $crate::metadata::RuntimeModuleMetadata {
prefix: $crate::metadata::DecodeDifferent::Encode(stringify!($mod)),
module: $crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode($mod::$module::<$runtime>::metadata)
),
storage: None,
};
$( $rest )*
)
};
(
$runtime: ident;
$( $metadata:expr ),*;
$mod:ident::$module:ident with Storage,
$( $rest:tt )*
) => {
__runtime_modules_to_metadata!(
$runtime;
$( $metadata, )* $crate::metadata::RuntimeModuleMetadata {
prefix: $crate::metadata::DecodeDifferent::Encode(stringify!($mod)),
module: $crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode($mod::$module::<$runtime>::metadata)
),
storage: Some($crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode($mod::$module::<$runtime>::store_metadata)
)),
$( $metadata, )* $crate::metadata::ModuleMetadata {
name: $crate::metadata::DecodeDifferent::Encode(stringify!($mod)),
prefix: __runtime_modules_to_metadata_calls_storagename!($mod, $module, $runtime, $(with $kw)*),
storage: __runtime_modules_to_metadata_calls_storage!($mod, $module, $runtime, $(with $kw)*),
calls: __runtime_modules_to_metadata_calls_call!($mod, $module, $runtime, $(with $kw)*),
event: __runtime_modules_to_metadata_calls_event!($mod, $module, $runtime, $(with $kw)*),
};
$( $rest )*
)
@@ -94,18 +75,172 @@ macro_rules! __runtime_modules_to_metadata {
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __runtime_modules_to_metadata_calls_call {
// skip system
(
system,
$skip_module: ident,
$skip_runtime: ident,
with Call
$(with $kws:ident)*
) => {
None
};
(
$mod: ident,
$module: ident,
$runtime: ident,
with Call
$(with $kws:ident)*
) => {
Some($crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode(
$mod::$module::<$runtime>::call_functions
)
))
};
(
$mod: ident,
$module: ident,
$runtime: ident,
with $_:ident
$(with $kws:ident)*
) => {
__runtime_modules_to_metadata_calls_call!( $mod, $module, $runtime, $(with $kws)* );
};
(
$mod: ident,
$module: ident,
$runtime: ident,
) => {
None
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __runtime_modules_to_metadata_calls_event {
(
$mod: ident,
$module: ident,
$runtime: ident,
with Event
$(with $kws:ident)*
) => {
Some($crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode(
$crate::paste::expr!{
$runtime:: [< __module_events_ $mod >]
}
)
))
};
(
$mod: ident,
$module: ident,
$runtime: ident,
with $_:ident
$(with $kws:ident)*
) => {
__runtime_modules_to_metadata_calls_event!( $mod, $module, $runtime, $(with $kws)* );
};
(
$mod: ident,
$module: ident,
$runtime: ident,
) => {
None
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __runtime_modules_to_metadata_calls_storagename {
(
$mod: ident,
$module: ident,
$runtime: ident,
with Storage
$(with $kws:ident)*
) => {
$crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode(
$mod::$module::<$runtime>::store_metadata_name
)
)
};
(
$mod: ident,
$module: ident,
$runtime: ident,
with $_:ident
$(with $kws:ident)*
) => {
__runtime_modules_to_metadata_calls_storagename!( $mod, $module, $runtime, $(with $kws)* );
};
(
$mod: ident,
$module: ident,
$runtime: ident,
) => {
$crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode(|| "")
)
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __runtime_modules_to_metadata_calls_storage {
(
$mod: ident,
$module: ident,
$runtime: ident,
with Storage
$(with $kws:ident)*
) => {
Some($crate::metadata::DecodeDifferent::Encode(
$crate::metadata::FnEncode(
$mod::$module::<$runtime>::store_metadata_functions
)
))
};
(
$mod: ident,
$module: ident,
$runtime: ident,
with $_:ident
$(with $kws:ident)*
) => {
__runtime_modules_to_metadata_calls_storage!( $mod, $module, $runtime, $(with $kws)* );
};
(
$mod: ident,
$module: ident,
$runtime: ident,
) => {
None
};
}
#[cfg(test)]
// Do not complain about unused `dispatch` and `dispatch_aux`.
#[allow(dead_code)]
mod tests {
use super::*;
use srml_metadata::{
EventMetadata, OuterEventMetadata, RuntimeModuleMetadata, CallMetadata, ModuleMetadata,
EventMetadata,
StorageFunctionModifier, StorageFunctionType, FunctionMetadata,
StorageMetadata, StorageFunctionMetadata, OuterDispatchMetadata, OuterDispatchCall
StorageFunctionMetadata,
ModuleMetadata, RuntimeMetadataPrefixed
};
use codec::{Decode, Encode};
mod system {
pub trait Trait {
type Origin: Into<Option<RawOrigin<Self::AccountId>>> + From<RawOrigin<Self::AccountId>>;
@@ -238,120 +373,89 @@ mod tests {
impl_runtime_metadata!(
for TestRuntime with modules
event_module::Module,
event_module2::Module with Storage,
system::Module with Event,
event_module::Module with Event Call,
event_module2::Module with Event Storage Call,
);
const EXPECTED_METADATA: RuntimeMetadata = RuntimeMetadata {
outer_event: OuterEventMetadata {
name: DecodeDifferent::Encode("TestEvent"),
events: DecodeDifferent::Encode(&[
(
"system",
FnEncode(|| &[
const EXPECTED_METADATA: RuntimeMetadata = RuntimeMetadata::V1(
RuntimeMetadataV1 {
modules: DecodeDifferent::Encode(&[
ModuleMetadata {
name: DecodeDifferent::Encode("system"),
prefix: DecodeDifferent::Encode(FnEncode(||"")),
storage: None,
calls: None,
event: Some(DecodeDifferent::Encode(
FnEncode(||&[
EventMetadata {
name: DecodeDifferent::Encode("SystemEvent"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[])
}
])
)),
},
ModuleMetadata {
name: DecodeDifferent::Encode("event_module"),
prefix: DecodeDifferent::Encode(FnEncode(||"")),
storage: None,
calls: Some(
DecodeDifferent::Encode(FnEncode(||&[
FunctionMetadata {
name: DecodeDifferent::Encode("aux_0"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
}
])
),
(
"event_module",
FnEncode(|| &[
]))),
event: Some(DecodeDifferent::Encode(
FnEncode(||&[
EventMetadata {
name: DecodeDifferent::Encode("TestEvent"),
arguments: DecodeDifferent::Encode(&["Balance"]),
documentation: DecodeDifferent::Encode(&[" Hi, I am a comment."])
}
])
),
(
"event_module2",
FnEncode(|| &[
])
)),
},
ModuleMetadata {
name: DecodeDifferent::Encode("event_module2"),
prefix: DecodeDifferent::Encode(FnEncode(||"TestStorage")),
storage: Some(DecodeDifferent::Encode(
FnEncode(||&[
StorageFunctionMetadata {
name: DecodeDifferent::Encode("StorageMethod"),
modifier: StorageFunctionModifier::Optional,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("u32")),
default: DecodeDifferent::Encode(
DefaultByteGetter(
&event_module2::__GetByteStructStorageMethod(::std::marker::PhantomData::<TestRuntime>)
)
),
documentation: DecodeDifferent::Encode(&[]),
}
])
)),
calls: Some(DecodeDifferent::Encode(FnEncode(||&[ ]))),
event: Some(DecodeDifferent::Encode(
FnEncode(||&[
EventMetadata {
name: DecodeDifferent::Encode("TestEvent"),
arguments: DecodeDifferent::Encode(&["Balance"]),
documentation: DecodeDifferent::Encode(&[])
}
])
)
]),
},
modules: DecodeDifferent::Encode(&[
RuntimeModuleMetadata {
prefix: DecodeDifferent::Encode("event_module"),
module: DecodeDifferent::Encode(FnEncode(||
ModuleMetadata {
name: DecodeDifferent::Encode("Module"),
call: CallMetadata {
name: DecodeDifferent::Encode("Call"),
functions: DecodeDifferent::Encode(&[
FunctionMetadata {
id: 0,
name: DecodeDifferent::Encode("aux_0"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
}
])
}
}
])
)),
storage: None,
},
RuntimeModuleMetadata {
prefix: DecodeDifferent::Encode("event_module2"),
module: DecodeDifferent::Encode(FnEncode(||
ModuleMetadata {
name: DecodeDifferent::Encode("Module"),
call: CallMetadata {
name: DecodeDifferent::Encode("Call"),
functions: DecodeDifferent::Encode(&[])
}
}
)),
storage: Some(DecodeDifferent::Encode(FnEncode(||
StorageMetadata {
prefix: DecodeDifferent::Encode("TestStorage"),
functions: DecodeDifferent::Encode(&[
StorageFunctionMetadata {
name: DecodeDifferent::Encode("StorageMethod"),
modifier: StorageFunctionModifier::Optional,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("u32")),
default: DecodeDifferent::Encode(
DefaultByteGetter(
&event_module2::__GetByteStructStorageMethod(::std::marker::PhantomData::<TestRuntime>)
)
),
documentation: DecodeDifferent::Encode(&[]),
}
])
}
))),
}
]),
outer_dispatch: OuterDispatchMetadata {
name: DecodeDifferent::Encode("Call"),
calls: DecodeDifferent::Encode(&[
OuterDispatchCall {
name: DecodeDifferent::Encode("EventModule"),
prefix: DecodeDifferent::Encode("event_module"),
index: 0,
},
OuterDispatchCall {
name: DecodeDifferent::Encode("EventModule2"),
prefix: DecodeDifferent::Encode("event_module2"),
index: 1,
}
])
}
};
])}
);
#[test]
fn runtime_metadata() {
let metadata_encoded = TestRuntime::metadata().encode();
let metadata_decoded = RuntimeMetadata::decode(&mut &metadata_encoded[..]);
let metadata_decoded = RuntimeMetadataPrefixed::decode(&mut &metadata_encoded[..]);
let expected_metadata: RuntimeMetadataPrefixed = EXPECTED_METADATA.into();
assert_eq!(EXPECTED_METADATA, metadata_decoded.unwrap());
assert_eq!(expected_metadata, metadata_decoded.unwrap());
}
}
+40 -126
View File
@@ -347,10 +347,9 @@ macro_rules! construct_runtime {
__decl_runtime_metadata!(
$runtime;
;
;
$(
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
),*;
$name: $module::{ $( $modules $( <$modules_generic> )* )* }
)*
);
__decl_outer_log!(
$runtime;
@@ -752,170 +751,85 @@ macro_rules! __decl_outer_dispatch {
#[macro_export]
#[doc(hidden)]
macro_rules! __decl_runtime_metadata {
// contain a module
(
$runtime:ident;
;
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$( $parsed_modules:ident { $( $withs:ident )* } )*;
$name:ident: $module:ident::{
Module $(, $modules:ident $( <$modules_generic:ident> )* )*
Module $( $modules:ident $( <$modules_generic:ident> )* )*
}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
$( $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* )*
})*
) => {
__decl_runtime_metadata!(
__decl_runtime_metadata!(@Module
$runtime;
$module { Module, };
$( $parsed_modules { Module $( with $parsed_storage )* } ),*;
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
$(
, $rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
}
)*;
);
};
(
$runtime:ident;
$current_module:ident { , Storage };
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$name:ident: $module:ident::{
Module $(, $modules:ident $( <$modules_generic:ident> )* )*
}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
) => {
__decl_runtime_metadata!(
$runtime;
;
$( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module with Storage };
$( $parsed_modules { $( $withs )* } )*;
$name: $module::{ $( $modules $( <$modules_generic> )* )* }
$(
$rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
$( $rest_modules $( <$rest_modules_generic> )* )*
}
),*;
)*
);
};
// do not contain Module : skip
(
$runtime:ident;
;
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$( $parsed_modules:ident { $( $withs:ident )* } )*;
$name:ident: $module:ident::{
Storage $(, $modules:ident $( <$modules_generic:ident> )* )*
$( $modules:ident $( <$modules_generic:ident> )* )*
}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
$( $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* )*
})*
) => {
__decl_runtime_metadata!(
$runtime;
$module { , Storage };
$( $parsed_modules { Module $( with $parsed_storage )* } ),*;
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
$(
, $rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
}
)*;
);
};
(
$runtime:ident;
$current_module:ident { Module, };
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$name:ident: $module:ident::{
Storage $(, $modules:ident $( <$modules_generic:ident> )* )*
}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
) => {
__decl_runtime_metadata!(
$runtime;
;
$( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module with Storage };
$( $parsed_modules { $( $withs )* } )*;
$(
$rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
$( $rest_modules $( <$rest_modules_generic> )* )*
}
),*;
)*
);
};
(
// process module
(@Module
$runtime:ident;
$( $current_module:ident { $( $current_module_storage:tt )* } )*;
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$( $parsed_modules:ident { $( $withs:ident )* } )*;
$name:ident: $module:ident::{
$ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )*
$( $modules:ident $( <$modules_generic:ident> )* )*
}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
$($rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* )*
})*
) => {
__decl_runtime_metadata!(
$runtime;
$( $current_module { $( $current_module_storage )* } )*;
$( $parsed_modules { Module $( with $parsed_storage )* } ),*;
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
$(
, $rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
}
)*;
);
};
(
$runtime:ident;
$current_module:ident { Module, };
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$name:ident: $module:ident::{}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
) => {
__decl_runtime_metadata!(
$runtime;
;
$( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module };
$( $parsed_modules { $( $withs )* } )*
$module {
$($modules)*
};
$(
$rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
$( $rest_modules $( <$rest_modules_generic> )* )*
}
),*;
)*
);
};
// end of decl
(
$runtime:ident;
$( $current_module:ident { $( $ignore:tt )* } )*;
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
$name:ident: $module:ident::{}
$(, $rest_name:ident : $rest_module:ident::{
$( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),*
})*;
) => {
__decl_runtime_metadata!(
$runtime;
;
$( $parsed_modules { Module $( with $parsed_storage )* } ),*;
$(
$rest_name: $rest_module::{
$( $rest_modules $( <$rest_modules_generic> )* ),*
}
),*;
);
};
(
$runtime:ident;
;
$( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*;
;
$( $parsed_modules:ident { $( $withs:ident )* } )*;
) => {
impl_runtime_metadata!(
for $runtime with modules
$( $parsed_modules::Module $(with $parsed_storage)*, )*
$( $parsed_modules::Module with $( $withs )* , )*
);
}
}
/// A private macro that generates Log enum for the runtime. See impl_outer_log macro.
@@ -635,9 +635,9 @@ mod tests {
GETMAPU32MYDEF get(map_u32_getter_mydef): map u32 => String = "map".into();
pub PUBGETMAPU32MYDEF get(pub_map_u32_getter_mydef): map u32 => String = "pubmap".into();
COMPLEX_TYPE1: ::std::vec::Vec<<T as Trait>::Origin>;
COMPLEX_TYPE2: (Vec<Vec<(u16,Box<( )>)>>, u32);
COMPLEX_TYPE3: ([u32;25]);
COMPLEXTYPE1: ::std::vec::Vec<<T as Trait>::Origin>;
COMPLEXTYPE2: (Vec<Vec<(u16,Box<( )>)>>, u32);
COMPLEXTYPE3: ([u32;25]);
}
add_extra_genesis {
build(|_, _, _| {});
@@ -652,7 +652,6 @@ mod tests {
}
const EXPECTED_METADATA: StorageMetadata = StorageMetadata {
prefix: DecodeDifferent::Encode("TestStorage"),
functions: DecodeDifferent::Encode(&[
StorageFunctionMetadata {
name: DecodeDifferent::Encode("U32"),
@@ -861,29 +860,29 @@ mod tests {
documentation: DecodeDifferent::Encode(&[]),
},
StorageFunctionMetadata {
name: DecodeDifferent::Encode("COMPLEX_TYPE1"),
name: DecodeDifferent::Encode("COMPLEXTYPE1"),
modifier: StorageFunctionModifier::Default,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("::std::vec::Vec<<T as Trait>::Origin>")),
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructCOMPLEX_TYPE1(PhantomData::<TraitImpl>))
DefaultByteGetter(&__GetByteStructCOMPLEXTYPE1(PhantomData::<TraitImpl>))
),
documentation: DecodeDifferent::Encode(&[]),
},
StorageFunctionMetadata {
name: DecodeDifferent::Encode("COMPLEX_TYPE2"),
name: DecodeDifferent::Encode("COMPLEXTYPE2"),
modifier: StorageFunctionModifier::Default,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("(Vec<Vec<(u16, Box<()>)>>, u32)")),
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructCOMPLEX_TYPE2(PhantomData::<TraitImpl>))
DefaultByteGetter(&__GetByteStructCOMPLEXTYPE2(PhantomData::<TraitImpl>))
),
documentation: DecodeDifferent::Encode(&[]),
},
StorageFunctionMetadata {
name: DecodeDifferent::Encode("COMPLEX_TYPE3"),
name: DecodeDifferent::Encode("COMPLEXTYPE3"),
modifier: StorageFunctionModifier::Default,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("([u32; 25])")),
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructCOMPLEX_TYPE3(PhantomData::<TraitImpl>))
DefaultByteGetter(&__GetByteStructCOMPLEXTYPE3(PhantomData::<TraitImpl>))
),
documentation: DecodeDifferent::Encode(&[]),
},