Remove SSZ dep from tree_hash
This commit is contained in:
parent
af39f096e7
commit
10eeced227
@ -8,4 +8,3 @@ edition = "2018"
|
||||
ethereum-types = "0.5"
|
||||
hashing = { path = "../hashing" }
|
||||
int_to_bytes = { path = "../int_to_bytes" }
|
||||
ssz = { path = "../ssz" }
|
||||
|
@ -1,13 +1,12 @@
|
||||
use super::resize::{grow_merkle_cache, shrink_merkle_cache};
|
||||
use super::*;
|
||||
use ssz::ssz_encode;
|
||||
|
||||
mod vec;
|
||||
|
||||
impl CachedTreeHashSubTree<u64> for u64 {
|
||||
fn new_tree_hash_cache(&self) -> Result<TreeHashCache, Error> {
|
||||
Ok(TreeHashCache::from_bytes(
|
||||
merkleize(ssz_encode(self)),
|
||||
merkleize(self.to_le_bytes().to_vec()),
|
||||
false,
|
||||
)?)
|
||||
}
|
||||
@ -23,7 +22,7 @@ impl CachedTreeHashSubTree<u64> for u64 {
|
||||
chunk: usize,
|
||||
) -> Result<usize, Error> {
|
||||
if self != other {
|
||||
let leaf = merkleize(ssz_encode(self));
|
||||
let leaf = merkleize(self.to_le_bytes().to_vec());
|
||||
cache.modify_chunk(chunk, &leaf)?;
|
||||
}
|
||||
|
||||
|
@ -49,26 +49,3 @@ macro_rules! impl_tree_hash_for_ssz_bytes {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_vec_as_fixed_len {
|
||||
($type: ty) => {
|
||||
impl tree_hash::TreeHash for $type {
|
||||
fn tree_hash_type() -> tree_hash::TreeHashType {
|
||||
tree_hash::TreeHashType::Vector
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
unreachable!("Vector should never be packed.")
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
unreachable!("Vector should never be packed.")
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
tree_hash::standard_tree_hash::vec_tree_hash_root(self)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::*;
|
||||
use hashing::hash;
|
||||
use int_to_bytes::int_to_bytes32;
|
||||
use ssz::ssz_encode;
|
||||
|
||||
pub use impls::vec_tree_hash_root;
|
||||
|
||||
|
@ -9,7 +9,7 @@ macro_rules! impl_for_bitsize {
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
ssz_encode(self)
|
||||
self.to_le_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
@ -28,7 +28,24 @@ impl_for_bitsize!(u16, 16);
|
||||
impl_for_bitsize!(u32, 32);
|
||||
impl_for_bitsize!(u64, 64);
|
||||
impl_for_bitsize!(usize, 64);
|
||||
impl_for_bitsize!(bool, 8);
|
||||
|
||||
impl TreeHash for bool {
|
||||
fn tree_hash_type() -> TreeHashType {
|
||||
TreeHashType::Basic
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
(*self as u8).tree_hash_packed_encoding()
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
u8::tree_hash_packing_factor()
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
int_to_bytes32(*self as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeHash for [u8; 4] {
|
||||
fn tree_hash_type() -> TreeHashType {
|
||||
@ -44,7 +61,7 @@ impl TreeHash for [u8; 4] {
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
merkle_root(&ssz::ssz_encode(self))
|
||||
merkle_root(&self[..])
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +71,7 @@ impl TreeHash for H256 {
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
ssz_encode(self)
|
||||
self.as_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
@ -62,7 +79,7 @@ impl TreeHash for H256 {
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
merkle_root(&ssz::ssz_encode(self))
|
||||
merkle_root(&self.as_bytes().to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user