referrerpolicy=no-referrer-when-downgrade
sp_trie

Type Alias Lookup

Source
pub type Lookup<'a, 'cache, L, Q> = Lookup<'a, 'cache, L, Q>;
Expand description

Querying interface, as in trie_db but less generic.

Aliased Type§

struct Lookup<'a, 'cache, L, Q> {
    pub db: &'a dyn HashDBRef<<L as TrieLayout>::Hash, Vec<u8>>,
    pub query: Q,
    pub hash: <<L as TrieLayout>::Hash as Hasher>::Out,
    pub cache: Option<&'cache mut dyn TrieCache<<L as TrieLayout>::Codec>>,
    pub recorder: Option<&'cache mut dyn TrieRecorder<<<L as TrieLayout>::Hash as Hasher>::Out>>,
}

Fields§

§db: &'a dyn HashDBRef<<L as TrieLayout>::Hash, Vec<u8>>

database to query from.

§query: Q

Query object to record nodes and transform data.

§hash: <<L as TrieLayout>::Hash as Hasher>::Out

Hash to start at

§cache: Option<&'cache mut dyn TrieCache<<L as TrieLayout>::Codec>>

Optional cache that should be used to speed up the lookup.

§recorder: Option<&'cache mut dyn TrieRecorder<<<L as TrieLayout>::Hash as Hasher>::Out>>

Optional recorder that will be called to record all trie accesses.

Implementations

§

impl<'a, 'cache, L, Q> Lookup<'a, 'cache, L, Q>
where L: TrieLayout, Q: Query<<L as TrieLayout>::Hash>,

pub fn lookup_first_descendant( self, full_key: &[u8], nibble_key: NibbleSlice<'_>, ) -> Result<Option<MerkleValue<<<L as TrieLayout>::Hash as Hasher>::Out>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>

Look up the merkle value (hash) of the node that is the closest descendant for the provided key.

When the provided key leads to a node, then the merkle value (hash) of that node is returned. However, if the key does not lead to a node, then the merkle value of the closest descendant is returned. None if no such descendant exists.

pub fn look_up( self, full_key: &[u8], nibble_key: NibbleSlice<'_>, ) -> Result<Option<<Q as Query<<L as TrieLayout>::Hash>>::Item>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>

Look up the given nibble_key.

If the value is found, it will be passed to the given function to decode or copy.

The given full_key should be the full key to the data that is requested. This will be used when there is a cache to potentially speed up the lookup.

pub fn look_up_hash( self, full_key: &[u8], nibble_key: NibbleSlice<'_>, ) -> Result<Option<<<L as TrieLayout>::Hash as Hasher>::Out>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>

Look up the value hash for the given nibble_key.

The given full_key should be the full key to the data that is requested. This will be used when there is a cache to potentially speed up the lookup.