Remove deps to hashdb, memdb, patricia-trie, keccak-hash.

This commit is contained in:
cheme 2019-02-07 10:30:26 +01:00
parent 97e1b5f533
commit 2c99d1edb9
No known key found for this signature in database
GPG Key ID: 893E86691A48857E
8 changed files with 39 additions and 29 deletions

View File

@ -1,16 +1,13 @@
[workspace] [workspace]
members = [ members = [
"fixed-hash", "fixed-hash",
"hashdb",
"keccak-hash", "keccak-hash",
"kvdb", "kvdb",
"kvdb-memorydb", "kvdb-memorydb",
"kvdb-rocksdb", "kvdb-rocksdb",
"memorydb",
"parity-bytes", "parity-bytes",
"parity-crypto", "parity-crypto",
"parity-path", "parity-path",
"patricia_trie",
"plain_hasher", "plain_hasher",
"rlp", "rlp",
"transaction-pool", "transaction-pool",

View File

@ -1,4 +1,7 @@
# HashDB # HashDB
`HashDB` defines a common interface for databases of byte-slices keyed to their hash. It is generic over hash type through the `Hasher` trait. `HashDB` defines a common interface for databases of byte-slices keyed to their hash. It is generic over hash type through the `Hasher` trait.
The `Hasher` trait can be used in a `no_std` context. The `Hasher` trait can be used in a `no_std` context.
**This crate is deprecated in favor of ['hash-db'](https://crates.io/crates/hash-db)**

View File

@ -1 +1,3 @@
MemoryDB is a reference counted memory-based [`HashDB`](https://github.com/paritytech/parity-common/tree/master/hashdb) implementation backed by a `HashMap`. MemoryDB is a reference counted memory-based [`HashDB`](https://github.com/paritytech/parity-common/tree/master/hashdb) implementation backed by a `HashMap`.
**This crate is deprecated in favor of ['memory-db'](https://crates.io/crates/hash-db)**

View File

@ -2,7 +2,7 @@
name = "patricia-trie" name = "patricia-trie"
version = "0.3.0" version = "0.3.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Merkle-Patricia Trie generic over key hasher and node encoding" description = "Merkle-Patricia Trie generic over key hasher and node encoding, deprecated please use trie-db crate"
repository = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common"
license = "GPL-3.0" license = "GPL-3.0"

View File

@ -15,6 +15,8 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Hasher implementation for the Keccak-256 hash //! Hasher implementation for the Keccak-256 hash
//!
//! This is deprecated in favor of trie crate.
extern crate hashdb; extern crate hashdb;
extern crate ethereum_types; extern crate ethereum_types;
extern crate tiny_keccak; extern crate tiny_keccak;

View File

@ -1,14 +1,14 @@
[package] [package]
name = "patricia-trie-ethereum" name = "patricia-trie-ethereum"
version = "0.1.0" version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Merkle-Patricia Trie (Ethereum Style)" description = "Merkle-Patricia Trie (Ethereum Style)"
license = "GPL-3.0" license = "GPL-3.0"
[dependencies] [dependencies]
patricia-trie = { version = "0.3.0", path = "../../patricia_trie" } trie-db = { version = "0.11.0" }
keccak-hasher = { version = "0.1", path = "../keccak-hasher" } keccak-hasher = { version = "0.11.0" }
hashdb = { version = "0.3.0", path = "../../hashdb" } hash-db = { version = "0.11.0" }
rlp = { version = "0.3.0", path = "../../rlp" } rlp = { version = "0.3.0", path = "../../rlp" }
parity-bytes = { version = "0.1", path = "../../parity-bytes" } parity-bytes = { version = "0.1", path = "../../parity-bytes" }

View File

@ -1,18 +1,18 @@
[package] [package]
name = "triehash" name = "triehash"
version = "0.3.0" version = "0.4.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "In-memory patricia trie operations" description = "In-memory patricia trie operations"
repository = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common"
license = "GPL-3.0" license = "GPL-3.0"
[dependencies] [dependencies]
hashdb = { version = "0.3.0", path = "../hashdb", default-features = false } hash-db = { version = "0.11.0", default-features = false }
rlp = { version = "0.3.0", path = "../rlp", default-features = false } rlp = { version = "0.3.0", path = "../rlp", default-features = false }
[dev-dependencies] [dev-dependencies]
trie-standardmap = { version = "0.1", path = "../trie-standardmap" } trie-standardmap = { version = "0.1", path = "../trie-standardmap" }
keccak-hasher = { version = "0.1", path = "../test-support/keccak-hasher" } keccak-hasher = { version = "0.11.0" }
tiny-keccak = "1.4.2" tiny-keccak = "1.4.2"
ethereum-types = "0.4" ethereum-types = "0.4"

View File

@ -1,4 +1,4 @@
// Copyright 2015-2018 Parity Technologies (UK) Ltd. // Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity. // This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify // Parity is free software: you can redistribute it and/or modify
@ -18,14 +18,14 @@
//! //!
//! This module should be used to generate trie root hash. //! This module should be used to generate trie root hash.
extern crate hashdb; extern crate hash_db;
extern crate rlp; extern crate rlp;
#[cfg(test)] extern crate keccak_hasher; #[cfg(test)] extern crate keccak_hasher;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::cmp; use std::cmp;
use std::iter::once; use std::iter::once;
use hashdb::Hasher; use hash_db::Hasher;
use rlp::RlpStream; use rlp::RlpStream;
fn shared_prefix_len<T: Eq>(first: &[T], second: &[T]) -> usize { fn shared_prefix_len<T: Eq>(first: &[T], second: &[T]) -> usize {
@ -40,13 +40,15 @@ fn shared_prefix_len<T: Eq>(first: &[T], second: &[T]) -> usize {
/// ```rust /// ```rust
/// extern crate triehash; /// extern crate triehash;
/// extern crate keccak_hasher; /// extern crate keccak_hasher;
/// extern crate ethereum_types;
/// use ethereum_types::H256;
/// use triehash::ordered_trie_root; /// use triehash::ordered_trie_root;
/// use keccak_hasher::KeccakHasher; /// use keccak_hasher::KeccakHasher;
/// ///
/// fn main() { /// fn main() {
/// let v = &["doe", "reindeer"]; /// let v = &["doe", "reindeer"];
/// let root = "e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3"; /// let root = H256::from("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3");
/// assert_eq!(ordered_trie_root::<KeccakHasher, _>(v), root.into()); /// assert_eq!(ordered_trie_root::<KeccakHasher, _>(v), root.as_ref());
/// } /// }
/// ``` /// ```
pub fn ordered_trie_root<H, I>(input: I) -> H::Out pub fn ordered_trie_root<H, I>(input: I) -> H::Out
@ -54,7 +56,7 @@ where
I: IntoIterator, I: IntoIterator,
I::Item: AsRef<[u8]>, I::Item: AsRef<[u8]>,
H: Hasher, H: Hasher,
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable, <H as hash_db::Hasher>::Out: cmp::Ord,
{ {
trie_root::<H, _, _, _>(input.into_iter().enumerate().map(|(i, v)| (rlp::encode(&i), v))) trie_root::<H, _, _, _>(input.into_iter().enumerate().map(|(i, v)| (rlp::encode(&i), v)))
} }
@ -63,8 +65,10 @@ where
/// ///
/// ```rust /// ```rust
/// extern crate triehash; /// extern crate triehash;
/// extern crate ethereum_types;
/// extern crate keccak_hasher; /// extern crate keccak_hasher;
/// use triehash::trie_root; /// use triehash::trie_root;
/// use ethereum_types::H256;
/// use keccak_hasher::KeccakHasher; /// use keccak_hasher::KeccakHasher;
/// ///
/// fn main() { /// fn main() {
@ -74,8 +78,8 @@ where
/// ("dogglesworth", "cat"), /// ("dogglesworth", "cat"),
/// ]; /// ];
/// ///
/// let root = "8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"; /// let root = H256::from("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
/// assert_eq!(trie_root::<KeccakHasher, _, _, _>(v), root.into()); /// assert_eq!(trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// } /// }
/// ``` /// ```
pub fn trie_root<H, I, A, B>(input: I) -> H::Out pub fn trie_root<H, I, A, B>(input: I) -> H::Out
@ -84,7 +88,7 @@ where
A: AsRef<[u8]> + Ord, A: AsRef<[u8]> + Ord,
B: AsRef<[u8]>, B: AsRef<[u8]>,
H: Hasher, H: Hasher,
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable, <H as hash_db::Hasher>::Out: cmp::Ord,
{ {
// first put elements into btree to sort them and to remove duplicates // first put elements into btree to sort them and to remove duplicates
@ -118,6 +122,8 @@ where
/// ```rust /// ```rust
/// extern crate triehash; /// extern crate triehash;
/// extern crate keccak_hasher; /// extern crate keccak_hasher;
/// extern crate ethereum_types;
/// use ethereum_types::H256;
/// use triehash::sec_trie_root; /// use triehash::sec_trie_root;
/// use keccak_hasher::KeccakHasher; /// use keccak_hasher::KeccakHasher;
/// ///
@ -128,8 +134,8 @@ where
/// ("dogglesworth", "cat"), /// ("dogglesworth", "cat"),
/// ]; /// ];
/// ///
/// let root = "d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585"; /// let root = H256::from("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585");
/// assert_eq!(sec_trie_root::<KeccakHasher, _, _, _>(v), root.into()); /// assert_eq!(sec_trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// } /// }
/// ``` /// ```
pub fn sec_trie_root<H, I, A, B>(input: I) -> H::Out pub fn sec_trie_root<H, I, A, B>(input: I) -> H::Out
@ -138,7 +144,7 @@ where
A: AsRef<[u8]>, A: AsRef<[u8]>,
B: AsRef<[u8]>, B: AsRef<[u8]>,
H: Hasher, H: Hasher,
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable, <H as hash_db::Hasher>::Out: cmp::Ord,
{ {
trie_root::<H, _, _, _>(input.into_iter().map(|(k, v)| (H::hash(k.as_ref()), v))) trie_root::<H, _, _, _>(input.into_iter().map(|(k, v)| (H::hash(k.as_ref()), v)))
} }
@ -181,7 +187,6 @@ where
A: AsRef<[u8]>, A: AsRef<[u8]>,
B: AsRef<[u8]>, B: AsRef<[u8]>,
H: Hasher, H: Hasher,
<H as hashdb::Hasher>::Out: rlp::Encodable,
{ {
let inlen = input.len(); let inlen = input.len();
@ -264,21 +269,22 @@ where
A: AsRef<[u8]>, A: AsRef<[u8]>,
B: AsRef<[u8]>, B: AsRef<[u8]>,
H: Hasher, H: Hasher,
<H as hashdb::Hasher>::Out: rlp::Encodable,
{ {
let mut s = RlpStream::new(); let mut s = RlpStream::new();
hash256rlp::<H, _, _>(input, pre_len, &mut s); hash256rlp::<H, _, _>(input, pre_len, &mut s);
let out = s.out(); let out = s.out();
match out.len() { match out.len() {
0...31 => stream.append_raw(&out, 1), 0...31 => stream.append_raw(&out, 1),
_ => stream.append(&H::hash(&out)) _ => stream.append(&H::hash(&out).as_ref())
}; };
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ethereum_types;
use super::{trie_root, shared_prefix_len, hex_prefix_encode}; use super::{trie_root, shared_prefix_len, hex_prefix_encode};
use keccak_hasher::KeccakHasher; use keccak_hasher::KeccakHasher;
use self::ethereum_types::H256;
#[test] #[test]
fn test_hex_prefix_encode() { fn test_hex_prefix_encode() {
@ -317,7 +323,7 @@ mod tests {
fn simple_test() { fn simple_test() {
assert_eq!(trie_root::<KeccakHasher, _, _, _>(vec![ assert_eq!(trie_root::<KeccakHasher, _, _, _>(vec![
(b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8]) (b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8])
]), "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab".into()); ]), H256::from("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").as_ref());
} }
#[test] #[test]