Type Definition patricia_trie_ethereum::TrieDB
source · [−]pub type TrieDB<'db> = TrieDB<'db, KeccakHasher, RlpCodec>;
Expand description
Convenience type alias to instantiate a Keccak/Rlp-flavoured TrieDB
Use it as a Trie
trait object. You can use db()
to get the backing database object.
Use get
and contains
to query values associated with keys in the trie.
Example
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate hash_db;
extern crate keccak_hasher;
extern crate memory_db;
extern crate ethereum_types;
extern crate elastic_array;
extern crate journaldb;
use trie::*;
use hash_db::*;
use keccak_hasher::KeccakHasher;
use memory_db::*;
use ethereum_types::H256;
use ethtrie::{TrieDB, TrieDBMut};
use elastic_array::ElasticArray128;
type DBValue = ElasticArray128<u8>;
fn main() {
let mut memdb = journaldb::new_memory_db();
let mut root = H256::default();
TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
let t = TrieDB::new(&memdb, &root).unwrap();
assert!(t.contains(b"foo").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar"));
}