Adds export-state subcommand (#5842)

* Export state cli

* More work

* Fix tests

* Make it work

* Fix compilation

* Apply suggestions from code review
This commit is contained in:
Bastian Köcher
2020-04-30 15:44:40 +02:00
committed by GitHub
parent 929bd07bef
commit 5b8d3607e9
12 changed files with 329 additions and 86 deletions
+7 -6
View File
@@ -92,9 +92,9 @@ pub struct StorageData(
#[cfg(feature = "std")]
pub type StorageMap = std::collections::BTreeMap<Vec<u8>, Vec<u8>>;
/// Child trie storage data.
#[cfg(feature = "std")]
#[derive(Debug, PartialEq, Eq, Clone)]
/// Child trie storage data.
pub struct StorageChild {
/// Child data for storage.
pub data: StorageMap,
@@ -103,9 +103,9 @@ pub struct StorageChild {
pub child_info: ChildInfo,
}
/// Struct containing data needed for a storage.
#[cfg(feature = "std")]
#[derive(Default, Debug, Clone)]
/// Struct containing data needed for a storage.
pub struct Storage {
/// Top trie storage data.
pub top: StorageMap,
@@ -148,6 +148,9 @@ pub mod well_known_keys {
/// Prefix of child storage keys.
pub const CHILD_STORAGE_KEY_PREFIX: &'static [u8] = b":child_storage:";
/// Prefix of the default child storage keys in the top trie.
pub const DEFAULT_CHILD_STORAGE_KEY_PREFIX: &'static [u8] = b":child_storage:default:";
/// Whether a key is a child storage key.
///
/// This is convenience function which basically checks if the given `key` starts
@@ -300,7 +303,7 @@ impl ChildType {
/// is one.
pub fn parent_prefix(&self) -> &'static [u8] {
match self {
&ChildType::ParentKeyId => DEFAULT_CHILD_TYPE_PARENT_PREFIX,
&ChildType::ParentKeyId => well_known_keys::DEFAULT_CHILD_STORAGE_KEY_PREFIX,
}
}
}
@@ -331,12 +334,10 @@ impl ChildTrieParentKeyId {
}
}
const DEFAULT_CHILD_TYPE_PARENT_PREFIX: &'static [u8] = b":child_storage:default:";
#[test]
fn test_prefix_default_child_info() {
let child_info = ChildInfo::new_default(b"any key");
let prefix = child_info.child_type().parent_prefix();
assert!(prefix.starts_with(well_known_keys::CHILD_STORAGE_KEY_PREFIX));
assert!(prefix.starts_with(DEFAULT_CHILD_TYPE_PARENT_PREFIX));
assert!(prefix.starts_with(well_known_keys::DEFAULT_CHILD_STORAGE_KEY_PREFIX));
}