pub struct NamespaceMerkleTree<Db, M: MerkleHash, const NS_ID_SIZE: usize> { /* private fields */ }Expand description
A namespaced merkle tree, implemented as a wrapper around a simple merkle tree.
Implementations§
Source§impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>where
Db: PreimageDb<M::Output>,
M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>> + Default,
impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>where
Db: PreimageDb<M::Output>,
M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>> + Default,
Source§impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>where
Db: PreimageDb<M::Output>,
M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>>,
impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>where
Db: PreimageDb<M::Output>,
M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>>,
Sourcepub fn with_hasher(hasher: M) -> Self
pub fn with_hasher(hasher: M) -> Self
Creates a new nmt with the provided hasher
Sourcepub fn push_leaf(
&mut self,
raw_data: &[u8],
namespace: NamespaceId<NS_ID_SIZE>,
) -> Result<(), &'static str>
pub fn push_leaf( &mut self, raw_data: &[u8], namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), &'static str>
Adds a leaf to the namespaced merkle tree. Leaves must be pushed in namespace order.
Sourcepub fn root(&mut self) -> NamespacedHash<NS_ID_SIZE>
pub fn root(&mut self) -> NamespacedHash<NS_ID_SIZE>
Returns the root of the tree, computing it if necessary. Repeated calls return a cached root.
Sourcepub fn build_range_proof(&mut self, leaf_range: Range<usize>) -> Proof<M>
pub fn build_range_proof(&mut self, leaf_range: Range<usize>) -> Proof<M>
Creates a range proof providing the sibling hashes required to show that a set of values really does occur in the merkle tree at some half-open range of indices. Intermediate hashes are identified by an in-order traversal and are returned in that same order. Panics if the range to prove is larger than the tree’s leaf array.
Example: consider the following merkle tree with leaves [C, D, E, F]
root
/ \
A B
/ \ / \
C D E F
A range proof of build_range_proof(1..3) would return the vector [C, F], since those two hashes, together with the two leaves in the range, are sufficient to reconstruct the tree
Sourcepub fn get_range_with_proof(
&mut self,
leaf_range: Range<usize>,
) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)
pub fn get_range_with_proof( &mut self, leaf_range: Range<usize>, ) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)
Fetch a range of leaves from the tree, along with a proof of their inclusion.
Sourcepub fn get_index_with_proof(&mut self, idx: usize) -> (Vec<u8>, Proof<M>)
pub fn get_index_with_proof(&mut self, idx: usize) -> (Vec<u8>, Proof<M>)
Get the leaf at a given index in the tree, along with a proof of its inclusion.
Sourcepub fn get_namespace_with_proof(
&mut self,
namespace: NamespaceId<NS_ID_SIZE>,
) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)
pub fn get_namespace_with_proof( &mut self, namespace: NamespaceId<NS_ID_SIZE>, ) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)
Get an entire namespace from the tree, along with an inclusion proof for that range.
Sourcepub fn leaves(&self) -> &[LeafWithHash<M>]
pub fn leaves(&self) -> &[LeafWithHash<M>]
Return all the leaves from the tree.
Sourcepub fn get_namespace_proof(
&mut self,
namespace: NamespaceId<NS_ID_SIZE>,
) -> NamespaceProof<M, NS_ID_SIZE>
pub fn get_namespace_proof( &mut self, namespace: NamespaceId<NS_ID_SIZE>, ) -> NamespaceProof<M, NS_ID_SIZE>
Get a proof for the given namespace.