From 4760dbb0789caaeb1ff95016b37131f035ea42f5 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 28 Nov 2022 14:22:19 -0500 Subject: [PATCH] add wrapper type --- consensus/types/src/signed_block_and_blobs.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/consensus/types/src/signed_block_and_blobs.rs b/consensus/types/src/signed_block_and_blobs.rs index 8dfd8d388..9b2057fa9 100644 --- a/consensus/types/src/signed_block_and_blobs.rs +++ b/consensus/types/src/signed_block_and_blobs.rs @@ -1,6 +1,6 @@ use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844}; use serde_derive::{Deserialize, Serialize}; -use ssz::{Decode, DecodeError, Encode}; +use ssz::{Decode, DecodeError}; use ssz_derive::{Decode, Encode}; use std::sync::Arc; use tree_hash_derive::TreeHash; @@ -31,3 +31,22 @@ impl SignedBeaconBlockAndBlobsSidecar { }) } } + +/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. +pub enum BlockWrapper { + Block { + block: Arc>, + }, + BlockAndBlob { + block_sidecar_pair: SignedBeaconBlockAndBlobsSidecar, + }, +} + +impl BlockWrapper { + pub fn block(&self) -> &SignedBeaconBlock { + match self { + BlockWrapper::Block { block } => &block, + BlockWrapper::BlockAndBlob { block_sidecar_pair } => &block_sidecar_pair.beacon_block, + } + } +}