Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sc-chainspec: Switch to assimilate_storage #12720

Merged
merged 1 commit into from
Nov 16, 2022
Merged
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
37 changes: 15 additions & 22 deletions client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,28 @@ impl<G: RuntimeGenesis> GenesisSource<G> {
}

impl<G: RuntimeGenesis, E> BuildStorage for ChainSpec<G, E> {
fn build_storage(&self) -> Result<Storage, String> {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
match self.genesis.resolve()? {
Genesis::Runtime(gc) => gc.build_storage(),
Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => Ok(Storage {
top: map.into_iter().map(|(k, v)| (k.0, v.0)).collect(),
children_default: children_map
.into_iter()
.map(|(storage_key, child_content)| {
let child_info = ChildInfo::new_default(storage_key.0.as_slice());
(
storage_key.0,
StorageChild {
data: child_content.into_iter().map(|(k, v)| (k.0, v.0)).collect(),
child_info,
},
)
})
.collect(),
}),
Genesis::Runtime(gc) => gc.assimilate_storage(storage),
Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => {
storage.top.extend(map.into_iter().map(|(k, v)| (k.0, v.0)));
children_map.into_iter().for_each(|(k, v)| {
let child_info = ChildInfo::new_default(k.0.as_slice());
storage
.children_default
.entry(k.0)
.or_insert_with(|| StorageChild { data: Default::default(), child_info })
.data
.extend(v.into_iter().map(|(k, v)| (k.0, v.0)));
});
Ok(())
},
// The `StateRootHash` variant exists as a way to keep note that other clients support
// it, but Substrate itself isn't capable of loading chain specs with just a hash at the
// moment.
Genesis::StateRootHash(_) => Err("Genesis storage in hash format not supported".into()),
}
}

fn assimilate_storage(&self, _: &mut Storage) -> Result<(), String> {
Err("`assimilate_storage` not implemented for `ChainSpec`.".into())
}
}

pub type GenesisStorage = BTreeMap<StorageKey, StorageData>;
Expand Down