mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 14:24:44 +00:00
Add TreeHash trait to all types and structs
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user