From 33ef78f8f5b2194206c1c26ac8cef941294a4832 Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Thu, 3 Aug 2023 14:58:51 +0200 Subject: [PATCH] tsmt: add basic traits and into/from parts methods --- src/merkle/tiered_smt/proof.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/merkle/tiered_smt/proof.rs b/src/merkle/tiered_smt/proof.rs index 3965faa..0e7fcbf 100644 --- a/src/merkle/tiered_smt/proof.rs +++ b/src/merkle/tiered_smt/proof.rs @@ -21,6 +21,7 @@ pub const EMPTY_VALUE: Word = super::TieredSmt::EMPTY_VALUE; /// The proof consists of a Merkle path and one or more key-value entries which describe the node /// located at the base of the path. If the node at the base of the path resolves to [ZERO; 4], /// the entries will contain a single item with value set to [ZERO; 4]. +#[derive(PartialEq, Eq, Debug)] pub struct TieredSmtProof { path: MerklePath, entries: Vec<(RpoDigest, Word)>, @@ -38,7 +39,11 @@ impl TieredSmtProof { /// - Entries contains more than 1 item, but the length of the path is not 64. /// - Entries contains more than 1 item, and one of the items has value set to [ZERO; 4]. /// - Entries contains multiple items with keys which don't share the same 64-bit prefix. - pub fn new(path: MerklePath, entries: Vec<(RpoDigest, Word)>) -> Self { + pub fn new(path: MerklePath, entries: I) -> Self + where + I: IntoIterator, + { + let entries: Vec<(RpoDigest, Word)> = entries.into_iter().collect(); assert!(path.depth() <= MAX_DEPTH); assert!(!entries.is_empty()); if entries.len() > 1 { @@ -110,6 +115,11 @@ impl TieredSmtProof { .expect("failed to compute Merkle path root") } + /// Consume the proof and returns its parts. + pub fn into_parts(self) -> (MerklePath, Vec<(RpoDigest, Word)>) { + (self.path, self.entries) + } + // HELPER METHODS // --------------------------------------------------------------------------------------------