Struct tari_mmr::MerkleMountainRange [−][src]
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]
D: Digest,
B: ArrayLike<Value = Hash>,
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]
&mut self,
leaf_hashes: Vec<Hash>
) -> Result<(), MerkleMountainRangeError>
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]
&mut self,
hash_iter: I
) -> Result<(), MerkleMountainRangeError>
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]
&self,
node_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
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]
&self,
leaf_index: usize
) -> Result<Option<Hash>, MerkleMountainRangeError>
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]
&self,
leaf_index: usize,
count: usize
) -> Result<Vec<Hash>, MerkleMountainRangeError>
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]
&self,
hash: &[u8]
) -> Result<Option<usize>, MerkleMountainRangeError>
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]
&self,
hash: &[u8]
) -> Result<Option<u32>, MerkleMountainRangeError>
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]
&self
) -> Result<PrunedHashSet, MerkleMountainRangeError>
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]
D: Digest,
B: ArrayLike<Value = Hash>,
fn from(mmr: MerkleMountainRange<D, B>) -> Self
[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]
D: Digest,
B: ArrayLike<Value = Hash>,
B2: ArrayLike<Value = Hash>,
fn eq(&self, other: &MerkleMountainRange<D, B2>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<D, B> TryFrom<&'_ MerkleMountainRange<D, B>> for PrunedHashSet where
D: Digest,
B: ArrayLike<Value = Hash>,
[src]
D: Digest,
B: ArrayLike<Value = Hash>,
type Error = MerkleMountainRangeError
The type returned in the event of a conversion error.
fn try_from(base_mmr: &MerkleMountainRange<D, B>) -> Result<Self, Self::Error>
[src]
Auto Trait Implementations
impl<D, B> RefUnwindSafe for MerkleMountainRange<D, B> where
B: RefUnwindSafe,
D: RefUnwindSafe,
[src]
B: RefUnwindSafe,
D: RefUnwindSafe,
impl<D, B> Send for MerkleMountainRange<D, B> where
B: Send,
D: Send,
[src]
B: Send,
D: Send,
impl<D, B> Sync for MerkleMountainRange<D, B> where
B: Sync,
D: Sync,
[src]
B: Sync,
D: Sync,
impl<D, B> Unpin for MerkleMountainRange<D, B> where
B: Unpin,
D: Unpin,
[src]
B: Unpin,
D: Unpin,
impl<D, B> UnwindSafe for MerkleMountainRange<D, B> where
B: UnwindSafe,
D: UnwindSafe,
[src]
B: UnwindSafe,
D: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
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]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,