Support multi trie in genesis generation (#958)

* Support multi trie in genesis generation

* Fix merge issues
This commit is contained in:
Wei Tang
2018-11-01 16:30:03 +08:00
committed by Gav Wood
parent ac4a188e15
commit b21de8a0b5
45 changed files with 292 additions and 213 deletions
+16 -7
View File
@@ -79,6 +79,10 @@ pub use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
pub type StorageMap = HashMap<Vec<u8>, Vec<u8>>;
/// A set of key value pairs for children storage;
#[cfg(feature = "std")]
pub type ChildrenStorageMap = HashMap<Vec<u8>, StorageMap>;
/// Complex storage builder stuff.
#[cfg(feature = "std")]
pub trait BuildStorage {
@@ -87,13 +91,13 @@ pub trait BuildStorage {
trace!(target: "build_storage", "{} <= {}", substrate_primitives::hexdisplay::HexDisplay::from(&r), ascii_format(data));
r
}
fn build_storage(self) -> Result<StorageMap, String>;
fn build_storage(self) -> Result<(StorageMap, ChildrenStorageMap), String>;
}
#[cfg(feature = "std")]
impl BuildStorage for StorageMap {
fn build_storage(self) -> Result<StorageMap, String> {
Ok(self)
fn build_storage(self) -> Result<(StorageMap, ChildrenStorageMap), String> {
Ok((self, Default::default()))
}
}
@@ -308,14 +312,19 @@ macro_rules! impl_outer_config {
}
#[cfg(any(feature = "std", test))]
impl $crate::BuildStorage for $main {
fn build_storage(self) -> ::std::result::Result<$crate::StorageMap, String> {
let mut s = $crate::StorageMap::new();
fn build_storage(self) -> ::std::result::Result<($crate::StorageMap, $crate::ChildrenStorageMap), String> {
let mut top = $crate::StorageMap::new();
let mut children = $crate::ChildrenStorageMap::new();
$(
if let Some(extra) = self.$snake {
s.extend(extra.build_storage()?);
let (other_top, other_children) = extra.build_storage()?;
top.extend(other_top);
for (other_child_key, other_child_map) in other_children {
children.entry(other_child_key).or_default().extend(other_child_map);
}
}
)*
Ok(s)
Ok((top, children))
}
}
}