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§
sourcefn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, TrieError>
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, TrieError>
Returns the value for key stored in the trie.
sourcefn contains(&self, key: &[u8]) -> Result<bool, TrieError>
fn contains(&self, key: &[u8]) -> Result<bool, TrieError>
Checks that the key is present in the trie
sourcefn insert(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>
fn insert(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>
Inserts value into trie and modifies it if it exists
sourcefn remove(&mut self, key: &[u8]) -> Result<bool, TrieError>
fn remove(&mut self, key: &[u8]) -> Result<bool, TrieError>
Removes any existing value for key from the trie.
sourcefn root(&mut self) -> Result<Vec<u8>, TrieError>
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.
sourcefn get_proof(&self, key: &[u8]) -> Result<Vec<Vec<u8>>, TrieError>
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.