reth_network_p2p/bodies/
response.rsuse alloy_consensus::BlockHeader;
use alloy_primitives::{BlockNumber, U256};
use reth_primitives::{BlockBody, SealedBlock, SealedHeader};
use reth_primitives_traits::InMemorySize;
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum BlockResponse<H, B = BlockBody> {
Full(SealedBlock<H, B>),
Empty(SealedHeader<H>),
}
impl<H, B> BlockResponse<H, B>
where
H: BlockHeader,
{
pub const fn header(&self) -> &SealedHeader<H> {
match self {
Self::Full(block) => &block.header,
Self::Empty(header) => header,
}
}
pub fn block_number(&self) -> BlockNumber {
self.header().number()
}
pub fn difficulty(&self) -> U256 {
match self {
Self::Full(block) => block.difficulty(),
Self::Empty(header) => header.difficulty(),
}
}
pub fn into_body(self) -> Option<B> {
match self {
Self::Full(block) => Some(block.body),
Self::Empty(_) => None,
}
}
}
impl<H: InMemorySize, B: InMemorySize> InMemorySize for BlockResponse<H, B> {
#[inline]
fn size(&self) -> usize {
match self {
Self::Full(block) => SealedBlock::size(block),
Self::Empty(header) => SealedHeader::size(header),
}
}
}