mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-29 18:53:32 +00:00
54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
use crate::{DBColumn, Error, StoreItem};
|
|
use ssz::{Decode, Encode};
|
|
use types::{
|
|
BlobSidecarList, EthSpec, ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadDeneb,
|
|
ExecutionPayloadMerge,
|
|
};
|
|
|
|
macro_rules! impl_store_item {
|
|
($ty_name:ident) => {
|
|
impl<E: EthSpec> StoreItem for $ty_name<E> {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::ExecPayload
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Result<Vec<u8>, Error> {
|
|
Ok(self.as_ssz_bytes())
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(Self::from_ssz_bytes(bytes)?)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
impl_store_item!(ExecutionPayloadMerge);
|
|
impl_store_item!(ExecutionPayloadCapella);
|
|
impl_store_item!(ExecutionPayloadDeneb);
|
|
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<E: EthSpec> StoreItem for ExecutionPayload<E> {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::ExecPayload
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Result<Vec<u8>, Error> {
|
|
Ok(self.as_ssz_bytes())
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
ExecutionPayloadDeneb::from_ssz_bytes(bytes)
|
|
.map(Self::Deneb)
|
|
.or_else(|_| {
|
|
ExecutionPayloadCapella::from_ssz_bytes(bytes)
|
|
.map(Self::Capella)
|
|
.or_else(|_| ExecutionPayloadMerge::from_ssz_bytes(bytes).map(Self::Merge))
|
|
})
|
|
.map_err(Into::into)
|
|
}
|
|
}
|