Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/sr-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ substrate-primitives = { path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
log = { version = "0.4", optional = true }
paste = { version = "0.1"}

[dev-dependencies]
serde_json = "1.0"
Expand Down
120 changes: 95 additions & 25 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub use serde;
#[doc(hidden)]
pub use rstd;

#[doc(hidden)]
pub use paste;

#[cfg(feature = "std")]
pub use runtime_io::{StorageOverlay, ChildrenStorageOverlay};

Expand Down Expand Up @@ -101,7 +104,22 @@ pub trait BuildStorage: Sized {
Ok((storage, child_storage))
}
/// Assimilate the storage for this module into pre-existing overlays.
fn assimilate_storage(self, storage: &mut StorageOverlay, child_storage: &mut ChildrenStorageOverlay) -> Result<(), String>;
fn assimilate_storage(
self,
storage: &mut StorageOverlay,
child_storage: &mut ChildrenStorageOverlay
) -> Result<(), String>;
}

/// Somethig that can build the genesis storage of a module.
#[cfg(feature = "std")]
pub trait BuildModuleGenesisStorage<T, I>: Sized {
/// Create the module genesis storage into the given `storage` and `child_storage`.
fn build_module_genesis_storage(
self,
storage: &mut StorageOverlay,
child_storage: &mut ChildrenStorageOverlay
) -> Result<(), String>;
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -585,26 +603,32 @@ pub fn verify_encoded_lazy<V: Verify, T: codec::Encode>(sig: &V, item: &T, signe
/// Helper macro for `impl_outer_config`
#[macro_export]
macro_rules! __impl_outer_config_types {
// Generic + Instance
(
$concrete:ident $config:ident $snake:ident < $ignore:ident, $instance:path > $( $rest:tt )*
$concrete:ident $config:ident $snake:ident { $instance:ident } < $ignore:ident >;
$( $rest:tt )*
) => {
#[cfg(any(feature = "std", test))]
pub type $config = $snake::GenesisConfig<$concrete, $instance>;
$crate::__impl_outer_config_types! {$concrete $($rest)*}
pub type $config = $snake::GenesisConfig<$concrete, $snake::$instance>;
$crate::__impl_outer_config_types! { $concrete $( $rest )* }
};
// Generic
(
$concrete:ident $config:ident $snake:ident < $ignore:ident > $( $rest:tt )*
$concrete:ident $config:ident $snake:ident < $ignore:ident >;
$( $rest:tt )*
) => {
#[cfg(any(feature = "std", test))]
pub type $config = $snake::GenesisConfig<$concrete>;
$crate::__impl_outer_config_types! {$concrete $($rest)*}
$crate::__impl_outer_config_types! { $concrete $( $rest )* }
};
// No Generic and maybe Instance
(
$concrete:ident $config:ident $snake:ident $( $rest:tt )*
$concrete:ident $config:ident $snake:ident $( { $instance:ident } )?;
$( $rest:tt )*
) => {
#[cfg(any(feature = "std", test))]
pub type $config = $snake::GenesisConfig;
__impl_outer_config_types! {$concrete $($rest)*}
$crate::__impl_outer_config_types! { $concrete $( $rest )* }
};
($concrete:ident) => ()
}
Expand All @@ -619,30 +643,76 @@ macro_rules! __impl_outer_config_types {
macro_rules! impl_outer_config {
(
pub struct $main:ident for $concrete:ident {
$( $config:ident => $snake:ident $( < $generic:ident $(, $instance:path)? > )*, )*
$( $config:ident =>
$snake:ident $( $instance:ident )? $( <$generic:ident> )*, )*
}
) => {
$crate::__impl_outer_config_types! { $concrete $( $config $snake $( < $generic $(, $instance)? > )* )* }
#[cfg(any(feature = "std", test))]
#[derive($crate::serde::Serialize, $crate::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct $main {
$(
pub $snake: Option<$config>,
)*
$crate::__impl_outer_config_types! {
$concrete $( $config $snake $( { $instance } )? $( <$generic> )*; )*
}
#[cfg(any(feature = "std", test))]
impl $crate::BuildStorage for $main {
fn assimilate_storage(self, top: &mut $crate::StorageOverlay, children: &mut $crate::ChildrenStorageOverlay) -> ::std::result::Result<(), String> {

$crate::paste::item! {
#[cfg(any(feature = "std", test))]
#[derive($crate::serde::Serialize, $crate::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct $main {
$(
if let Some(extra) = self.$snake {
extra.assimilate_storage(top, children)?;
}
pub [< $snake $(_ $instance )? >]: Option<$config>,
)*
Ok(())
}
#[cfg(any(feature = "std", test))]
impl $crate::BuildStorage for $main {
fn assimilate_storage(
self,
top: &mut $crate::StorageOverlay,
children: &mut $crate::ChildrenStorageOverlay
) -> std::result::Result<(), String> {
$(
if let Some(extra) = self.[< $snake $(_ $instance )? >] {
$crate::impl_outer_config! {
@CALL_FN
$concrete;
$snake;
$( $instance )?;
extra;
top;
children;
}
}
)*
Ok(())
}
}
}
};
(@CALL_FN
$runtime:ident;
$module:ident;
$instance:ident;
$extra:ident;
$top:ident;
$children:ident;
) => {
$crate::BuildModuleGenesisStorage::<$runtime, $module::$instance>::build_module_genesis_storage(
$extra,
$top,
$children,
)?;
};
(@CALL_FN
$runtime:ident;
$module:ident;
;
$extra:ident;
$top:ident;
$children:ident;
) => {
$crate::BuildModuleGenesisStorage::<$runtime, $module::__InherentHiddenInstance>::build_module_genesis_storage(
$extra,
$top,
$children,
)?;
}
}

Expand Down
1 change: 1 addition & 0 deletions core/test-runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ construct_runtime!(
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{default, Config<T>},
System: system::{Module, Call, Storage, Config, Event},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Indices: indices::{default, Config<T>},
Expand Down
10 changes: 3 additions & 7 deletions node-template/runtime/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ decl_module! {

// TODO: Code to execute when something calls this.
// For example: the following line stores the passed in u32 in the storage
<Something<T>>::put(something);
Something::put(something);

// here we are raising the Something event
Self::deposit_event(RawEvent::SomethingStored(something, who));
Expand All @@ -72,11 +72,7 @@ mod tests {
use runtime_io::with_externalities;
use primitives::{H256, Blake2Hasher};
use support::{impl_outer_origin, assert_ok};
use runtime_primitives::{
BuildStorage,
traits::{BlakeTwo256, IdentityLookup},
testing::Header,
};
use runtime_primitives::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};

impl_outer_origin! {
pub enum Origin for Test {}
Expand Down Expand Up @@ -106,7 +102,7 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
system::GenesisConfig::default().build_storage::<Test>().unwrap().0.into()
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions node-template/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion node-template/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>, endowed_accounts: Vec<
system: Some(SystemConfig {
code: include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/node_template_runtime_wasm.compact.wasm").to_vec(),
changes_trie_config: Default::default(),
_genesis_phantom_data: Default::default(),
}),
aura: Some(AuraConfig {
authorities: initial_authorities.clone(),
Expand Down
4 changes: 0 additions & 4 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
GenesisConfig {
system: Some(SystemConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // FIXME change once we have #1252
_genesis_phantom_data: Default::default(),
changes_trie_config: Default::default(),
}),
balances: Some(BalancesConfig {
Expand Down Expand Up @@ -191,7 +190,6 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
_genesis_phantom_data: Default::default(),
}),
}
}
Expand Down Expand Up @@ -274,7 +272,6 @@ pub fn testnet_genesis(
GenesisConfig {
system: Some(SystemConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
_genesis_phantom_data: Default::default(),
changes_trie_config: Default::default(),
}),
indices: Some(IndicesConfig {
Expand Down Expand Up @@ -358,7 +355,6 @@ pub fn testnet_genesis(
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
_genesis_phantom_data: Default::default(),
}),
}
}
Expand Down
1 change: 0 additions & 1 deletion node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ mod tests {
contracts: Some(Default::default()),
sudo: Some(Default::default()),
grandpa: Some(GrandpaConfig {
_genesis_phantom_data: Default::default(),
authorities: vec![],
}),
}.build_storage().unwrap().0);
Expand Down
6 changes: 3 additions & 3 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,19 @@ construct_runtime!(
NodeBlock = node_primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
System: system::{Module, Call, Storage, Config, Event},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Indices: indices,
Balances: balances,
Session: session::{Module, Call, Storage, Event, Config<T>},
Staking: staking::{default, OfflineWorker},
Democracy: democracy,
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
Council: council::{Module, Call, Storage, Event<T>},
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin<T>},
CouncilSeats: council_seats::{Config<T>},
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config<T>, Event},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Treasury: treasury,
Contracts: contracts,
Sudo: sudo,
Expand Down
1 change: 1 addition & 0 deletions node/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions srml/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ mod tests {
use substrate_primitives::{H256, Blake2Hasher};
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use primitives::{
BuildStorage,
traits::{BlakeTwo256, IdentityLookup},
testing::Header
};
use primitives::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};

impl_outer_origin! {
pub enum Origin for Test {}
Expand Down Expand Up @@ -280,7 +276,7 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into()
system::GenesisConfig::default().build_storage::<Test>().unwrap().0.into()
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions srml/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#![cfg(test)]

use primitives::{BuildStorage, traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use primitives::{traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use srml_support::impl_outer_origin;
use runtime_io;
use substrate_primitives::{H256, Blake2Hasher};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Trait for Test {
}

pub fn new_test_ext(authorities: Vec<u64>) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap().0;
t.extend(timestamp::GenesisConfig::<Test>{
minimum_period: 1,
}.build_storage().unwrap().0);
Expand Down
Loading