SparseMerklePath: add SparseValuePath container

This commit is contained in:
Qyriad 2025-04-04 14:38:41 +02:00
parent c45d9682eb
commit cc6981de7f

View file

@ -254,6 +254,33 @@ impl DoubleEndedIterator for SparseMerkleIter {
}
}
// SPARSE MERKLE PATH CONTAINERS
// ================================================================================================
/// A container for a [crate::Word] value and its [SparseMerklePath] opening.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct SparseValuePath {
/// The node value opening for `path`.
pub value: RpoDigest,
/// The path from `value` to `root` (exclusive), using an efficient memory representation for
/// empty nodes.
pub path: SparseMerklePath,
}
impl SparseValuePath {
/// Convenience function to construct a [SparseValuePath].
///
/// `value` is the value `path` leads to, in the tree.
pub fn new(value: RpoDigest, path: SparseMerklePath) -> Self {
Self { value, path }
}
}
impl From<(SparseMerklePath, Word)> for SparseValuePath {
fn from((path, value): (SparseMerklePath, Word)) -> Self {
SparseValuePath::new(value.into(), path)
}
}
// SERIALIZATION
// ================================================================================================