SparseMerklePath: add SparseValuePath container
This commit is contained in:
parent
f1eb9a8f04
commit
22b33ed8b6
1 changed files with 27 additions and 0 deletions
|
@ -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
|
// SERIALIZATION
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue