mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
Fix consensus, SSZ, tree hash & run merge EF tests (#2622)
* Update to v1.1.0-beta.4 (squash of #2548) * SSZ, cached tree hash, EF tests
This commit is contained in:
committed by
Paul Hauner
parent
3718c36c51
commit
ef6158f4ee
25
consensus/ssz_types/src/serde_utils/hex_fixed_vec.rs
Normal file
25
consensus/ssz_types/src/serde_utils/hex_fixed_vec.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::FixedVector;
|
||||
use eth2_serde_utils::hex::{self, PrefixedHexVisitor};
|
||||
use serde::{Deserializer, Serializer};
|
||||
use typenum::Unsigned;
|
||||
|
||||
pub fn serialize<S, U>(bytes: &FixedVector<u8, U>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
U: Unsigned,
|
||||
{
|
||||
let mut hex_string: String = "0x".to_string();
|
||||
hex_string.push_str(&hex::encode(&bytes[..]));
|
||||
|
||||
serializer.serialize_str(&hex_string)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D, U>(deserializer: D) -> Result<FixedVector<u8, U>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
U: Unsigned,
|
||||
{
|
||||
let vec = deserializer.deserialize_string(PrefixedHexVisitor)?;
|
||||
FixedVector::new(vec)
|
||||
.map_err(|e| serde::de::Error::custom(format!("invalid fixed vector: {:?}", e)))
|
||||
}
|
||||
26
consensus/ssz_types/src/serde_utils/hex_var_list.rs
Normal file
26
consensus/ssz_types/src/serde_utils/hex_var_list.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
//! Serialize `VariableList<u8, N>` as 0x-prefixed hex string.
|
||||
use crate::VariableList;
|
||||
use eth2_serde_utils::hex::{self, PrefixedHexVisitor};
|
||||
use serde::{Deserializer, Serializer};
|
||||
use typenum::Unsigned;
|
||||
|
||||
pub fn serialize<S, N>(bytes: &VariableList<u8, N>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
N: Unsigned,
|
||||
{
|
||||
let mut hex_string: String = "0x".to_string();
|
||||
hex_string.push_str(&hex::encode(&**bytes));
|
||||
|
||||
serializer.serialize_str(&hex_string)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D, N>(deserializer: D) -> Result<VariableList<u8, N>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
N: Unsigned,
|
||||
{
|
||||
let bytes = deserializer.deserialize_str(PrefixedHexVisitor)?;
|
||||
VariableList::new(bytes)
|
||||
.map_err(|e| serde::de::Error::custom(format!("invalid variable list: {:?}", e)))
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
pub mod hex_fixed_vec;
|
||||
pub mod hex_var_list;
|
||||
pub mod quoted_u64_fixed_vec;
|
||||
pub mod quoted_u64_var_list;
|
||||
|
||||
Reference in New Issue
Block a user