use crate::{DBColumn, Error, StoreItem}; use ssz::{Decode, Encode}; use types::{ BlobSidecarList, EthSpec, ExecutionPayload, ExecutionPayloadBellatrix, ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadFulu, }; macro_rules! impl_store_item { ($ty_name:ident) => { impl StoreItem for $ty_name { fn db_column() -> DBColumn { DBColumn::ExecPayload } fn as_store_bytes(&self) -> Vec { self.as_ssz_bytes() } fn from_store_bytes(bytes: &[u8]) -> Result { Ok(Self::from_ssz_bytes(bytes)?) } } }; } impl_store_item!(ExecutionPayloadBellatrix); impl_store_item!(ExecutionPayloadCapella); impl_store_item!(ExecutionPayloadDeneb); impl_store_item!(ExecutionPayloadElectra); impl_store_item!(ExecutionPayloadFulu); impl_store_item!(BlobSidecarList); /// This fork-agnostic implementation should be only used for writing. /// /// It is very inefficient at reading, and decoding the desired fork-specific variant is recommended /// instead. impl StoreItem for ExecutionPayload { fn db_column() -> DBColumn { DBColumn::ExecPayload } fn as_store_bytes(&self) -> Vec { self.as_ssz_bytes() } fn from_store_bytes(bytes: &[u8]) -> Result { ExecutionPayloadFulu::from_ssz_bytes(bytes) .map(Self::Fulu) .or_else(|_| { ExecutionPayloadElectra::from_ssz_bytes(bytes) .map(Self::Electra) .or_else(|_| { ExecutionPayloadDeneb::from_ssz_bytes(bytes) .map(Self::Deneb) .or_else(|_| { ExecutionPayloadCapella::from_ssz_bytes(bytes) .map(Self::Capella) .or_else(|_| { ExecutionPayloadBellatrix::from_ssz_bytes(bytes) .map(Self::Bellatrix) }) }) }) }) .map_err(Into::into) } }