support: BuildStorage methods to take self reference (#3884)

* support: BuildStorage methods to take self reference.

There is no reason to consume the GenesisConfig when using it to
initialize a new storage backend. Instead, build_storage and
assimilate_storage now operator on self references.

* Bump node runtime impl_version.
This commit is contained in:
Jim Posen
2019-10-25 11:44:57 +02:00
committed by GitHub
parent 44696f46c3
commit e05e624a3a
5 changed files with 21 additions and 23 deletions
+11 -13
View File
@@ -123,14 +123,14 @@ use crate::traits::IdentifyAccount;
#[cfg(feature = "std")]
pub trait BuildStorage: Sized {
/// Build the storage out of this builder.
fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
fn build_storage(&self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
let mut storage = (Default::default(), Default::default());
self.assimilate_storage(&mut storage)?;
Ok(storage)
}
/// Assimilate the storage for this module into pre-existing overlays.
fn assimilate_storage(
self,
&self,
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
) -> Result<(), String>;
}
@@ -140,26 +140,24 @@ pub trait BuildStorage: Sized {
pub trait BuildModuleGenesisStorage<T, I>: Sized {
/// Create the module genesis storage into the given `storage` and `child_storage`.
fn build_module_genesis_storage(
self,
&self,
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
) -> Result<(), String>;
}
#[cfg(feature = "std")]
impl BuildStorage for (StorageOverlay, ChildrenStorageOverlay) {
fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
Ok(self)
}
fn assimilate_storage(
self,
&self,
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
)-> Result<(), String> {
storage.0.extend(self.0);
for (k, other_map) in self.1.into_iter() {
storage.0.extend(self.0.iter().map(|(k, v)| (k.clone(), v.clone())));
for (k, other_map) in self.1.iter() {
let k = k.clone();
if let Some(map) = storage.1.get_mut(&k) {
map.extend(other_map);
map.extend(other_map.iter().map(|(k, v)| (k.clone(), v.clone())));
} else {
storage.1.insert(k, other_map);
storage.1.insert(k, other_map.clone());
}
}
Ok(())
@@ -522,11 +520,11 @@ macro_rules! impl_outer_config {
#[cfg(any(feature = "std", test))]
impl $crate::BuildStorage for $main {
fn assimilate_storage(
self,
&self,
storage: &mut ($crate::StorageOverlay, $crate::ChildrenStorageOverlay),
) -> std::result::Result<(), String> {
$(
if let Some(extra) = self.[< $snake $(_ $instance )? >] {
if let Some(ref extra) = self.[< $snake $(_ $instance )? >] {
$crate::impl_outer_config! {
@CALL_FN
$concrete;