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]
members = [
"fixed-hash",
"hashdb",
"keccak-hash",
"kvdb",
"kvdb-memorydb",
"kvdb-rocksdb",
"memorydb",
"parity-bytes",
"parity-crypto",
"parity-path",
"patricia_trie",
"plain_hasher",
"rlp",
"transaction-pool",

View File

@ -1,4 +1,7 @@
# 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.
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"
version = "0.3.0"
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"
license = "GPL-3.0"

View File

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

View File

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

View File

@ -1,18 +1,18 @@
[package]
name = "triehash"
version = "0.3.0"
version = "0.4.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "In-memory patricia trie operations"
repository = "https://github.com/paritytech/parity-common"
license = "GPL-3.0"
[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 }
[dev-dependencies]
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"
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.
// 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.
extern crate hashdb;
extern crate hash_db;
extern crate rlp;
#[cfg(test)] extern crate keccak_hasher;
use std::collections::BTreeMap;
use std::cmp;
use std::iter::once;
use hashdb::Hasher;
use hash_db::Hasher;
use rlp::RlpStream;
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
/// extern crate triehash;
/// extern crate keccak_hasher;
/// extern crate ethereum_types;
/// use ethereum_types::H256;
/// use triehash::ordered_trie_root;
/// use keccak_hasher::KeccakHasher;
///
/// fn main() {
/// let v = &["doe", "reindeer"];
/// let root = "e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3";
/// assert_eq!(ordered_trie_root::<KeccakHasher, _>(v), root.into());
/// let root = H256::from("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3");
/// assert_eq!(ordered_trie_root::<KeccakHasher, _>(v), root.as_ref());
/// }
/// ```
pub fn ordered_trie_root<H, I>(input: I) -> H::Out
@ -54,7 +56,7 @@ where
I: IntoIterator,
I::Item: AsRef<[u8]>,
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)))
}
@ -63,8 +65,10 @@ where
///
/// ```rust
/// extern crate triehash;
/// extern crate ethereum_types;
/// extern crate keccak_hasher;
/// use triehash::trie_root;
/// use ethereum_types::H256;
/// use keccak_hasher::KeccakHasher;
///
/// fn main() {
@ -74,8 +78,8 @@ where
/// ("dogglesworth", "cat"),
/// ];
///
/// let root = "8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3";
/// assert_eq!(trie_root::<KeccakHasher, _, _, _>(v), root.into());
/// let root = H256::from("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
/// assert_eq!(trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// }
/// ```
pub fn trie_root<H, I, A, B>(input: I) -> H::Out
@ -84,7 +88,7 @@ where
A: AsRef<[u8]> + Ord,
B: AsRef<[u8]>,
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
@ -118,6 +122,8 @@ where
/// ```rust
/// extern crate triehash;
/// extern crate keccak_hasher;
/// extern crate ethereum_types;
/// use ethereum_types::H256;
/// use triehash::sec_trie_root;
/// use keccak_hasher::KeccakHasher;
///
@ -128,8 +134,8 @@ where
/// ("dogglesworth", "cat"),
/// ];
///
/// let root = "d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585";
/// assert_eq!(sec_trie_root::<KeccakHasher, _, _, _>(v), root.into());
/// let root = H256::from("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585");
/// assert_eq!(sec_trie_root::<KeccakHasher, _, _, _>(v), root.as_ref());
/// }
/// ```
pub fn sec_trie_root<H, I, A, B>(input: I) -> H::Out
@ -138,7 +144,7 @@ where
A: AsRef<[u8]>,
B: AsRef<[u8]>,
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)))
}
@ -181,7 +187,6 @@ where
A: AsRef<[u8]>,
B: AsRef<[u8]>,
H: Hasher,
<H as hashdb::Hasher>::Out: rlp::Encodable,
{
let inlen = input.len();
@ -264,21 +269,22 @@ where
A: AsRef<[u8]>,
B: AsRef<[u8]>,
H: Hasher,
<H as hashdb::Hasher>::Out: rlp::Encodable,
{
let mut s = RlpStream::new();
hash256rlp::<H, _, _>(input, pre_len, &mut s);
let out = s.out();
match out.len() {
0...31 => stream.append_raw(&out, 1),
_ => stream.append(&H::hash(&out))
_ => stream.append(&H::hash(&out).as_ref())
};
}
#[cfg(test)]
mod tests {
extern crate ethereum_types;
use super::{trie_root, shared_prefix_len, hex_prefix_encode};
use keccak_hasher::KeccakHasher;
use self::ethereum_types::H256;
#[test]
fn test_hex_prefix_encode() {
@ -317,7 +323,7 @@ mod tests {
fn simple_test() {
assert_eq!(trie_root::<KeccakHasher, _, _, _>(vec![
(b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8])
]), "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab".into());
]), H256::from("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").as_ref());
}
#[test]