From f317b18e9aa61fe5541927964805efac35a9e428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 13 Sep 2018 13:07:38 +0200 Subject: [PATCH 1/7] Make `system` module renamable in `impl_outer_event!` --- srml/support/src/event.rs | 75 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/srml/support/src/event.rs b/srml/support/src/event.rs index ddce345c38e89..80a32951983ed 100644 --- a/srml/support/src/event.rs +++ b/srml/support/src/event.rs @@ -273,6 +273,21 @@ macro_rules! impl_outer_event { ( $(#[$attr:meta])* pub enum $name:ident for $runtime:ident { + $( $rest:tt $( <$t:ident> )*, )* + } + ) => { + impl_outer_event!( + $( #[$attr] )*; + $name; + $runtime; + system; + Modules { $( $rest $(<$t>)*, )* }; + ; + ); + }; + ( + $(#[$attr:meta])* + pub enum $name:ident for $runtime:ident where system = $system:ident { $module:ident, $( $rest:tt $( <$t:ident> )*, )* } @@ -281,13 +296,14 @@ macro_rules! impl_outer_event { $( #[$attr] )*; $name; $runtime; + $system; Modules { $( $rest $(<$t>)*, )* }; $module::Event<$runtime>,; ); }; ( $(#[$attr:meta])* - pub enum $name:ident for $runtime:ident { + pub enum $name:ident for $runtime:ident where system = $system:ident { $module:ident, $( $rest:tt $( <$t:ident> )*, )* } @@ -296,6 +312,7 @@ macro_rules! impl_outer_event { $( #[$attr] )*; $name; $runtime; + $system; Modules { $( $rest $(<$t>)*, )* }; $module::Event,; ); @@ -304,6 +321,7 @@ macro_rules! impl_outer_event { $(#[$attr:meta])*; $name:ident; $runtime:ident; + $system:ident; Modules { $module:ident, $( $rest:tt $( <$t:ident> )*, )* @@ -314,6 +332,7 @@ macro_rules! impl_outer_event { $( #[$attr] )*; $name; $runtime; + $system; Modules { $( $rest $(<$t>)*, )* }; $( $module_name::Event $( <$generic_param> )*, )* $module::Event<$runtime>,; ); @@ -322,6 +341,7 @@ macro_rules! impl_outer_event { $(#[$attr:meta])*; $name:ident; $runtime:ident; + $system:ident; Modules { $module:ident, $( $rest:tt, )* @@ -332,6 +352,7 @@ macro_rules! impl_outer_event { $( #[$attr] )*; $name; $runtime; + $system; Modules { $( $rest, )* }; $( $module_name::Event $( <$generic_param> )*, )* $module::Event,; ); @@ -340,6 +361,7 @@ macro_rules! impl_outer_event { $(#[$attr:meta])*; $name:ident; $runtime:ident; + $system:ident; Modules {}; $( $module_name:ident::Event $( <$generic_param:ident> )*, )*; ) => { @@ -349,13 +371,13 @@ macro_rules! impl_outer_event { $(#[$attr])* #[allow(non_camel_case_types)] pub enum $name { - system(system::Event), + system($system::Event), $( $module_name( $module_name::Event $( <$generic_param> )* ), )* } - impl From for $name { - fn from(x: system::Event) -> Self { + impl From<$system::Event> for $name { + fn from(x: $system::Event) -> Self { $name::system(x) } } @@ -369,6 +391,7 @@ macro_rules! impl_outer_event { __impl_outer_event_json_metadata!( $runtime; $name; + $system; $( $module_name::Event $( <$generic_param> )*, )*; ); } @@ -380,13 +403,14 @@ macro_rules! __impl_outer_event_json_metadata { ( $runtime:ident; $event_name:ident; + $system:ident; $( $module_name:ident::Event $( <$generic_param:ident> )*, )*; ) => { impl $runtime { #[allow(dead_code)] pub fn outer_event_json_metadata() -> (&'static str, &'static [(&'static str, fn() -> &'static str)]) { static METADATA: &[(&str, fn() -> &'static str)] = &[ - ("system", system::Event::event_json_metadata) + ("system", $system::Event::event_json_metadata) $( , ( stringify!($module_name), @@ -425,6 +449,22 @@ mod tests { ); } + mod system_renamed { + pub trait Trait { + type Origin; + } + + decl_module! { + pub struct Module for enum Call where origin: T::Origin {} + } + + decl_event!( + pub enum Event { + SystemEvent, + } + ); + } + mod event_module { pub trait Trait { type Origin; @@ -488,6 +528,17 @@ mod tests { } } + #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Deserialize, Serialize)] + pub struct TestRuntime2; + + impl_outer_event! { + pub enum TestEventSystemRenamed for TestRuntime2 where system = system_renamed { + event_module, + event_module2, + event_module3, + } + } + impl event_module::Trait for TestRuntime { type Origin = u32; type Balance = u32; @@ -502,6 +553,20 @@ mod tests { type Origin = u32; } + impl event_module::Trait for TestRuntime2 { + type Origin = u32; + type Balance = u32; + } + + impl event_module2::Trait for TestRuntime2 { + type Origin = u32; + type Balance = u32; + } + + impl system_renamed::Trait for TestRuntime2 { + type Origin = u32; + } + const EXPECTED_METADATA: (&str, &[(&str, &str)]) = ( "TestEvent", &[ ("system", r#"{ "SystemEvent": { "params": null, "description": [ ] } }"#), From 0b376134c9c79296f6f7b3f69ac12c1fe0ca3cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 09:56:25 +0200 Subject: [PATCH 2/7] Implement `construct_runtime!` macro This macro generates code for calling all the common `impl_outer_*` macros. --- Cargo.lock | 21 + node/runtime/src/lib.rs | 148 +----- srml/support/Cargo.toml | 1 + srml/support/src/lib.rs | 7 + srml/support/src/runtime.rs | 969 ++++++++++++++++++++++++++++++++++++ 5 files changed, 1016 insertions(+), 130 deletions(-) create mode 100644 srml/support/src/runtime.rs diff --git a/Cargo.lock b/Cargo.lock index 148428e4617e3..4d882c3526c77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,6 +1237,24 @@ dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mashup" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mashup-impl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "matches" version = "0.1.6" @@ -2540,6 +2558,7 @@ name = "srml-support" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3870,6 +3889,8 @@ dependencies = [ "checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" +"checksum mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d886e371548f5c66258a99df9ec03366bff02cc96ea3d3f8f346b5d2d6836de7" +"checksum mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8d426741e35fab52542d84dfee615f442c2b37247bee8b1ed5c25ca723487580" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 75578ef2b09ce..2c519de1befea 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -17,6 +17,7 @@ //! The Substrate runtime. This can be compiled with ``#[no_std]`, ready for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit="256"] #[macro_use] extern crate sr_io as runtime_io; @@ -80,12 +81,6 @@ pub use checked_block::CheckedBlock; const TIMESTAMP_SET_POSITION: u32 = 0; const NOTE_OFFLINE_POSITION: u32 = 1; -// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. -#[derive(Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] -/// Runtime type used to collate and parameterize the various modules. -pub struct Runtime; - /// Runtime version. pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: ver_str!("node"), @@ -107,9 +102,6 @@ impl system::Trait for Runtime { type Event = Event; } -/// System module for this concrete runtime. -pub type System = system::Module; - impl balances::Trait for Runtime { type Balance = Balance; type AccountIndex = AccountIndex; @@ -118,9 +110,6 @@ impl balances::Trait for Runtime { type Event = Event; } -/// Staking module for this concrete runtime. -pub type Balances = balances::Module; - impl consensus::Trait for Runtime { const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION; type Log = Log; @@ -128,17 +117,11 @@ impl consensus::Trait for Runtime { type OnOfflineValidator = Staking; } -/// Consensus module for this concrete runtime. -pub type Consensus = consensus::Module; - impl timestamp::Trait for Runtime { const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION; type Moment = u64; } -/// Timestamp module for this concrete runtime. -pub type Timestamp = timestamp::Module; - /// Session key conversion. pub struct SessionKeyConversion; impl Convert for SessionKeyConversion { @@ -153,153 +136,41 @@ impl session::Trait for Runtime { type Event = Event; } -/// Session module for this concrete runtime. -pub type Session = session::Module; - impl staking::Trait for Runtime { type OnRewardMinted = Treasury; type Event = Event; } -/// Staking module for this concrete runtime. -pub type Staking = staking::Module; - impl democracy::Trait for Runtime { type Proposal = Call; type Event = Event; } -/// Democracy module for this concrete runtime. -pub type Democracy = democracy::Module; - impl council::Trait for Runtime { type Event = Event; } -/// Council module for this concrete runtime. -pub type Council = council::Module; - impl council::voting::Trait for Runtime { type Event = Event; } -/// Council voting module for this concrete runtime. -pub type CouncilVoting = council::voting::Module; - impl council::motions::Trait for Runtime { type Origin = Origin; type Proposal = Call; type Event = Event; } -/// Council motions module for this concrete runtime. -pub type CouncilMotions = council_motions::Module; - impl treasury::Trait for Runtime { type ApproveOrigin = council_motions::EnsureMembers<_4>; type RejectOrigin = council_motions::EnsureMembers<_2>; type Event = Event; } -/// Treasury module for this concrete runtime. -pub type Treasury = treasury::Module; - impl contract::Trait for Runtime { type Gas = u64; type DetermineContractAddress = contract::SimpleAddressDeterminator; } -/// Contract module for this concrete runtime. -pub type Contract = contract::Module; - -impl_outer_event! { - pub enum Event for Runtime { - //consensus, - balances, - //timetstamp, - session, - staking, - democracy, - council, - council_voting, - council_motions, - treasury, - } -} - -impl_outer_log! { - pub enum Log(InternalLog: DigestItem) for Runtime { - consensus(AuthoritiesChange) - } -} - -impl_outer_origin! { - pub enum Origin for Runtime { - council_motions - } -} - -impl_outer_dispatch! { - pub enum Call where origin: Origin { - Consensus, - Balances, - Timestamp, - Session, - Staking, - Democracy, - Council, - CouncilVoting, - CouncilMotions, - Treasury, - Contract, - } -} - -impl_outer_config! { - pub struct GenesisConfig for Runtime { - SystemConfig => system, - ConsensusConfig => consensus, - ContractConfig => contract, - BalancesConfig => balances, - TimestampConfig => timestamp, - SessionConfig => session, - StakingConfig => staking, - DemocracyConfig => democracy, - CouncilConfig => council, - TreasuryConfig => treasury, - } -} - -type AllModules = ( - Consensus, - Balances, - Timestamp, - Session, - Staking, - Democracy, - Council, - CouncilVoting, - CouncilMotions, - Treasury, - Contract, -); - -impl_json_metadata!( - for Runtime with modules - system::Module with Storage, - consensus::Module with Storage, - balances::Module with Storage, - timestamp::Module with Storage, - session::Module with Storage, - staking::Module with Storage, - democracy::Module with Storage, - council::Module with Storage, - council_voting::Module with Storage, - council_motions::Module with Storage, - treasury::Module with Storage, - contract::Module with Storage, -); - impl DigestItem for Log { type AuthorityId = SessionKey; @@ -310,6 +181,23 @@ impl DigestItem for Log { } } +construct_runtime!( + pub enum Runtime with Log(InternalLog: DigestItem) { + System: system, + Consensus: consensus::{Module, Call, Storage, Config, Log(AuthoritiesChange)}, + Balances: balances, + Timestamp: timestamp::{Module, Call, Storage, Config}, + Session: session, + Staking: staking, + Democracy: democracy, + Council: council, + CouncilVoting: council_voting::{Module, Call, Storage, Event}, + CouncilMotions: council_motions::{Module, Call, Storage, Event, Origin}, + Treasury: treasury, + Contract: contract::{Module, Call, Log}, + } +); + /// The address format for describing accounts. pub use balances::address::Address as RawAddress; /// The address format for describing accounts. diff --git a/srml/support/Cargo.toml b/srml/support/Cargo.toml index 1677b12dd3d5c..89f09abcd8e80 100644 --- a/srml/support/Cargo.toml +++ b/srml/support/Cargo.toml @@ -12,6 +12,7 @@ substrate-primitives = { path = "../../core/primitives", default_features = fals substrate-metadata = { path = "../../core/metadata", default_features = false } sr-std = { path = "../../core/sr-std", default_features = false } sr-io = { path = "../../core/sr-io", default_features = false } +mashup = "0.1.7" [dev-dependencies] pretty_assertions = "0.5.1" diff --git a/srml/support/src/lib.rs b/srml/support/src/lib.rs index f4da761ea0db5..6836be27eaf14 100644 --- a/srml/support/src/lib.rs +++ b/srml/support/src/lib.rs @@ -32,6 +32,8 @@ extern crate sr_io as runtime_io; extern crate substrate_primitives as primitives; extern crate substrate_metadata; +extern crate mashup; + #[cfg(test)] #[macro_use] extern crate pretty_assertions; @@ -65,6 +67,8 @@ mod event; pub mod metadata; #[macro_use] mod origin; +#[macro_use] +mod runtime; pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap}; pub use self::hashable::Hashable; @@ -122,3 +126,6 @@ macro_rules! assert_ok { #[derive(Clone, Eq, PartialEq)] #[cfg_attr(feature = "std", derive(Debug))] pub enum Void {} + +#[doc(hidden)] +pub use mashup::*; diff --git a/srml/support/src/runtime.rs b/srml/support/src/runtime.rs new file mode 100644 index 0000000000000..f2660925e345d --- /dev/null +++ b/srml/support/src/runtime.rs @@ -0,0 +1,969 @@ +// Copyright 2018 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +#[macro_export] +macro_rules! construct_runtime { + ( + pub enum $runtime:ident with Log ($log_internal:ident: DigestItem<$( $log_genarg:ty ),+>) { + $( $rest:tt )* + } + ) => { + construct_runtime!( + $runtime; + $log_internal < $( $log_genarg ),* >; + ; + $( $rest )* + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( + $expanded_name:ident: $expanded_module:ident::{ + $( + $expanded_modules:ident + $( <$expanded_modules_generic:ident> )* + $( ( $( $expanded_modules_args:ident ),* ) )* + ),* + } + ),*; + $name:ident: $module:ident, + $( + $rest_name:ident: $rest_module:ident $( + ::{ + $( + $rest_modules:ident + $( <$rest_modules_generic:ident> )* + $( ( $( $rest_modules_args:ident ),* ) )* + ),* + } + )*, + )* + ) => { + construct_runtime!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( + $expanded_name: $expanded_module::{ + $( + $expanded_modules + $( <$expanded_modules_generic> )* + $( ( $( $expanded_modules_args ),* ) )* + ),* + }, + )* $name: $module::{Module, Call, Storage, Event, Config}; + $( + $rest_name: $rest_module $( + ::{ + $( + $rest_modules + $( <$rest_modules_generic> )* + $( ( $( $rest_modules_args ),* ) )* + ),* + } + )*, + )* + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( + $expanded_name:ident: $expanded_module:ident::{ + $( + $expanded_modules:ident + $( <$expanded_modules_generic:ident> )* + $( ( $( $expanded_modules_args:ident ),* ) )* + ),* + } + ),*; + $name:ident: $module:ident::{ + default, + $( + $modules:ident + $( <$modules_generic:ident> )* + $( ( $( $modules_args:ident ),* ) )* + ),* + }, + $( + $rest_name:ident: $rest_module:ident $( + ::{ + $( + $rest_modules:ident + $( <$rest_modules_generic:ident> )* + $( ( $( $rest_modules_args:ident ),* ) )* + ),* + } + )*, + )* + ) => { + construct_runtime!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( + $expanded_name: $expanded_module::{ + $( + $expanded_modules + $( <$expanded_modules_generic> )* + $( ( $( $expanded_modules_args ),* ) )* + ),* + }, + )* + $name: $module::{ + Module, Call, Storage, Event, Config, + $( + $modules $( <$modules_generic> )* $( ( $( $modules_args ),* ) )* + ),* + }; + $( + $rest_name: $rest_module $( + ::{ + $( + $rest_modules + $( <$rest_modules_generic> )* + $( ( $( $rest_modules_args ),* ) )* + ),* + } + )*, + )* + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( + $expanded_name:ident: $expanded_module:ident::{ + $( + $expanded_modules:ident + $( <$expanded_modules_generic:ident> )* + $( ( $( $expanded_modules_args:ident ),* ) )* + ),* + } + ),*; + $name:ident: $module:ident::{ + $( + $modules:ident + $( <$modules_generic:ident> )* + $( ( $( $modules_args:ident ),* ) )* + ),* + }, + $( + $rest_name:ident: $rest_module:ident $( + ::{ + $( + $rest_modules:ident + $( <$rest_modules_generic:ident> )* + $( ( $( $rest_modules_args:ident ),* ) )* + ),* + } + )*, + )* + ) => { + construct_runtime!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( + $expanded_name: $expanded_module::{ + $( + $expanded_modules + $( <$expanded_modules_generic> )* + $( ( $( $expanded_modules_args ),* ) )* + ),* + }, + )* + $name: $module::{ + $( + $modules $( <$modules_generic> )* $( ( $( $modules_args ),* ) )* + ),* + }; + $( + $rest_name: $rest_module $( + ::{ + $( + $rest_modules + $( <$rest_modules_generic> )* + $( ( $( $rest_modules_args ),* ) )* + ),* + } + )*, + )* + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( + $name:ident: $module:ident::{ + $( + $modules:ident + $( <$modules_generic:ident> )* + $( ( $( $modules_args:ident ),* ) )* + ),* + } + ),*; + ) => { + #[derive(Clone, Copy, PartialEq, Eq)] + #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + pub struct $runtime; + __decl_outer_event!( + $runtime; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),* + ); + __decl_outer_origin!( + $runtime; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),* + ); + __decl_all_modules!( + $runtime; + ; + ; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),*; + ); + __decl_outer_dispatch!( + $runtime; + ; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),*; + ); + __decl_json_metadata!( + $runtime; + ; + ; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),*; + ); + __decl_outer_log!( + $runtime; + $log_internal < $( $log_genarg ),* >; + ; + $( + $name: $module::{ $( $modules $( ( $( $modules_args ),* ) )* ),* } + ),*; + ); + __decl_outer_config!( + $runtime; + ; + $( + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + ),*; + ); + } +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __create_decl_macro { + ( + // Parameter $d is a hack for the following issue: + // https://github.com/rust-lang/rust/issues/35853 + $macro_name:ident, $macro_outer_name:ident, $macro_enum_name:ident, $d:tt + ) => { + #[macro_export] + #[doc(hidden)] + macro_rules! $macro_name { + ( + $runtime:ident; + System: $module:ident::{ + $ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )* + } + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })* + ) => { + $macro_name!( + $runtime; + $module; + ; + $d( + $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + ; // there can not be multiple `System`s + $d( $parsed_modules:ident $d( <$parsed_generic:ident> )* ),*; + System: $module:ident::{ + $ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )* + } + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + $macro_name!( + $runtime; + $module; + $d( $parsed_modules $d( <$parsed_generic> )* ),*; + $d( + $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $name:ident: $module:ident::{ + $ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )* + } + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })* + ) => { + $macro_name!( + $runtime; + ; + ; + $name: $module::{ $d( $modules $d( <$modules_generic> )* ),* } + $d( + , $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $d( $system:ident )*; + $d( $parsed_modules:ident $d( <$parsed_generic:ident> )* ),*; + $name:ident: $module:ident::{ + $macro_enum_name $d( <$event_gen:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )* + } + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + $macro_name!( + $runtime; + $d( $system )*; + $d( + $parsed_modules $d( <$parsed_generic> )* , )* + $module $d( <$event_gen> )*; + $d( + $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $d( $system:ident )*; + $d( $parsed_modules:ident $d( <$parsed_generic:ident> )* ),*; + $name:ident: $module:ident::{ + $ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )* + } + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + $macro_name!( + $runtime; + $d( $system )*; + $d( $parsed_modules $d( <$parsed_generic> )* ),*; + $name: $module::{ $d( $modules $d( <$modules_generic> )* ),* } + $d( + , $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $d( $system:ident )*; + $d( $parsed_modules:ident $d( <$parsed_generic:ident> )* ),*; + $name:ident: $module:ident::{} + $d(, $rest_name:ident : $rest_module:ident::{ + $d( $rest_modules:ident $d( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + $macro_name!( + $runtime; + $d( $system )*; + $d( $parsed_modules $d( <$parsed_generic> )* ),*; + $d( + $rest_name: $rest_module::{ + $d( $rest_modules $d( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $d( $system:ident )+; + $d( $parsed_modules:ident $d( <$parsed_generic:ident> )* ),*; + ; + ) => { + $macro_outer_name! { + pub enum $macro_enum_name for $runtime where system = $d( $system )* { + $d( + $parsed_modules $d( <$parsed_generic> )*, + )* + } + } + } + } + } +} + +__create_decl_macro!(__decl_outer_event, impl_outer_event, Event, $); +__create_decl_macro!(__decl_outer_origin, impl_outer_origin, Origin, $); + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_all_modules { + ( + $runtime:ident; + ; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + System: $module:ident::{ + Module $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_all_modules!( + $runtime; + $module; + $( $parsed_modules :: $parsed_name ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $system:ident )*; + $( $parsed_modules:ident :: $parsed_name: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_all_modules!( + $runtime; + $( $system )*; + $( $parsed_modules :: $parsed_name, )* $module::$name; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $system:ident )*; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{ + $ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_all_modules!( + $runtime; + $( $system )*; + $( $parsed_modules :: $parsed_name ),*; + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + $( + , $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $( $system:ident )*; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{} + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_all_modules!( + $runtime; + $( $system )*; + $( $parsed_modules :: $parsed_name ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $system:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + ; + ) => { + pub type System = system::Module<$runtime>; + $( + pub type $parsed_name = $parsed_modules::Module<$runtime>; + )* + type AllModules = ( $( $parsed_name, )* ); + } +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_outer_dispatch { + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + System: $module:ident::{ + $ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_dispatch!( + $runtime; + $( $parsed_modules :: $parsed_name ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{ + Call $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_dispatch!( + $runtime; + $( $parsed_modules :: $parsed_name, )* $module::$name; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{ + $ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_dispatch!( + $runtime; + $( $parsed_modules :: $parsed_name ),*; + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + $( + , $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{} + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_dispatch!( + $runtime; + $( $parsed_modules :: $parsed_name ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + ; + ) => { + impl_outer_dispatch!( + pub enum Call where origin: Origin { + $( $parsed_name, )* + } + ); + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_json_metadata { + ( + $runtime:ident; + ; + $( $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_json_metadata!( + $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_json_metadata!( + $runtime; + ; + $( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module with Storage }; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + ; + $( $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_json_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_json_metadata!( + $runtime; + ; + $( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module with Storage }; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $current_module:ident { $( $current_module_storage:tt )* } )*; + $( $parsed_modules:ident { Module $( with $parsed_storage:ident )* } ),*; + $name:ident: $module:ident::{ + $ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_json_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_json_metadata!( + $runtime; + ; + $( $parsed_modules { Module $( with $parsed_storage )* }, )* $module { Module }; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $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_json_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 )* } ),*; + ; + ) => { + impl_json_metadata!( + for $runtime with modules + $( $parsed_modules::Module $(with $parsed_storage)*, )* + ); + } +} +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_outer_log { + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( $parsed_modules:ident( $( $parsed_args:ident ),* ) ),*; + $name:ident: $module:ident::{ + Log ( $( $args:ident ),* ) $(, $modules:ident $( ( $( $modules_args:ident )* ) )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( ( $( $rest_modules_args:ident )* ) )* ),* + })*; + ) => { + __decl_outer_log!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( $parsed_modules ( $( $parsed_args ),* ), )* $module ( $( $args ),* ); + $( + $rest_name: $rest_module::{ + $( $rest_modules $( ( $( $rest_modules_args ),* ) )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( $parsed_modules:ident( $( $parsed_args:ident ),* ) ),*; + $name:ident: $module:ident::{ + $ignore:ident $( ( $( $args_ignore:ident ),* ) )* + $(, $modules:ident $( ( $( $modules_args:ident ),* ) )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( ( $( $rest_modules_args:ident )* ) )* ),* + })*; + ) => { + __decl_outer_log!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( $parsed_modules ( $( $parsed_args ),* ) ),*; + $name: $module::{ $( $modules $( ( $( $modules_args ),* ) )* ),* } + $( + , $rest_name: $rest_module::{ + $( $rest_modules $( ( $( $rest_modules_args ),* ) )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( $parsed_modules:ident( $( $parsed_args:ident ),* ) ),*; + $name:ident: $module:ident::{} + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( ( $( $rest_modules_args:ident )* ) )* ),* + })*; + ) => { + __decl_outer_log!( + $runtime; + $log_internal < $( $log_genarg ),* >; + $( $parsed_modules ( $( $parsed_args ),* ) ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( ( $( $rest_modules_args ),* ) )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $log_internal:ident <$( $log_genarg:ty ),+>; + $( $parsed_modules:ident( $( $parsed_args:ident ),* ) ),*; + ; + ) => { + impl_outer_log!( + pub enum Log($log_internal: DigestItem<$( $log_genarg)* >) for $runtime { + $( $parsed_modules ( $( $parsed_args ),* ) ),* + } + ); + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_outer_config { + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{ + Config $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_config!( + $runtime; + $( $parsed_modules :: $parsed_name, )* $module::$name; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{ + $ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )* + } + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_config!( + $runtime; + $( $parsed_modules :: $parsed_name ),*; + $name: $module::{ $( $modules $( <$modules_generic> )* ),* } + $( + , $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + )*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + $name:ident: $module:ident::{} + $(, $rest_name:ident : $rest_module:ident::{ + $( $rest_modules:ident $( <$rest_modules_generic:ident> )* ),* + })*; + ) => { + __decl_outer_config!( + $runtime; + $( $parsed_modules :: $parsed_name ),*; + $( + $rest_name: $rest_module::{ + $( $rest_modules $( <$rest_modules_generic> )* ),* + } + ),*; + ); + }; + ( + $runtime:ident; + $( $parsed_modules:ident :: $parsed_name:ident ),*; + ; + ) => { + mashup! { + $( + substrate_generate_config_name["config-name" $parsed_name] = $parsed_name Config; + )* + } + + substrate_generate_config_name! { + impl_outer_config!( + pub struct GenesisConfig for $runtime { + $( + "config-name" $parsed_name => $parsed_modules, + )* + } + ); + } + }; +} From e0c5bb3ee96b1aeeb8100b343e8dfe19231a30d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 10:10:48 +0200 Subject: [PATCH 3/7] Add documentation --- srml/support/src/runtime.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/srml/support/src/runtime.rs b/srml/support/src/runtime.rs index f2660925e345d..220d617f21077 100644 --- a/srml/support/src/runtime.rs +++ b/srml/support/src/runtime.rs @@ -14,6 +14,36 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +/// Construct a runtime, with the given name and the given modules. +/// +/// # Example: +/// +/// ```nocompile +/// construct_runtime!( +/// pub enum Runtime with Log(interalIdent: DigestItem) { +/// System: system, +/// Test: test::{default, Log(Test)}, +/// Test2: test_with_long_module::{Module}, +/// } +/// ) +/// ``` +/// +/// The module `System: system` will expand to `System: system::{Module, Call, Storage, Event, Config}`. +/// The identifier `System` is the name of the module and the lower case identifier `system` is the +/// name of the rust module for this module. +/// The module `Test: test::{default, Log(Test)}` will expand to +/// `Test: test::{Module, Call, Storage, Event, Config, Log(Test)}`. +/// The module `Test2: test_with_long_module::{Module}` will expand to +/// `Test2: test_with_long_module::{Module}`. +/// +/// We provide support for the following types in a module: +/// - `Module` +/// - `Call` +/// - `Storage` +/// - `Event` or `Event` (if the event is generic) +/// - `Origin` or `Origin` (if the origin is generic) +/// - `Config` +/// - `Log( $(IDENT),* )` #[macro_export] macro_rules! construct_runtime { ( From e2599d5d94e32e13937542e5341450662f61405c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 10:16:56 +0200 Subject: [PATCH 4/7] Fixes wrong declaration of `contract` --- node/runtime/src/lib.rs | 2 +- node/runtime/wasm/Cargo.lock | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 2c519de1befea..edd065a76bffd 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -194,7 +194,7 @@ construct_runtime!( CouncilVoting: council_voting::{Module, Call, Storage, Event}, CouncilMotions: council_motions::{Module, Call, Storage, Event, Origin}, Treasury: treasury, - Contract: contract::{Module, Call, Log}, + Contract: contract::{Module, Call, Config}, } ); diff --git a/node/runtime/wasm/Cargo.lock b/node/runtime/wasm/Cargo.lock index d060de7274bb0..1db3544ad1c61 100644 --- a/node/runtime/wasm/Cargo.lock +++ b/node/runtime/wasm/Cargo.lock @@ -221,6 +221,24 @@ dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mashup" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mashup-impl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memoffset" version = "0.2.1" @@ -779,6 +797,7 @@ name = "srml-support" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1038,6 +1057,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" +"checksum mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d886e371548f5c66258a99df9ec03366bff02cc96ea3d3f8f346b5d2d6836de7" +"checksum mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8d426741e35fab52542d84dfee615f442c2b37247bee8b1ed5c25ca723487580" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" "checksum memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f72c93304ad51e21230ecbd0d2b58a3f94703bf9339d14aed88c3aaf5e8b7a56" From 604f647cdeef5ebf1905e4efdbc008248113f0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 12:51:37 +0200 Subject: [PATCH 5/7] Update dependencies to work on `no_std` --- Cargo.lock | 14 ++++++------- core/test-runtime/wasm/Cargo.lock | 35 ++++++++++++++++++++++++------- node/runtime/wasm/Cargo.lock | 18 ++++++++-------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d882c3526c77..c1b1c50034b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -662,7 +662,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -670,7 +670,7 @@ name = "hex-literal-impl" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1243,7 +1243,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1251,7 +1251,7 @@ name = "mashup-impl" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1832,15 +1832,15 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-hack-impl" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] diff --git a/core/test-runtime/wasm/Cargo.lock b/core/test-runtime/wasm/Cargo.lock index dbb3dc7876f8e..db42eb9780b0c 100644 --- a/core/test-runtime/wasm/Cargo.lock +++ b/core/test-runtime/wasm/Cargo.lock @@ -174,7 +174,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -182,7 +182,7 @@ name = "hex-literal-impl" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -221,6 +221,24 @@ dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mashup" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mashup-impl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memoffset" version = "0.2.1" @@ -347,15 +365,15 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-hack-impl" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -550,6 +568,7 @@ name = "srml-support" version = "0.1.0" dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", @@ -764,6 +783,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" +"checksum mashup 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d886e371548f5c66258a99df9ec03366bff02cc96ea3d3f8f346b5d2d6836de7" +"checksum mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8d426741e35fab52542d84dfee615f442c2b37247bee8b1ed5c25ca723487580" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" "checksum memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f72c93304ad51e21230ecbd0d2b58a3f94703bf9339d14aed88c3aaf5e8b7a56" @@ -780,8 +801,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum patricia-trie 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fa27fc4a972a03d64e5170d7facd2c84c6ed425b38ce62ad98dcfee2f7845b3b" "checksum plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "95fa6386b1d34aaf0adb9b7dd2885dbe7c34190e6263785e5a7ec2b19044a90f" -"checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" -"checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" +"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" +"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" "checksum proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1fa93823f53cfd0f5ac117b189aed6cfdfb2cfc0a9d82e956dd7927595ed7d46" "checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" diff --git a/node/runtime/wasm/Cargo.lock b/node/runtime/wasm/Cargo.lock index 1db3544ad1c61..51fb8d1e78e9c 100644 --- a/node/runtime/wasm/Cargo.lock +++ b/node/runtime/wasm/Cargo.lock @@ -174,7 +174,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -182,7 +182,7 @@ name = "hex-literal-impl" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -227,7 +227,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "mashup-impl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -235,7 +235,7 @@ name = "mashup-impl" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -406,15 +406,15 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-hack-impl" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1075,8 +1075,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum patricia-trie 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fa27fc4a972a03d64e5170d7facd2c84c6ed425b38ce62ad98dcfee2f7845b3b" "checksum plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "95fa6386b1d34aaf0adb9b7dd2885dbe7c34190e6263785e5a7ec2b19044a90f" -"checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" -"checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" +"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" +"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" "checksum proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1fa93823f53cfd0f5ac117b189aed6cfdfb2cfc0a9d82e956dd7927595ed7d46" "checksum pwasm-utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "efd695333cfae6e9dbe2703a6d040e252b57a6fc3b9a65c712615ac042b2e0c5" "checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035" From f07d5f9efa09efb31875abf7f0ba85b4de6d2b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 12:59:47 +0200 Subject: [PATCH 6/7] One more `Cargo.lock` update --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1b1c50034b4d..59c8980d14457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3935,8 +3935,8 @@ dependencies = [ "checksum plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "95fa6386b1d34aaf0adb9b7dd2885dbe7c34190e6263785e5a7ec2b19044a90f" "checksum pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28ea5118e2f41bfbc974b28d88c07621befd1fa5d6ec23549be96302a1a59dd2" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" -"checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" -"checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" +"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" +"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" "checksum proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1fa93823f53cfd0f5ac117b189aed6cfdfb2cfc0a9d82e956dd7927595ed7d46" "checksum protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7fec4b8f0fa26c52d29c66e93e8624aad859458ec5e5d4f6ddf923954293436a" "checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07" From ebd1d7139034bd490c9d1920636b22c5cd0d9cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 17 Sep 2018 14:24:30 +0200 Subject: [PATCH 7/7] Address comments --- node/runtime/src/lib.rs | 1 + srml/support/src/runtime.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index edd065a76bffd..ef6370672fb70 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -17,6 +17,7 @@ //! The Substrate runtime. This can be compiled with ``#[no_std]`, ready for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit="256"] #[macro_use] diff --git a/srml/support/src/runtime.rs b/srml/support/src/runtime.rs index 220d617f21077..d3e755b4925da 100644 --- a/srml/support/src/runtime.rs +++ b/srml/support/src/runtime.rs @@ -982,9 +982,9 @@ macro_rules! __decl_outer_config { ) => { mashup! { $( - substrate_generate_config_name["config-name" $parsed_name] = $parsed_name Config; + substrate_generate_config_name["config-name" $parsed_name] = $parsed_name Config; )* - } + } substrate_generate_config_name! { impl_outer_config!(