From 2919259e2f0188999466b9042e6a5fcd9e2dc16c Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Sat, 17 Jul 2021 20:35:29 +0700 Subject: [PATCH 1/4] added method to get root of proof --- src/proofs/query/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/proofs/query/mod.rs b/src/proofs/query/mod.rs index fb66f8a7..84e5a1a5 100644 --- a/src/proofs/query/mod.rs +++ b/src/proofs/query/mod.rs @@ -355,6 +355,16 @@ pub fn verify(bytes: &[u8], expected_hash: Hash) -> Result { Ok(map_builder.build()) } +pub fn execute_proof(bytes: &[u8]) -> Result<(Hash,Map)> { + let ops = Decoder::new(bytes); + let mut map_builder = MapBuilder::new(); + + let root = execute(ops, true, |node| map_builder.insert(node))?; + + Ok((root.hash(), map_builder.build())) +} + + /// Verifies the encoded proof with the given query and expected hash. /// /// Every key in `keys` is checked to either have a key/value pair in the proof, From aaca175cf4ff1f6a6bc22d5dd60fc2e8d95c01a5 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Sat, 17 Jul 2021 20:42:19 +0700 Subject: [PATCH 2/4] added method to get root of proof --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index db965492..083752bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,3 +34,4 @@ pub use tree::{Batch, BatchEntry, Hash, Op, PanicSource, HASH_LENGTH}; pub use proofs::query::verify_query; pub use proofs::query::verify; +pub use proofs::query::execute_proof; From 7b93abd29b8ad1c1358a0743c21634ed822d8437 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Wed, 21 Jul 2021 12:36:17 +0700 Subject: [PATCH 3/4] expose map iterator --- src/proofs/query/map.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/proofs/query/map.rs b/src/proofs/query/map.rs index 5c82f008..9ec6af5a 100644 --- a/src/proofs/query/map.rs +++ b/src/proofs/query/map.rs @@ -4,6 +4,7 @@ use failure::{bail, ensure, format_err}; use std::collections::btree_map; use std::collections::BTreeMap; use std::ops::{Bound, RangeBounds}; +use std::collections::btree_map::Iter; /// `MapBuilder` allows a consumer to construct a `Map` by inserting the nodes /// contained in a proof, in key-order. @@ -77,6 +78,10 @@ impl Map { Ok(entry) } + pub fn all(&self) -> Iter<'_, K, V> { + self.entries.iter() + } + /// Returns an iterator over all (key, value) entries in the requested range /// of keys. If during iteration we encounter a gap in the data (e.g. the /// proof did not include all nodes within the range), the iterator will From 42c5bc96ffefc427f12ab598c993986063dfb9da Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Wed, 21 Jul 2021 12:46:08 +0700 Subject: [PATCH 4/4] expose map iterator --- src/proofs/query/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proofs/query/map.rs b/src/proofs/query/map.rs index 9ec6af5a..dc2f7a35 100644 --- a/src/proofs/query/map.rs +++ b/src/proofs/query/map.rs @@ -78,7 +78,7 @@ impl Map { Ok(entry) } - pub fn all(&self) -> Iter<'_, K, V> { + pub fn all(&self) -> Iter<'_, Vec, (bool, Vec)> { self.entries.iter() }