[][src]Struct geen::MerkleMountainRange

pub struct MerkleMountainRange<B> where
    B: Storage
{ /* 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.

Methods

impl<B> MerkleMountainRange<B> where
    B: Storage<Value = H256>, 
[src]

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

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

pub fn restore(&mut self, leaf_hashes: Vec<H256>) -> Result<(), GeneError>[src]

Clears the MMR and restores its state from a set of leaf hashes.

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

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

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

Returns true if the MMR contains no hashes

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

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

pub fn get_leaf_hash(
    &self,
    leaf_node_index: usize
) -> Result<Option<H256>, GeneError>
[src]

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

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

Returns the number of leaf nodes in the MMR.

pub fn get_leaf_hashes(
    &self,
    index: usize,
    count: usize
) -> Result<Vec<H256>, GeneError>
[src]

Returns a set of leaf hashes from the MMR.

pub fn get_merkle_root(&self) -> Result<H256, GeneError>[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: &H256) -> Result<usize, GeneError>[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<(), GeneError>[src]

Walks the nodes in the MMR and revalidates all parent hashes

pub fn find_leaf_node(&self, hash: &H256) -> Result<Option<usize>, GeneError>[src]

Search for a given hash in the leaf node array. 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. The index that is returned is the index of the leaf node, and not the MMR node index.

Trait Implementations

impl<B> From<MerkleMountainRange<B>> for MutableMmr<B> where
    B: Storage<Value = H256>, 
[src]

impl<B, B2> PartialEq<MerkleMountainRange<B2>> for MerkleMountainRange<B> where
    B: Storage<Value = H256>,
    B2: Storage<Value = H256>, 
[src]

impl<B: Debug> Debug for MerkleMountainRange<B> where
    B: Storage
[src]

impl<'_, B> TryFrom<&'_ MerkleMountainRange<B>> for PrunedHashSet where
    B: Storage<Value = H256>, 
[src]

type Error = GeneError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<B> Send for MerkleMountainRange<B> where
    B: Send

impl<B> Sync for MerkleMountainRange<B> where
    B: Sync

impl<B> Unpin for MerkleMountainRange<B> where
    B: Unpin

impl<B> UnwindSafe for MerkleMountainRange<B> where
    B: UnwindSafe

impl<B> RefUnwindSafe for MerkleMountainRange<B> where
    B: RefUnwindSafe

Blanket Implementations

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

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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

impl<T> FromCast<T> for T

impl<T, U> Cast<U> for T where
    U: FromCast<T>, 

impl<T> FromBits<T> for T

impl<T, U> IntoBits<U> for T where
    U: FromBits<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

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