Trait cita_trie::Trie

source ·
pub trait Trie<D: DB, H: Hasher> {
    // Required methods
    fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, TrieError>;
    fn contains(&self, key: &[u8]) -> Result<bool, TrieError>;
    fn insert(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>;
    fn remove(&mut self, key: &[u8]) -> Result<bool, TrieError>;
    fn root(&mut self) -> Result<Vec<u8>, TrieError>;
    fn get_proof(&self, key: &[u8]) -> Result<Vec<Vec<u8>>, TrieError>;
    fn verify_proof(
        &self,
        root_hash: &[u8],
        key: &[u8],
        proof: Vec<Vec<u8>>
    ) -> Result<Option<Vec<u8>>, TrieError>;
}

Required Methods§

source

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, TrieError>

Returns the value for key stored in the trie.

source

fn contains(&self, key: &[u8]) -> Result<bool, TrieError>

Checks that the key is present in the trie

source

fn insert(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>

Inserts value into trie and modifies it if it exists

source

fn remove(&mut self, key: &[u8]) -> Result<bool, TrieError>

Removes any existing value for key from the trie.

source

fn root(&mut self) -> Result<Vec<u8>, TrieError>

Saves all the nodes in the db, clears the cache data, recalculates the root. Returns the root hash of the trie.

source

fn get_proof(&self, key: &[u8]) -> Result<Vec<Vec<u8>>, TrieError>

Prove constructs a merkle proof for key. The result contains all encoded nodes on the path to the value at key. The value itself is also included in the last node and can be retrieved by verifying the proof.

If the trie does not contain a value for key, the returned proof contains all nodes of the longest existing prefix of the key (at least the root node), ending with the node that proves the absence of the key.

source

fn verify_proof( &self, root_hash: &[u8], key: &[u8], proof: Vec<Vec<u8>> ) -> Result<Option<Vec<u8>>, TrieError>

return value if key exists, None if key not exist, Error if proof is wrong

Implementors§

source§

impl<D, H> Trie<D, H> for PatriciaTrie<D, H>where D: DB, H: Hasher,