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
+34
View File
@@ -2206,6 +2206,26 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste-impl"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
@@ -2249,6 +2269,16 @@ dependencies = [
"proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack-impl"
version = "0.4.1"
@@ -3175,6 +3205,7 @@ dependencies = [
"once_cell 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4960,12 +4991,15 @@ dependencies = [
"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d"
"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a"
"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e"
"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8"
"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66"
"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a"
"checksum proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "77997c53ae6edd6d187fec07ec41b207063b5ee6f33680e9fa86d405cdd313d4"
"checksum proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "38fddd23d98b2144d197c0eca5705632d4fe2667d14a6be5df8934f8d74f1978"
+34
View File
@@ -685,6 +685,26 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste-impl"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "percent-encoding"
version = "1.0.1"
@@ -714,6 +734,16 @@ dependencies = [
"proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack-impl"
version = "0.4.1"
@@ -1060,6 +1090,7 @@ dependencies = [
"mashup 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 0.1.0",
@@ -1759,10 +1790,13 @@ dependencies = [
"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d"
"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e"
"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8"
"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66"
"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
+1 -1
View File
@@ -59,7 +59,7 @@ pub use consensus::Call as ConsensusCall;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use runtime_primitives::{Permill, Perbill};
pub use srml_support::{StorageValue, RuntimeMetadata};
pub use srml_support::StorageValue;
/// Runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion {
+34
View File
@@ -743,6 +743,26 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "paste-impl"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "percent-encoding"
version = "1.0.1"
@@ -772,6 +792,16 @@ dependencies = [
"proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-hack-impl"
version = "0.4.1"
@@ -1368,6 +1398,7 @@ dependencies = [
"mashup 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 0.1.0",
@@ -2119,10 +2150,13 @@ dependencies = [
"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d"
"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e"
"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8"
"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66"
"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum pwasm-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e9135bed7b452e20dbb395a2d519abaf0c46d60e7ecc02daeeab447d29bada1"
+59 -33
View File
@@ -42,6 +42,9 @@ use rstd::vec::Vec;
#[cfg(feature = "std")]
type StringBuf = String;
/// Curent prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
#[cfg(not(feature = "std"))]
@@ -120,34 +123,17 @@ impl<B, O> serde::Serialize for DecodeDifferent<B, O>
}
}
type DecodeDifferentArray<B, O=B> = DecodeDifferent<&'static [B], Vec<O>>;
pub type DecodeDifferentArray<B, O=B> = DecodeDifferent<&'static [B], Vec<O>>;
#[cfg(feature = "std")]
type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>;
#[cfg(not(feature = "std"))]
type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>;
/// All the metadata about a module.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub call: CallMetadata,
}
/// All the metadata about a call.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct CallMetadata {
pub name: DecodeDifferentStr,
pub functions: DecodeDifferentArray<FunctionMetadata>,
}
/// All the metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct FunctionMetadata {
pub id: u16,
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
@@ -218,7 +204,6 @@ pub struct EventMetadata {
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct StorageMetadata {
pub prefix: DecodeDifferentStr,
pub functions: DecodeDifferentArray<StorageFunctionMetadata>,
}
@@ -310,30 +295,71 @@ pub struct OuterDispatchMetadata {
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct OuterDispatchCall {
pub name: DecodeDifferentStr,
pub prefix: DecodeDifferentStr,
pub index: u16,
}
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
/// Metadata prefixed by a u32 for reserved usage
pub struct RuntimeMetadataPrefixed(pub u32, pub RuntimeMetadata);
/// The metadata of a runtime.
/// The version ID encoded/decoded through
/// the enum nature of `RuntimeMetadata`.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub enum RuntimeMetadata {
/// Unused; enum filler.
V0(RuntimeMetadataDeprecated),
/// Version 1 for runtime metadata.
V1(RuntimeMetadataV1),
}
/// Enum that should fail.
#[derive(Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
pub enum RuntimeMetadataDeprecated { }
impl Encode for RuntimeMetadataDeprecated {
fn encode_to<W: Output>(&self, _dest: &mut W) {
}
}
#[cfg(feature = "std")]
impl Decode for RuntimeMetadataDeprecated {
fn decode<I: Input>(_input: &mut I) -> Option<Self> {
unimplemented!()
}
}
/// The metadata of a runtime version 1.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct RuntimeMetadataV1 {
pub modules: DecodeDifferentArray<ModuleMetadata>,
}
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct RuntimeModuleMetadata {
pub prefix: DecodeDifferentStr,
pub module: DecodeDifferent<FnEncode<ModuleMetadata>, ModuleMetadata>,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub prefix: DecodeDifferent<FnEncode<&'static str>, StringBuf>,
pub storage: ODFnA<StorageFunctionMetadata>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct RuntimeMetadata {
pub outer_event: OuterEventMetadata,
pub modules: DecodeDifferentArray<RuntimeModuleMetadata>,
pub outer_dispatch: OuterDispatchMetadata,
}
type ODFnA<T> = Option<DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>>;
impl Into<primitives::OpaqueMetadata> for RuntimeMetadata {
impl Into<primitives::OpaqueMetadata> for RuntimeMetadataPrefixed {
fn into(self) -> primitives::OpaqueMetadata {
primitives::OpaqueMetadata::new(self.encode())
}
}
impl Into<RuntimeMetadataPrefixed> for RuntimeMetadata {
fn into(self) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, self)
}
}
+1
View File
@@ -16,6 +16,7 @@ substrate-inherents = { path = "../../core/inherents", default-features = false
srml-support-procedural = { path = "./procedural" }
mashup = "0.1.7"
once_cell = { version = "0.1.6", default-features = false, optional = true }
paste = "0.1"
[dev-dependencies]
pretty_assertions = "0.5.1"
@@ -131,10 +131,16 @@ pub fn decl_storage_impl(input: TokenStream) -> TokenStream {
#impl_store_fns
pub fn store_metadata() -> #scrate::storage::generator::StorageMetadata {
#scrate::storage::generator::StorageMetadata {
prefix: #scrate::storage::generator::DecodeDifferent::Encode(#cratename_string),
functions: #store_functions_to_metadata ,
functions: #scrate::storage::generator::DecodeDifferent::Encode(#store_functions_to_metadata) ,
}
}
pub fn store_metadata_functions() -> &'static [#scrate::storage::generator::StorageFunctionMetadata] {
#store_functions_to_metadata
}
pub fn store_metadata_name() -> &'static str {
#cratename_string
}
}
#extra_genesis
@@ -656,7 +662,7 @@ fn store_functions_to_metadata (
}
let str_name = name.to_string();
let struct_name = proc_macro2::Ident::new(&("__GetByteStruct".to_string() + &str_name), name.span());
let cache_name = proc_macro2::Ident::new(&("__CacheGetByteStruct".to_string() + &str_name), name.span());
let cache_name = proc_macro2::Ident::new(&("__CACHE_GET_BYTE_STRUCT_".to_string() + &str_name), name.span());
let item = quote! {
#scrate::storage::generator::StorageFunctionMetadata {
name: #scrate::storage::generator::DecodeDifferent::Encode(#str_name),
@@ -674,6 +680,7 @@ fn store_functions_to_metadata (
let def_get = quote! {
pub struct #struct_name<#traitinstance>(pub #scrate::rstd::marker::PhantomData<#traitinstance>);
#[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> #scrate::storage::generator::DefaultByte for #struct_name<#traitinstance> {
@@ -698,9 +705,9 @@ fn store_functions_to_metadata (
}
(default_getter_struct_def, quote!{
{
#scrate::storage::generator::DecodeDifferent::Encode(&[
&[
#items
])
]
}
})
}
+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(&[]),
},