Add TreeHash trait to all types and structs

This commit is contained in:
Kirk Baird
2019-01-25 12:22:56 +11:00
parent 407bf5e06d
commit 9c9b07c182
31 changed files with 642 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
use super::ethereum_types::{Address, H256};
use super::{merkle_hash, ssz_encode, TreeHash};
use super::{hash, merkle_hash, ssz_encode, TreeHash};
impl TreeHash for u8 {
fn hash_tree_root(&self) -> Vec<u8> {
@@ -25,6 +25,12 @@ impl TreeHash for u64 {
}
}
impl TreeHash for usize {
fn hash_tree_root(&self) -> Vec<u8> {
ssz_encode(self)
}
}
impl TreeHash for Address {
fn hash_tree_root(&self) -> Vec<u8> {
ssz_encode(self)
@@ -37,6 +43,15 @@ impl TreeHash for H256 {
}
}
impl TreeHash for [u8] {
fn hash_tree_root(&self) -> Vec<u8> {
if self.len() > 32 {
return hash(&self);
}
self.to_vec()
}
}
impl<T> TreeHash for Vec<T>
where
T: TreeHash,