use miden_crypto::{
hash::rpo::RpoDigest,
merkle::{MerkleError, SimpleSmt},
};
use crate::{
notes::{NoteId, NoteMetadata},
BATCH_OUTPUT_NOTES_TREE_DEPTH,
};
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct BatchNoteTree(SimpleSmt<BATCH_OUTPUT_NOTES_TREE_DEPTH>);
impl BatchNoteTree {
pub fn with_contiguous_leaves<'a>(
entries: impl IntoIterator<Item = (NoteId, &'a NoteMetadata)>,
) -> Result<Self, MerkleError> {
let interleaved = entries
.into_iter()
.flat_map(|(note_id, metadata)| [note_id.into(), metadata.into()]);
SimpleSmt::with_contiguous_leaves(interleaved).map(Self)
}
pub fn root(&self) -> RpoDigest {
self.0.root()
}
}