Struct tari_mmr::MerkleMountainRange[][src]

pub struct MerkleMountainRange<D, B> { /* fields omitted */ }

An implementation of a Merkle Mountain Range (MMR). The MMR is append-only and immutable. Only the hashes are stored in this data structure. The data itself can be stored anywhere as long as you can maintain a 1:1 mapping of the hash of that data to the leaf nodes in the MMR.

Implementations

impl<D, B> MerkleMountainRange<D, B> where
    D: Digest,
    B: ArrayLike<Value = Hash>, 
[src]

pub fn new(backend: B) -> MerkleMountainRange<D, B>[src]

Create a new Merkle mountain range using the given backend for storage

pub fn assign(
    &mut self,
    leaf_hashes: Vec<Hash>
) -> Result<(), MerkleMountainRangeError>
[src]

Clears the MMR and assigns its state from the list of leaf hashes given in leaf_hashes.

pub fn assign_iter<I: IntoIterator<Item = Hash>>(
    &mut self,
    hash_iter: I
) -> Result<(), MerkleMountainRangeError>
[src]

Clears the MMR and assigns its state from the provided iterator, which must produce a finite number of Hashes.

pub fn len(&self) -> Result<usize, MerkleMountainRangeError>[src]

Return the number of nodes in the full Merkle Mountain range, excluding bagged hashes

pub fn is_empty(&self) -> Result<bool, MerkleMountainRangeError>[src]

Returns true if the MMR contains no hashes

pub fn get_node_hash(
    &self,
    node_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
[src]

This function returns the hash of the node index provided indexed from 0

pub fn get_leaf_count(&self) -> Result<usize, MerkleMountainRangeError>[src]

Returns the number of leaf nodes in the MMR.

pub fn get_leaf_hash(
    &self,
    leaf_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
[src]

This function returns the hash of the leaf index provided, indexed from 0

pub fn get_leaf_hashes(
    &self,
    leaf_index: usize,
    count: usize
) -> Result<Vec<Hash>, MerkleMountainRangeError>
[src]

Returns a set of leaf hashes from the MMR.

pub fn get_merkle_root(&self) -> Result<Hash, MerkleMountainRangeError>[src]

This function will return the single merkle root of the MMR by simply hashing the peaks together.

Note that this differs from the bagging strategy used in other MMR implementations, and saves you a few hashes

pub fn push(&mut self, hash: Hash) -> Result<usize, MerkleMountainRangeError>[src]

Push a new element into the MMR. Computes new related peaks at the same time if applicable. Returns the new length of the merkle mountain range (the number of all nodes, not just leaf nodes).

pub fn validate(&self) -> Result<(), MerkleMountainRangeError>[src]

Walks the nodes in the MMR and revalidates all parent hashes

pub fn find_node_index(
    &self,
    hash: &[u8]
) -> Result<Option<usize>, MerkleMountainRangeError>
[src]

Search for the node index of the given hash in the MMR. This is a very slow function, being O(n). In general, it's better to cache the index of the hash when storing it rather than using this function, but it's here for completeness.

pub fn find_leaf_index(
    &self,
    hash: &[u8]
) -> Result<Option<u32>, MerkleMountainRangeError>
[src]

Search for the leaf index of the given hash in the leaf nodes of the MMR.

pub fn clear(&mut self) -> Result<(), MerkleMountainRangeError>[src]

pub fn get_pruned_hash_set(
    &self
) -> Result<PrunedHashSet, MerkleMountainRangeError>
[src]

Trait Implementations

impl<D: Debug, B: Debug> Debug for MerkleMountainRange<D, B>[src]

impl<D, B> From<MerkleMountainRange<D, B>> for MutableMmr<D, B> where
    D: Digest,
    B: ArrayLike<Value = Hash>, 
[src]

impl<D, B, B2> PartialEq<MerkleMountainRange<D, B2>> for MerkleMountainRange<D, B> where
    D: Digest,
    B: ArrayLike<Value = Hash>,
    B2: ArrayLike<Value = Hash>, 
[src]

impl<D, B> TryFrom<&'_ MerkleMountainRange<D, B>> for PrunedHashSet where
    D: Digest,
    B: ArrayLike<Value = Hash>, 
[src]

type Error = MerkleMountainRangeError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<D, B> RefUnwindSafe for MerkleMountainRange<D, B> where
    B: RefUnwindSafe,
    D: RefUnwindSafe
[src]

impl<D, B> Send for MerkleMountainRange<D, B> where
    B: Send,
    D: Send
[src]

impl<D, B> Sync for MerkleMountainRange<D, B> where
    B: Sync,
    D: Sync
[src]

impl<D, B> Unpin for MerkleMountainRange<D, B> where
    B: Unpin,
    D: Unpin
[src]

impl<D, B> UnwindSafe for MerkleMountainRange<D, B> where
    B: UnwindSafe,
    D: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,