Skip to content
Snippets Groups Projects
Commit 3507c389 authored by Wei Tang's avatar Wei Tang
Browse files

Pass all ssz tests

parent e28cf59a
No related merge requests found
......@@ -30,6 +30,7 @@ pub struct BeaconState<C: Config> {
// == Registry ==
pub validators: MaxVec<Validator, C::ValidatorRegistryLimit>,
#[bm(compact)]
pub balances: MaxVec<Uint, C::ValidatorRegistryLimit>,
// == Shuffling ==
......@@ -39,6 +40,7 @@ pub struct BeaconState<C: Config> {
pub compact_committees_roots: VecArray<H256, C::EpochsPerHistoricalVector>,
// == Slashings ==
#[bm(compact)]
pub slashings: VecArray<Uint, C::EpochsPerSlashingsVector>,
// == Attestations ==
......@@ -53,7 +55,7 @@ pub struct BeaconState<C: Config> {
#[bm(compact)]
#[cfg_attr(feature = "serde", serde(serialize_with = "crate::utils::serialize_bitvector"))]
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::utils::deserialize_bitvector"))]
pub justification_bits: generic_array::GenericArray<bool, consts::JustificationBitsLength>,
pub justification_bits: VecArray<bool, consts::JustificationBitsLength>,
pub previous_justified_checkpoint: Checkpoint,
pub current_justified_checkpoint: Checkpoint,
pub finalized_checkpoint: Checkpoint,
......
......@@ -52,6 +52,50 @@ macro_rules! impl_builtin_fixed_uint_vector {
Ok(Compact(ret))
}
}
impl<L: Unsigned> Codec for Compact<VecArray<$t, L>>
{
type Size = Mul<<$t as Codec>::Size, L>;
}
impl<'a, L: Unsigned> Codec for CompactRef<'a, VecArray<$t, L>> where
Compact<VecArray<$t, L>>: Codec,
{
type Size = <Compact<VecArray<$t, L>> as Codec>::Size;
}
impl<'a, L: Unsigned> Encode for CompactRef<'a, VecArray<$t, L>> where
CompactRef<'a, VecArray<$t, L>>: Codec
{
fn encode(&self) -> Vec<u8> {
encode_list(self.0)
}
}
impl<L: Unsigned> Encode for Compact<VecArray<$t, L>> where
Compact<VecArray<$t, L>>: Codec,
for<'a> CompactRef<'a, GenericArray<$t, L>>: Encode
{
fn encode(&self) -> Vec<u8> {
CompactRef(&self.0).encode()
}
}
impl<L: Unsigned> Decode for Compact<VecArray<$t, L>> where
Compact<VecArray<$t, L>>: Codec,
{
fn decode(value: &[u8]) -> Result<Self, Error> {
let decoded = decode_list::<$t>(value)?;
if decoded.len() != L::to_usize() {
return Err(Error::InvalidLength)
}
let mut ret = VecArray::default();
for i in 0..decoded.len() {
ret[i] = decoded[i];
}
Ok(Compact(ret))
}
}
)* }
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment