pub struct ProofMapIndex<T, K, V> { /* fields omitted */ }
A Merkelized version of a map that provides proofs of existence or non-existence for the map
keys.
ProofMapIndex
implements a Merkle Patricia tree, storing values as leaves.
ProofMapIndex
requires that keys implement the ProofMapKey
trait and
values implement the StorageValue
trait.
The size of the proof map keys must be exactly 32 bytes and the keys must have a uniform
distribution. Usually, Hash
and PublicKey
are used as types of proof map keys.
Creates a new index representation based on the name and storage view.
Storage view can be specified as &Snapshot
or &mut Fork
. In the first case, only
immutable methods are available. In the second case, both immutable and mutable methods are
available.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
let mut fork = db.fork();
let mut mut_index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &mut fork);
Creates a new index representation based on the name, common prefix of its keys
and storage view.
Storage view can be specified as &Snapshot
or &mut Fork
. In the first case, only
immutable methods are available. In the second case, both immutable and mutable methods are
available.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let index_id = vec![01];
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new_in_family(
name,
&index_id,
&snapshot,
);
let mut fork = db.fork();
let mut mut_index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new_in_family(
name,
&index_id,
&mut fork,
);
Returns the root hash of the proof map or default hash value if it is empty.
The default hash consists solely of zeroes.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let default_hash = index.merkle_root();
assert_eq!(Hash::default(), default_hash);
index.put(&default_hash, 100);
let hash = index.merkle_root();
assert_ne!(hash, default_hash);
Returns a value corresponding to the key.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let hash = Hash::default();
assert_eq!(None, index.get(&hash));
index.put(&hash, 2);
assert_eq!(Some(2), index.get(&hash));
Returns true
if the map contains a value for the specified key.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let hash = Hash::default();
assert!(!index.contains(&hash));
index.put(&hash, 2);
assert!(index.contains(&hash));
Returns the proof of existence or non-existence for the specified key.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new("index", &snapshot);
let proof = index.get_proof(Hash::default());
Returns the combined proof of existence or non-existence for the multiple specified keys.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
let db = MemoryDB::new();
let snapshot = db.snapshot();
let index: ProofMapIndex<_, [u8; 32], u8> = ProofMapIndex::new("index", &snapshot);
let proof = index.get_multiproof(vec![[0; 32], [1; 32]]);
Returns an iterator over the entries of the map in ascending order. The iterator element
type is (K::Output, V)
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
for val in index.iter() {
println!("{:?}", val);
}
Returns an iterator over the keys of the map in ascending order. The iterator element
type is K::Output
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
for key in index.keys() {
println!("{:?}", key);
}
Returns an iterator over the values of the map in ascending order of keys. The iterator
element type is V
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
for val in index.values() {
println!("{}", val);
}
Returns an iterator over the entries of the map in ascending order starting from the
specified key. The iterator element type is (K::Output, V)
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
let hash = Hash::default();
for val in index.iter_from(&hash) {
println!("{:?}", val);
}
Returns an iterator over the keys of the map in ascending order starting from the
specified key. The iterator element type is K::Output
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
let hash = Hash::default();
for key in index.keys_from(&hash) {
println!("{:?}", key);
}
Returns an iterator over the values of the map in ascending order of keys starting from the
specified key. The iterator element type is V
.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);
let hash = Hash::default();
for val in index.values_from(&hash) {
println!("{}", val);
}
pub fn put(&mut self, key: &K, value: V) | [src] |
Inserts the key-value pair into the proof map.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));
Removes a key from the proof map.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));
index.remove(&hash);
assert!(!index.contains(&hash));
Clears the proof map, removing all entries.
Currently, this method is not optimized to delete a large set of data. During the execution of
this method, the amount of allocated memory is linearly dependent on the number of elements
in the index.
use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ProofMapIndex::new(name, &mut fork);
let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));
index.clear();
assert!(!index.contains(&hash));
Formats the value using the given formatter. Read more
type Error = !
🔬 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
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.
🔬 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