mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Merge branch 'master' into 215-migrate-ssz-little-endian
This commit is contained in:
@@ -6,5 +6,5 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bytes = "0.4.9"
|
||||
ethereum-types = "0.4.0"
|
||||
ethereum-types = "0.5"
|
||||
hashing = { path = "../hashing" }
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Decodable for H256 {
|
||||
if bytes.len() < 32 || bytes.len() - 32 < index {
|
||||
Err(DecodeError::TooShort)
|
||||
} else {
|
||||
Ok((H256::from(&bytes[index..(index + 32)]), index + 32))
|
||||
Ok((H256::from_slice(&bytes[index..(index + 32)]), index + 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl Decodable for Address {
|
||||
if bytes.len() < 20 || bytes.len() - 20 < index {
|
||||
Err(DecodeError::TooShort)
|
||||
} else {
|
||||
Ok((Address::from(&bytes[index..(index + 20)]), index + 20))
|
||||
Ok((Address::from_slice(&bytes[index..(index + 20)]), index + 20))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ mod tests {
|
||||
*/
|
||||
let input = vec![42_u8; 32];
|
||||
let (decoded, i) = H256::ssz_decode(&input, 0).unwrap();
|
||||
assert_eq!(decoded.to_vec(), input);
|
||||
assert_eq!(decoded.as_bytes(), &input[..]);
|
||||
assert_eq!(i, 32);
|
||||
|
||||
/*
|
||||
@@ -104,7 +104,7 @@ mod tests {
|
||||
let mut input = vec![42_u8; 32];
|
||||
input.push(12);
|
||||
let (decoded, i) = H256::ssz_decode(&input, 0).unwrap();
|
||||
assert_eq!(decoded.to_vec()[..], input[0..32]);
|
||||
assert_eq!(decoded.as_bytes(), &input[0..32]);
|
||||
assert_eq!(i, 32);
|
||||
|
||||
/*
|
||||
|
||||
@@ -55,13 +55,13 @@ impl Encodable for bool {
|
||||
|
||||
impl Encodable for H256 {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_encoded_raw(&self.to_vec());
|
||||
s.append_encoded_raw(self.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Address {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_encoded_raw(&self.to_vec());
|
||||
s.append_encoded_raw(self.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@ impl TreeHash for usize {
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeHash for bool {
|
||||
fn hash_tree_root_internal(&self) -> Vec<u8> {
|
||||
ssz_encode(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeHash for Address {
|
||||
fn hash_tree_root_internal(&self) -> Vec<u8> {
|
||||
ssz_encode(self)
|
||||
|
||||
@@ -12,6 +12,7 @@ extern crate ethereum_types;
|
||||
|
||||
pub mod decode;
|
||||
pub mod encode;
|
||||
mod signed_root;
|
||||
pub mod tree_hash;
|
||||
|
||||
mod impl_decode;
|
||||
@@ -20,6 +21,7 @@ mod impl_tree_hash;
|
||||
|
||||
pub use crate::decode::{decode_ssz, decode_ssz_list, Decodable, DecodeError};
|
||||
pub use crate::encode::{Encodable, SszStream};
|
||||
pub use crate::signed_root::SignedRoot;
|
||||
pub use crate::tree_hash::{merkle_hash, TreeHash};
|
||||
|
||||
pub use hashing::hash;
|
||||
|
||||
5
eth2/utils/ssz/src/signed_root.rs
Normal file
5
eth2/utils/ssz/src/signed_root.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
use crate::TreeHash;
|
||||
|
||||
pub trait SignedRoot: TreeHash {
|
||||
fn signed_root(&self) -> Vec<u8>;
|
||||
}
|
||||
@@ -7,9 +7,7 @@ pub trait TreeHash {
|
||||
fn hash_tree_root_internal(&self) -> Vec<u8>;
|
||||
fn hash_tree_root(&self) -> Vec<u8> {
|
||||
let mut result = self.hash_tree_root_internal();
|
||||
if result.len() < HASHSIZE {
|
||||
zpad(&mut result, HASHSIZE);
|
||||
}
|
||||
zpad(&mut result, HASHSIZE);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user