2020-09-22 14:53:52 +02:00
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of OpenEthereum.
2018-07-02 18:50:05 +02:00
2020-09-22 14:53:52 +02:00
// OpenEthereum is free software: you can redistribute it and/or modify
2018-07-02 18:50:05 +02:00
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2020-09-22 14:53:52 +02:00
// OpenEthereum is distributed in the hope that it will be useful,
2018-07-02 18:50:05 +02:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
2020-09-22 14:53:52 +02:00
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
2018-07-02 18:50:05 +02:00
//! Façade crate for `patricia_trie` for Ethereum specific impls
extern crate elastic_array ;
extern crate ethereum_types ;
2019-02-20 19:09:34 +01:00
extern crate hash_db ;
2018-07-02 18:50:05 +02:00
extern crate keccak_hasher ;
Delete crates from parity-ethereum and fetch them from parity-common instead (#9083)
Use crates from parity-common: hashdb, keccak-hash, kvdb, kvdb-memorydb, kvdb-rocksdb, memorydb, parity-bytes, parity-crypto, path, patricia_trie, plain_hasher, rlp, target, test-support, trie-standardmap, triehash
2018-07-10 14:59:19 +02:00
extern crate parity_bytes ;
2018-07-02 18:50:05 +02:00
extern crate rlp ;
2019-02-20 19:09:34 +01:00
pub extern crate trie_db as trie ; // `pub` because we need to import this crate for the tests in `patricia_trie` and there were issues: https://gist.github.com/dvdplm/869251ee557a1b4bd53adc7c971979aa
2018-07-02 18:50:05 +02:00
mod rlp_node_codec ;
pub use rlp_node_codec ::RlpNodeCodec ;
use ethereum_types ::H256 ;
use keccak_hasher ::KeccakHasher ;
use rlp ::DecoderError ;
/// Convenience type alias to instantiate a Keccak-flavoured `RlpNodeCodec`
pub type RlpCodec = RlpNodeCodec < KeccakHasher > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieDB`
2018-09-04 20:13:51 +02:00
///
/// 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
/// ```
2019-02-20 19:09:34 +01:00
/// extern crate trie_db as trie;
2018-09-04 20:13:51 +02:00
/// extern crate patricia_trie_ethereum as ethtrie;
2019-02-20 19:09:34 +01:00
/// extern crate hash_db;
2018-09-04 20:13:51 +02:00
/// extern crate keccak_hasher;
2019-02-20 19:09:34 +01:00
/// extern crate memory_db;
2018-09-04 20:13:51 +02:00
/// extern crate ethereum_types;
2018-10-09 22:07:25 +02:00
/// extern crate elastic_array;
2019-02-20 19:09:34 +01:00
/// extern crate journaldb;
2018-09-04 20:13:51 +02:00
///
/// use trie::*;
2019-02-20 19:09:34 +01:00
/// use hash_db::*;
2018-09-04 20:13:51 +02:00
/// use keccak_hasher::KeccakHasher;
2019-02-20 19:09:34 +01:00
/// use memory_db::*;
2018-09-04 20:13:51 +02:00
/// use ethereum_types::H256;
/// use ethtrie::{TrieDB, TrieDBMut};
2018-10-09 22:07:25 +02:00
/// use elastic_array::ElasticArray128;
2018-09-04 20:13:51 +02:00
///
2018-10-09 22:07:25 +02:00
/// type DBValue = ElasticArray128<u8>;
2018-09-04 20:13:51 +02:00
///
/// fn main() {
2019-02-20 19:09:34 +01:00
/// let mut memdb = journaldb::new_memory_db();
2018-09-04 20:13:51 +02:00
/// let mut root = H256::new();
/// 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"));
/// }
/// ```
2018-07-02 18:50:05 +02:00
pub type TrieDB < ' db > = trie ::TrieDB < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `SecTrieDB`
pub type SecTrieDB < ' db > = trie ::SecTrieDB < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `FatDB`
pub type FatDB < ' db > = trie ::FatDB < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieDBMut`
2018-09-04 20:13:51 +02:00
///
/// 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
/// ```
2019-02-20 19:09:34 +01:00
/// extern crate trie_db as trie;
2018-09-04 20:13:51 +02:00
/// extern crate patricia_trie_ethereum as ethtrie;
2019-02-20 19:09:34 +01:00
/// extern crate hash_db;
2018-09-04 20:13:51 +02:00
/// extern crate keccak_hash;
/// extern crate keccak_hasher;
2019-02-20 19:09:34 +01:00
/// extern crate memory_db;
2018-09-04 20:13:51 +02:00
/// extern crate ethereum_types;
2018-10-09 22:07:25 +02:00
/// extern crate elastic_array;
2019-02-20 19:09:34 +01:00
/// extern crate journaldb;
2018-09-04 20:13:51 +02:00
///
/// use keccak_hash::KECCAK_NULL_RLP;
/// use ethtrie::{TrieDBMut, trie::TrieMut};
/// use keccak_hasher::KeccakHasher;
2019-02-20 19:09:34 +01:00
/// use memory_db::*;
2018-09-04 20:13:51 +02:00
/// use ethereum_types::H256;
2018-10-09 22:07:25 +02:00
/// use elastic_array::ElasticArray128;
///
/// type DBValue = ElasticArray128<u8>;
2018-09-04 20:13:51 +02:00
///
/// fn main() {
2019-02-20 19:09:34 +01:00
/// let mut memdb = journaldb::new_memory_db();
2018-09-04 20:13:51 +02:00
/// let mut root = H256::new();
/// 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());
/// }
/// ```
2018-07-02 18:50:05 +02:00
pub type TrieDBMut < ' db > = trie ::TrieDBMut < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `SecTrieDBMut`
pub type SecTrieDBMut < ' db > = trie ::SecTrieDBMut < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `FatDBMut`
pub type FatDBMut < ' db > = trie ::FatDBMut < ' db , KeccakHasher , RlpCodec > ;
/// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieFactory`
pub type TrieFactory = trie ::TrieFactory < KeccakHasher , RlpCodec > ;
/// Convenience type alias for Keccak/Rlp flavoured trie errors
pub type TrieError = trie ::TrieError < H256 , DecoderError > ;
/// Convenience type alias for Keccak/Rlp flavoured trie results
pub type Result < T > = trie ::Result < T , H256 , DecoderError > ;