pub trait Backend<H: Hasher>: Debug {
type Error: Error;
type Transaction: Consolidate + Default + Send;
type TrieBackendStorage: TrieBackendStorage<H>;
Show 27 methods
// Required methods
fn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, Self::Error>;
fn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageValue>, Self::Error>;
fn next_storage_key(
&self,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error>;
fn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error>;
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
);
fn for_key_values_with_prefix<F: FnMut(&[u8], &[u8])>(
&self,
prefix: &[u8],
f: F,
);
fn for_child_keys_with_prefix<F: FnMut(&[u8])>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F,
);
fn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, Self::Transaction)
where H::Out: Ord;
fn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, bool, Self::Transaction)
where H::Out: Ord;
fn pairs(&self) -> Vec<(StorageKey, StorageValue)>;
fn register_overlay_stats(&mut self, _stats: &StateMachineStats);
fn usage_info(&self) -> UsageInfo;
// Provided methods
fn storage_hash(&self, key: &[u8]) -> Result<Option<H::Out>, Self::Error> { ... }
fn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<H::Out>, Self::Error> { ... }
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> { ... }
fn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<bool, Self::Error> { ... }
fn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], f: F) { ... }
fn keys(&self, prefix: &[u8]) -> Vec<StorageKey> ⓘ { ... }
fn child_keys(
&self,
child_info: &ChildInfo,
prefix: &[u8],
) -> Vec<StorageKey> ⓘ { ... }
fn as_trie_backend(
&mut self,
) -> Option<&TrieBackend<Self::TrieBackendStorage, H>> { ... }
fn full_storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>,
) -> (H::Out, Self::Transaction)
where H::Out: Ord + Encode { ... }
fn wipe(&self) -> Result<(), Self::Error> { ... }
fn commit(
&self,
_: H::Out,
_: Self::Transaction,
_: StorageCollection,
_: ChildStorageCollection,
) -> Result<(), Self::Error> { ... }
fn read_write_count(&self) -> (u32, u32, u32, u32) { ... }
fn reset_read_write_count(&self) { ... }
fn get_whitelist(&self) -> Vec<TrackedStorageKey> { ... }
fn set_whitelist(&self, _: Vec<TrackedStorageKey>) { ... }
}Expand description
A state backend is used to read state data and can have changes committed to it.
The clone operation (if implemented) should be cheap.
Required Associated Types§
Sourcetype Transaction: Consolidate + Default + Send
type Transaction: Consolidate + Default + Send
Storage changes to be applied if committing
Sourcetype TrieBackendStorage: TrieBackendStorage<H>
type TrieBackendStorage: TrieBackendStorage<H>
Type of trie backend storage.
Required Methods§
Sourcefn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, Self::Error>
fn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, Self::Error>
Get keyed storage or None if there is nothing associated.
Sourcefn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageValue>, Self::Error>
fn child_storage( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<StorageValue>, Self::Error>
Get keyed child storage or None if there is nothing associated.
Sourcefn next_storage_key(
&self,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error>
fn next_storage_key( &self, key: &[u8], ) -> Result<Option<StorageKey>, Self::Error>
Return the next key in storage in lexicographic order or None if there is no value.
Sourcefn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error>
fn next_child_storage_key( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<StorageKey>, Self::Error>
Return the next key in child storage in lexicographic order or None if there is no value.
Sourcefn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
)
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>( &self, child_info: &ChildInfo, f: F, )
Retrieve all entries keys of child storage and call f for each of those keys.
Aborts as soon as f returns false.
Sourcefn for_key_values_with_prefix<F: FnMut(&[u8], &[u8])>(
&self,
prefix: &[u8],
f: F,
)
fn for_key_values_with_prefix<F: FnMut(&[u8], &[u8])>( &self, prefix: &[u8], f: F, )
Retrieve all entries keys and values of which start with the given prefix and
call f for each of those keys.
Sourcefn for_child_keys_with_prefix<F: FnMut(&[u8])>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F,
)
fn for_child_keys_with_prefix<F: FnMut(&[u8])>( &self, child_info: &ChildInfo, prefix: &[u8], f: F, )
Retrieve all child entries keys which start with the given prefix and
call f for each of those keys.
Sourcefn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, Self::Transaction)
fn storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, ) -> (H::Out, Self::Transaction)
Calculate the storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. Does not include child storage updates.
Sourcefn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, bool, Self::Transaction)
fn child_storage_root<'a>( &self, child_info: &ChildInfo, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, ) -> (H::Out, bool, Self::Transaction)
Calculate the child storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. The second argument is true if child storage root equals default storage root.
Sourcefn pairs(&self) -> Vec<(StorageKey, StorageValue)>
fn pairs(&self) -> Vec<(StorageKey, StorageValue)>
Get all key/value pairs into a Vec.
Sourcefn register_overlay_stats(&mut self, _stats: &StateMachineStats)
fn register_overlay_stats(&mut self, _stats: &StateMachineStats)
Register stats from overlay of state machine.
By default nothing is registered.
Sourcefn usage_info(&self) -> UsageInfo
fn usage_info(&self) -> UsageInfo
Query backend usage statistics (i/o, memory)
Not all implementations are expected to be able to do this. In the case when they don’t, empty statistics is returned.
Provided Methods§
Sourcefn storage_hash(&self, key: &[u8]) -> Result<Option<H::Out>, Self::Error>
fn storage_hash(&self, key: &[u8]) -> Result<Option<H::Out>, Self::Error>
Get keyed storage value hash or None if there is nothing associated.
Sourcefn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<H::Out>, Self::Error>
fn child_storage_hash( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<H::Out>, Self::Error>
Get child keyed storage value hash or None if there is nothing associated.
Sourcefn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error>
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error>
true if a key exists in storage.
Sourcefn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<bool, Self::Error>
fn exists_child_storage( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<bool, Self::Error>
true if a key exists in child storage.
Sourcefn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], f: F)
fn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], f: F)
Retrieve all entries keys which start with the given prefix and
call f for each of those keys.
Sourcefn child_keys(&self, child_info: &ChildInfo, prefix: &[u8]) -> Vec<StorageKey> ⓘ
fn child_keys(&self, child_info: &ChildInfo, prefix: &[u8]) -> Vec<StorageKey> ⓘ
Get all keys of child storage with given prefix
Sourcefn as_trie_backend(
&mut self,
) -> Option<&TrieBackend<Self::TrieBackendStorage, H>>
fn as_trie_backend( &mut self, ) -> Option<&TrieBackend<Self::TrieBackendStorage, H>>
Try convert into trie backend.
Sourcefn full_storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>,
) -> (H::Out, Self::Transaction)
fn full_storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>, ) -> (H::Out, Self::Transaction)
Calculate the storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. Does include child storage updates.
Sourcefn commit(
&self,
_: H::Out,
_: Self::Transaction,
_: StorageCollection,
_: ChildStorageCollection,
) -> Result<(), Self::Error>
fn commit( &self, _: H::Out, _: Self::Transaction, _: StorageCollection, _: ChildStorageCollection, ) -> Result<(), Self::Error>
Commit given transaction to storage.
Sourcefn reset_read_write_count(&self)
fn reset_read_write_count(&self)
Get the read/write count of the db
Sourcefn get_whitelist(&self) -> Vec<TrackedStorageKey>
fn get_whitelist(&self) -> Vec<TrackedStorageKey>
Get the whitelist for tracking db reads/writes
Sourcefn set_whitelist(&self, _: Vec<TrackedStorageKey>)
fn set_whitelist(&self, _: Vec<TrackedStorageKey>)
Update the whitelist for tracking db reads/writes
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.