Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions src/proofs/query/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -77,6 +78,10 @@ impl Map {
Ok(entry)
}

pub fn all(&self) -> Iter<'_, Vec<u8>, (bool, Vec<u8>)> {
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
Expand Down
10 changes: 10 additions & 0 deletions src/proofs/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ pub fn verify(bytes: &[u8], expected_hash: Hash) -> Result<Map> {
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,
Expand Down