[][src]Struct exonum::storage::proof_map_index::MapProof

pub struct MapProof<K, V> { /* fields omitted */ }

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 MapProofs 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 mut fork = { let db = MemoryDB::new(); db.fork() };
let mut map = ProofMapIndex::new("index", &mut 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(), vec![(&h1, &100u32)]);
assert_eq!(checked_proof.missing_keys(), vec![&h3]);
assert_eq!(checked_proof.merkle_root(), map.merkle_root());

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 increasing ProofPath, 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 mut fork = { let db = MemoryDB::new(); db.fork() };
let mut map = ProofMapIndex::new("index", &mut fork);
let (h1, h2) = (hash(&[1]), hash(&[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": 100u32.hash() } ],
        "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) -> Vec<&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.

impl<K, V> MapProof<K, V> where
    K: ProofMapKey,
    V: StorageValue
[src]

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 mut fork = { let db = MemoryDB::new(); db.fork() };
let mut map = ProofMapIndex::new("index", &mut 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(), vec![(&h2, &200u32)]);
assert_eq!(checked_proof.merkle_root(), map.merkle_root());

Trait Implementations

impl<K: Clone, V: Clone> Clone for 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<'de, K, V> Deserialize<'de> for MapProof<K, V> where
    K: Deserialize<'de>,
    V: Deserialize<'de>, 
[src]

impl<K, V> Serialize for MapProof<K, V> where
    K: Serialize,
    V: Serialize
[src]

Auto Trait Implementations

impl<K, V> Send for MapProof<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for MapProof<K, V> where
    K: Sync,
    V: Sync

Blanket Implementations

impl<T> SerializeContent for T where
    T: Serialize
[src]

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T> Erased for T

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Same for T

type Output = T

Should always be Self