mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 09:01:08 +00:00
Add typedefs for storage types (#4654)
* Add typedefs for storage types * Fix after merge
This commit is contained in:
committed by
Bastian Köcher
parent
20ce6c120c
commit
482ca522cc
@@ -18,6 +18,8 @@
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::StorageKey;
|
||||
|
||||
/// Changes trie build cache.
|
||||
///
|
||||
/// Helps to avoid read of changes tries from the database when digest trie
|
||||
@@ -36,7 +38,7 @@ pub struct BuildCache<H, N> {
|
||||
/// The `Option<Vec<u8>>` in inner `HashMap` stands for the child storage key.
|
||||
/// If it is `None`, then the `HashSet` contains keys changed in top-level storage.
|
||||
/// If it is `Some`, then the `HashSet` contains keys changed in child storage, identified by the key.
|
||||
changed_keys: HashMap<H, HashMap<Option<Vec<u8>>, HashSet<Vec<u8>>>>,
|
||||
changed_keys: HashMap<H, HashMap<Option<StorageKey>, HashSet<StorageKey>>>,
|
||||
}
|
||||
|
||||
/// The action to perform when block-with-changes-trie is imported.
|
||||
@@ -54,7 +56,7 @@ pub struct CachedBuildData<H, N> {
|
||||
block: N,
|
||||
trie_root: H,
|
||||
digest_input_blocks: Vec<N>,
|
||||
changed_keys: HashMap<Option<Vec<u8>>, HashSet<Vec<u8>>>,
|
||||
changed_keys: HashMap<Option<StorageKey>, HashSet<StorageKey>>,
|
||||
}
|
||||
|
||||
/// The action to perform when block-with-changes-trie is imported.
|
||||
@@ -70,7 +72,7 @@ pub(crate) enum IncompleteCacheAction<N> {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct IncompleteCachedBuildData<N> {
|
||||
digest_input_blocks: Vec<N>,
|
||||
changed_keys: HashMap<Option<Vec<u8>>, HashSet<Vec<u8>>>,
|
||||
changed_keys: HashMap<Option<StorageKey>, HashSet<StorageKey>>,
|
||||
}
|
||||
|
||||
impl<H, N> BuildCache<H, N>
|
||||
@@ -87,7 +89,7 @@ impl<H, N> BuildCache<H, N>
|
||||
}
|
||||
|
||||
/// Get cached changed keys for changes trie with given root.
|
||||
pub fn get(&self, root: &H) -> Option<&HashMap<Option<Vec<u8>>, HashSet<Vec<u8>>>> {
|
||||
pub fn get(&self, root: &H) -> Option<&HashMap<Option<StorageKey>, HashSet<StorageKey>>> {
|
||||
self.changed_keys.get(&root)
|
||||
}
|
||||
|
||||
@@ -96,7 +98,7 @@ impl<H, N> BuildCache<H, N>
|
||||
pub fn with_changed_keys(
|
||||
&self,
|
||||
root: &H,
|
||||
functor: &mut dyn FnMut(&HashMap<Option<Vec<u8>>, HashSet<Vec<u8>>>),
|
||||
functor: &mut dyn FnMut(&HashMap<Option<StorageKey>, HashSet<StorageKey>>),
|
||||
) -> bool {
|
||||
match self.changed_keys.get(&root) {
|
||||
Some(changed_keys) => {
|
||||
@@ -162,8 +164,8 @@ impl<N> IncompleteCacheAction<N> {
|
||||
/// Insert changed keys of given storage into cached data.
|
||||
pub(crate) fn insert(
|
||||
self,
|
||||
storage_key: Option<Vec<u8>>,
|
||||
changed_keys: HashSet<Vec<u8>>,
|
||||
storage_key: Option<StorageKey>,
|
||||
changed_keys: HashSet<StorageKey>,
|
||||
) -> Self {
|
||||
match self {
|
||||
IncompleteCacheAction::CacheBuildData(build_data) =>
|
||||
@@ -198,8 +200,8 @@ impl<N> IncompleteCachedBuildData<N> {
|
||||
|
||||
fn insert(
|
||||
mut self,
|
||||
storage_key: Option<Vec<u8>>,
|
||||
changed_keys: HashSet<Vec<u8>>,
|
||||
storage_key: Option<StorageKey>,
|
||||
changed_keys: HashSet<StorageKey>,
|
||||
) -> Self {
|
||||
self.changed_keys.insert(storage_key, changed_keys);
|
||||
self
|
||||
@@ -259,4 +261,4 @@ mod tests {
|
||||
|
||||
assert_eq!(cache.changed_keys.len(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user