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.
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 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);
let proof = map.get_multiproof(vec![h1, h3]);
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());
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 } ]
})
);
Provides access to the proof part of the view. Useful mainly for debug purposes.
Retrieves references to keys that the proof shows as missing from the map.
This method does not perform any integrity checks of the proof.
Consumes this proof producing a CheckedMapProof
structure.
Fails if the proof is malformed.
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());
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more
Serializes content of a transaction with the given serializer.
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static