pub struct PartialMerkleTree { /* private fields */ }
Expand description
A partial Merkle tree with NodeIndex keys and 4-element RpoDigest leaf values. Partial Merkle Tree allows to create Merkle Tree by providing Merkle paths of different lengths.
The root of the tree is recomputed on each new leaf update.
Implementations§
source§impl PartialMerkleTree
impl PartialMerkleTree
sourcepub fn new() -> Self
pub fn new() -> Self
Returns a new empty PartialMerkleTree.
sourcepub fn with_paths<I>(paths: I) -> Result<Self, MerkleError>
pub fn with_paths<I>(paths: I) -> Result<Self, MerkleError>
Appends the provided paths iterator into the set.
Analogous to Self::add_path.
sourcepub fn with_leaves<R, I>(entries: R) -> Result<Self, MerkleError>where
R: IntoIterator<IntoIter = I>,
I: Iterator<Item = (NodeIndex, RpoDigest)> + ExactSizeIterator,
pub fn with_leaves<R, I>(entries: R) -> Result<Self, MerkleError>where
R: IntoIterator<IntoIter = I>,
I: Iterator<Item = (NodeIndex, RpoDigest)> + ExactSizeIterator,
Returns a new PartialMerkleTree instantiated with leaves map as specified by the provided entries.
§Errors
Returns an error if:
- If the depth is 0 or is greater than 64.
- The number of entries exceeds the maximum tree capacity, that is 2^{depth}.
- The provided entries contain an insufficient set of nodes.
sourcepub fn get_node(&self, index: NodeIndex) -> Result<RpoDigest, MerkleError>
pub fn get_node(&self, index: NodeIndex) -> Result<RpoDigest, MerkleError>
Returns a node at the specified NodeIndex.
§Errors
Returns an error if the specified NodeIndex is not contained in the nodes map.
sourcepub fn is_leaf(&self, index: NodeIndex) -> bool
pub fn is_leaf(&self, index: NodeIndex) -> bool
Returns true if provided index contains in the leaves set, false otherwise.
sourcepub fn to_paths(&self) -> Vec<(NodeIndex, ValuePath)>
pub fn to_paths(&self) -> Vec<(NodeIndex, ValuePath)>
Returns a vector of paths from every leaf to the root.
sourcepub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>
pub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>
Returns a Merkle path from the node at the specified index to the root.
The node itself is not included in the path.
§Errors
Returns an error if:
- the specified index has depth set to 0 or the depth is greater than the depth of this Merkle tree.
- the specified index is not contained in the nodes map.
sourcepub fn leaves(&self) -> impl Iterator<Item = (NodeIndex, RpoDigest)> + '_
pub fn leaves(&self) -> impl Iterator<Item = (NodeIndex, RpoDigest)> + '_
Returns an iterator over the leaves of this PartialMerkleTree.
sourcepub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
pub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
Returns an iterator over the inner nodes of this Merkle tree.
sourcepub fn add_path(
&mut self,
index_value: u64,
value: RpoDigest,
path: MerklePath,
) -> Result<(), MerkleError>
pub fn add_path( &mut self, index_value: u64, value: RpoDigest, path: MerklePath, ) -> Result<(), MerkleError>
Adds the nodes of the specified Merkle path to this PartialMerkleTree. The index_value
and value
parameters specify the leaf node at which the path starts.
§Errors
Returns an error if:
- The depth of the specified node_index is greater than 64 or smaller than 1.
- The specified path is not consistent with other paths in the set (i.e., resolves to a different root).
sourcepub fn update_leaf(
&mut self,
index: u64,
value: Word,
) -> Result<RpoDigest, MerkleError>
pub fn update_leaf( &mut self, index: u64, value: Word, ) -> Result<RpoDigest, MerkleError>
Updates value of the leaf at the specified index returning the old leaf value. By default the specified index is assumed to belong to the deepest layer. If the considered node does not belong to the tree, the first node on the way to the root will be changed.
By default the specified index is assumed to belong to the deepest layer. If the considered node does not belong to the tree, the first node on the way to the root will be changed.
This also recomputes all hashes between the leaf and the root, updating the root itself.
§Errors
Returns an error if:
- The specified index is greater than the maximum number of nodes on the deepest layer.
Trait Implementations§
source§impl Clone for PartialMerkleTree
impl Clone for PartialMerkleTree
source§fn clone(&self) -> PartialMerkleTree
fn clone(&self) -> PartialMerkleTree
1.6.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PartialMerkleTree
impl Debug for PartialMerkleTree
source§impl Default for PartialMerkleTree
impl Default for PartialMerkleTree
source§impl Deserializable for PartialMerkleTree
impl Deserializable for PartialMerkleTree
source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl<T: KvMap<RpoDigest, StoreNode>> From<&PartialMerkleTree> for MerkleStore<T>
impl<T: KvMap<RpoDigest, StoreNode>> From<&PartialMerkleTree> for MerkleStore<T>
source§fn from(value: &PartialMerkleTree) -> Self
fn from(value: &PartialMerkleTree) -> Self
source§impl PartialEq for PartialMerkleTree
impl PartialEq for PartialMerkleTree
source§impl Serializable for PartialMerkleTree
impl Serializable for PartialMerkleTree
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self
into bytes and writes these bytes into the target
.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Eq for PartialMerkleTree
impl StructuralPartialEq for PartialMerkleTree
Auto Trait Implementations§
impl Freeze for PartialMerkleTree
impl RefUnwindSafe for PartialMerkleTree
impl Send for PartialMerkleTree
impl Sync for PartialMerkleTree
impl Unpin for PartialMerkleTree
impl UnwindSafe for PartialMerkleTree
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)