Skip to content

Commit

Permalink
Merge pull request #31 from carver/use-ethereum-types-H256
Browse files Browse the repository at this point in the history
feat!: use ethereum-types::H256, not keccak-hash::
  • Loading branch information
carver authored Sep 1, 2023
2 parents 82f6b63 + f3d8751 commit 3ebfc36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ homepage = "https://github.com/carver/eth-trie.rs"
documentation = "https://docs.rs/eth_trie"

[dependencies]
ethereum-types = "0.12.1"
hashbrown = "0.14.0"
keccak-hash = "0.10.0"
log = "0.4.16"
Expand All @@ -22,7 +23,6 @@ rlp = "0.5.1"
rand = "0.8.3"
hex = "0.4.2"
criterion = "0.5.1"
ethereum-types = "0.14.1"
uuid = { version = "1.4.1", features = ["serde", "v4"] }

[[bench]]
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;
use std::fmt;

use keccak_hash::H256;
use ethereum_types::H256;
use rlp::DecoderError;

use crate::nibbles::Nibbles;
Expand Down
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, RwLock};

use keccak_hash::H256;
use ethereum_types::H256;

use crate::nibbles::Nibbles;

Expand Down
15 changes: 8 additions & 7 deletions src/trie.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use keccak_hash::KECCAK_NULL_RLP;
use std::sync::{Arc, RwLock};

use ethereum_types::H256;
use hashbrown::{HashMap, HashSet};
use keccak_hash::{keccak, H256};
use keccak_hash::{keccak, KECCAK_NULL_RLP};
use log::warn;
use rlp::{Prototype, Rlp, RlpStream};

Expand Down Expand Up @@ -225,7 +225,7 @@ where
pub fn new(db: Arc<D>) -> Self {
Self {
root: Node::Empty,
root_hash: KECCAK_NULL_RLP,
root_hash: KECCAK_NULL_RLP.as_fixed_bytes().into(),

cache: HashMap::new(),
passing_keys: HashSet::new(),
Expand Down Expand Up @@ -388,7 +388,7 @@ where
) -> TrieResult<Option<Vec<u8>>> {
let proof_db = Arc::new(MemoryDB::new(true));
for node_encoded in proof.into_iter() {
let hash = keccak(&node_encoded);
let hash: H256 = keccak(&node_encoded).as_fixed_bytes().into();

if root_hash.eq(&hash) || node_encoded.len() >= HASHED_LENGTH {
proof_db.insert(hash.as_bytes(), node_encoded).unwrap();
Expand Down Expand Up @@ -764,7 +764,7 @@ where
let root_hash = match self.write_node(&self.root.clone()) {
EncodedNode::Hash(hash) => hash,
EncodedNode::Inline(encoded) => {
let hash = keccak(&encoded);
let hash: H256 = keccak(&encoded).as_fixed_bytes().into();
self.cache.insert(hash.as_bytes().to_vec(), encoded);
hash
}
Expand Down Expand Up @@ -813,7 +813,7 @@ where
if data.len() < HASHED_LENGTH {
EncodedNode::Inline(data)
} else {
let hash = keccak(&data);
let hash: H256 = keccak(&data).as_fixed_bytes().into();
self.cache.insert(hash.as_bytes().to_vec(), data);

self.gen_keys.insert(hash.as_bytes().to_vec());
Expand Down Expand Up @@ -931,7 +931,8 @@ mod tests {
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use keccak_hash::{H256, KECCAK_NULL_RLP};
use ethereum_types::H256;
use keccak_hash::KECCAK_NULL_RLP;

use super::{EthTrie, Trie};
use crate::db::{MemoryDB, DB};
Expand Down

0 comments on commit 3ebfc36

Please sign in to comment.