[−][src]Struct exonum_merkledb::proof_map_index::MapProof
View of a ProofMapIndex
, i.e., a subset of its elements coupled with a proof,
which jointly allow restoring the merkle_root()
of the index. Apart from the
existing elements, MapProof
can assert absence of certain keys from the underlying
index.
Workflow
You can create MapProof
s with get_proof()
and get_multiproof()
methods of
ProofMapIndex
. Proofs can be verified on the server side with the help of
check()
. Prior to the check
conversion, you may use *unchecked
methods
to obtain information about the proof.
let fork = { let db = TemporaryDB::new(); db.fork() }; let mut map = ProofMapIndex::new("index", &fork); let (h1, h2, h3) = (hash(&[1]), hash(&[2]), hash(&[3])); map.put(&h1, 100u32); map.put(&h2, 200u32); // Get the proof from the index let proof = map.get_multiproof(vec![h1, h3]); // Check the proof consistency let checked_proof = proof.check().unwrap(); assert_eq!(checked_proof.entries().collect::<Vec<_>>(), vec![(&h1, &100u32)]); assert_eq!(checked_proof.missing_keys().collect::<Vec<_>>(), vec![&h3]); assert_eq!(checked_proof.root_hash(), map.object_hash());
JSON serialization
MapProof
is serialized to JSON as an object with 2 array fields:
proof
is an array of{ "path": ProofPath, "hash": Hash }
objects. The entries are sorted by increasingProofPath
, but client implementors should not rely on this if security is a concern.entries
is an array with 2 kinds of objects:{ "missing": K }
for keys missing from the underlying index, and{ "key": K, "value": V }
for key-value pairs, existence of which is asserted by the proof.
let fork = { let db = TemporaryDB::new(); db.fork() }; let mut map = ProofMapIndex::new("index", &fork); let (h1, h2) = (HashTag::hash_leaf(&[1]), HashTag::hash_leaf(&[2])); map.put(&h1, 100u32); map.put(&h2, 200u32); let proof = map.get_proof(h2); assert_eq!( serde_json::to_value(&proof).unwrap(), json!({ "proof": [ { "path": ProofPath::new(&h1), "hash": HashTag::hash_leaf(&100u32.to_bytes()) } ], "entries": [ { "key": h2, "value": 200 } ] }) );
Methods
impl<K, V> MapProof<K, V>
[src]
pub fn proof_unchecked(&self) -> Vec<(ProofPath, Hash)>
[src]
Provides access to the proof part of the view. Useful mainly for debug purposes.
pub fn missing_keys_unchecked(&self) -> impl Iterator<Item = &K>
[src]
Retrieves references to keys that the proof shows as missing from the map. This method does not perform any integrity checks of the proof.
pub fn all_entries_unchecked(&self) -> impl Iterator<Item = (&K, Option<&V>)>
[src]
Retrieves references to existing and non-existing entries in the proof.
Existing entries have Some
value, non-existing have None
.
This method does not perform any integrity checks of the proof.
impl<K, V> MapProof<K, V> where
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
[src]
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
pub fn check(self) -> Result<CheckedMapProof<K, V>, MapProofError>
[src]
Consumes this proof producing a CheckedMapProof
structure.
Fails if the proof is malformed.
Examples
let fork = { let db = TemporaryDB::new(); db.fork() }; let mut map = ProofMapIndex::new("index", &fork); let (h1, h2) = (hash(&[1]), hash(&[2])); map.put(&h1, 100u32); map.put(&h2, 200u32); let proof = map.get_proof(h2); let checked_proof = proof.check().unwrap(); assert_eq!(checked_proof.entries().collect::<Vec<_>>(), vec![(&h2, &200u32)]); assert_eq!(checked_proof.root_hash(), map.object_hash());
Trait Implementations
impl<K: Clone, V: Clone> Clone for MapProof<K, V>
[src]
fn clone(&self) -> MapProof<K, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Debug, V: Debug> Debug for MapProof<K, V>
[src]
impl<K, V> Serialize for MapProof<K, V> where
K: Serialize,
V: Serialize,
[src]
K: Serialize,
V: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, K, V> Deserialize<'de> for MapProof<K, V> where
K: Deserialize<'de>,
V: Deserialize<'de>,
[src]
K: Deserialize<'de>,
V: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<K, V> Sync for MapProof<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Send for MapProof<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Unpin for MapProof<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> RefUnwindSafe for MapProof<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> UnwindSafe for MapProof<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,