mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 09:47:56 +00:00
Support multi trie in genesis generation (#958)
* Support multi trie in genesis generation * Fix merge issues
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user