mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-11 08:31:30 +01:00
feat: add support for MMR to the MerkleStore
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use super::mmr::{Mmr, MmrPeaks};
|
||||
use super::{
|
||||
BTreeMap, BTreeSet, EmptySubtreeRoots, MerkleError, MerklePath, MerklePathSet, MerkleTree,
|
||||
NodeIndex, RootPath, Rpo256, RpoDigest, SimpleSmt, ValuePath, Vec, Word,
|
||||
@@ -151,6 +152,15 @@ impl MerkleStore {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Appends the provided [Mmr] represented by its `leaves` to the set.
|
||||
pub fn with_mmr<I>(mut self, leaves: I) -> Result<Self, MerkleError>
|
||||
where
|
||||
I: IntoIterator<Item = Word>,
|
||||
{
|
||||
self.add_mmr(leaves)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
// PUBLIC ACCESSORS
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -375,6 +385,25 @@ impl MerkleStore {
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
/// Appends the provided [Mmr] into the store.
|
||||
pub fn add_mmr<I>(&mut self, leaves: I) -> Result<MmrPeaks, MerkleError>
|
||||
where
|
||||
I: IntoIterator<Item = Word>,
|
||||
{
|
||||
let mmr = Mmr::from(leaves);
|
||||
for node in mmr.inner_nodes() {
|
||||
self.nodes.insert(
|
||||
node.value.into(),
|
||||
Node {
|
||||
left: node.left.into(),
|
||||
right: node.right.into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Ok(mmr.accumulator())
|
||||
}
|
||||
|
||||
/// Sets a node to `value`.
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
Reference in New Issue
Block a user