mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 16:11:05 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user