diff --git a/consensus/types/src/attestation/attestation.rs b/consensus/types/src/attestation/attestation.rs index 693b5889f53..868615c0513 100644 --- a/consensus/types/src/attestation/attestation.rs +++ b/consensus/types/src/attestation/attestation.rs @@ -19,7 +19,7 @@ use crate::{ IndexedAttestationElectra, }, core::{ChainSpec, Domain, EthSpec, Hash256, SignedRoot, Slot, SlotData}, - fork::{Fork, ForkName}, + fork::{Fork, ForkName, ForkVersionDecode}, test_utils::TestRandom, }; @@ -261,6 +261,17 @@ impl Attestation { Self::Electra(attn) => attn.get_aggregation_bits(), } } + + pub fn from_ssz_bytes_for_fork( + bytes: &[u8], + fork_name: ForkName, + ) -> Result { + if fork_name.electra_enabled() { + ssz::Decode::from_ssz_bytes(bytes).map(Self::Electra) + } else { + ssz::Decode::from_ssz_bytes(bytes).map(Self::Base) + } + } } impl AttestationRef<'_, E> { @@ -582,6 +593,12 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Attestation { } } +impl ForkVersionDecode for Attestation { + fn from_ssz_bytes_by_fork(bytes: &[u8], fork_name: ForkName) -> Result { + Self::from_ssz_bytes_for_fork(bytes, fork_name) + } +} + /* impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec> { fn context_deserialize(