pub struct Mmr { /* private fields */ }
Expand description
A fully materialized Merkle Mountain Range, with every tree in the forest and all their elements.
Since this is a full representation of the MMR, elements are never removed and the MMR will
grow roughly O(2n)
in number of leaf elements.
Implementations§
Source§impl Mmr
impl Mmr
Sourcepub fn open(&self, pos: usize) -> Result<MmrProof, MmrError>
pub fn open(&self, pos: usize) -> Result<MmrProof, MmrError>
Returns an MmrProof for the leaf at the specified position.
Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.
§Errors
Returns an error if the specified leaf position is out of bounds for this MMR.
Sourcepub fn open_at(&self, pos: usize, forest: Forest) -> Result<MmrProof, MmrError>
pub fn open_at(&self, pos: usize, forest: Forest) -> Result<MmrProof, MmrError>
Returns an MmrProof for the leaf at the specified position using the state of the MMR
at the specified forest
.
Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.
§Errors
Returns an error if:
- The specified leaf position is out of bounds for this MMR.
- The specified
forest
value is not valid for this MMR.
Sourcepub fn get(&self, pos: usize) -> Result<Word, MmrError>
pub fn get(&self, pos: usize) -> Result<Word, MmrError>
Returns the leaf value at position pos
.
Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.
Sourcepub fn peaks_at(&self, forest: Forest) -> Result<MmrPeaks, MmrError>
pub fn peaks_at(&self, forest: Forest) -> Result<MmrPeaks, MmrError>
Returns the peaks of the MMR at the state specified by forest
.
§Errors
Returns an error if the specified forest
value is not valid for this MMR.
Sourcepub fn get_delta(
&self,
from_forest: Forest,
to_forest: Forest,
) -> Result<MmrDelta, MmrError>
pub fn get_delta( &self, from_forest: Forest, to_forest: Forest, ) -> Result<MmrDelta, MmrError>
Compute the required update to original_forest
.
The result is a packed sequence of the authentication elements required to update the trees that have been merged together, followed by the new peaks of the Mmr.
Sourcepub fn inner_nodes(&self) -> MmrNodes<'_>
pub fn inner_nodes(&self) -> MmrNodes<'_>
An iterator over inner nodes in the MMR. The order of iteration is unspecified.
Trait Implementations§
Source§impl Deserializable for Mmr
impl Deserializable for Mmr
Source§fn read_from<R>(source: &mut R) -> Result<Mmr, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<Mmr, DeserializationError>where
R: ByteReader,
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> From<&Mmr> for MerkleStore<T>
impl<T> From<&Mmr> for MerkleStore<T>
Source§fn from(value: &Mmr) -> MerkleStore<T>
fn from(value: &Mmr) -> MerkleStore<T>
Source§impl Serializable for Mmr
impl Serializable for Mmr
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self
into bytes and writes these bytes into the target
.