Struct arber::MerkleMountainRange[][src]

pub struct MerkleMountainRange<T, S> where
    T: Hashable + Clone,
    S: Store<T>, 
{ pub size: u64, // some fields omitted }
Expand description

Merkle-Mountain-Range (MMR) implementation.

All tree positions start at '1'. MMR positions are depth-frist, post-order tree traversal node positions and should not be seen as array indices.

The MMR Store, however, is a flat list representation of the MMR, i.e. an array of nodes. Hence, Store elements are accessed using a '0' based index.

Again, positions are '1' based tree node positions, indices are '0' based Store locations.

Fields

size: u64

Total number of MMR nodes, i.e. MMR size

Implementations

impl<'a, T, S> MerkleMountainRange<T, S> where
    T: Hashable + Clone,
    S: Store<T>, 
[src]

pub fn new(store: S) -> Self[src]

pub fn append(&mut self, elem: &T) -> Result<u64, Error>[src]

Append elem to the MMR. Return new MMR size.

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

Validate the MMR by re-calculating the hash of all inner, i.e. parent nodes. Retrun true, if the MMR is valid or an error.

pub fn proof(&self, pos: u64) -> Result<MerkleProof, Error>[src]

Return a MMR membership proof for a leaf node at position pos.

pub fn hash(&self, pos: u64) -> Result<Hash, Error>[src]

Return node hash at pos.

Note that in case of an error, Error::Store is returned and the error message is referring to pss - 1, i.e. an index.

pub fn peaks(&self) -> Vec<Hash>[src]

Return MMR peak hashes as a vec

Peaks are listed left to right, starting with the leftmost peak. The leftmost peak is also always the ‘highest’ peak.

pub fn root(&self) -> Result<Hash, Error>[src]

Return the root hash of the MMR.

Find all the current peaks and bag them together into a single peak hash.

Auto Trait Implementations

impl<T, S> RefUnwindSafe for MerkleMountainRange<T, S> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, S> Send for MerkleMountainRange<T, S> where
    S: Send,
    T: Send

impl<T, S> Sync for MerkleMountainRange<T, S> where
    S: Sync,
    T: Sync

impl<T, S> Unpin for MerkleMountainRange<T, S> where
    S: Unpin,
    T: Unpin

impl<T, S> UnwindSafe for MerkleMountainRange<T, S> where
    S: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.