Type Definition patricia_trie_ethereum::TrieDBMut
source · [−]pub type TrieDBMut<'db> = TrieDBMut<'db, KeccakHasher, RlpCodec>;
Expand description
Convenience type alias to instantiate a Keccak/Rlp-flavoured TrieDBMut
Use it as a TrieMut
trait object. You can use db()
to get the backing database object.
Note that changes are not committed to the database until commit
is called.
Querying the root or dropping the trie will commit automatically.
Example
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate hash_db;
extern crate keccak_hash;
extern crate keccak_hasher;
extern crate memory_db;
extern crate ethereum_types;
extern crate elastic_array;
extern crate journaldb;
use keccak_hash::KECCAK_NULL_RLP;
use ethtrie::{TrieDBMut, trie::TrieMut};
use keccak_hasher::KeccakHasher;
use memory_db::*;
use ethereum_types::H256;
use elastic_array::ElasticArray128;
type DBValue = ElasticArray128<u8>;
fn main() {
let mut memdb = journaldb::new_memory_db();
let mut root = H256::default();
let mut t = TrieDBMut::new(&mut memdb, &mut root);
assert!(t.is_empty());
assert_eq!(*t.root(), KECCAK_NULL_RLP);
t.insert(b"foo", b"bar").unwrap();
assert!(t.contains(b"foo").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar"));
t.remove(b"foo").unwrap();
assert!(!t.contains(b"foo").unwrap());
}