reth_network_p2p/bodies/
response.rsuse alloy_primitives::{BlockNumber, U256};
use reth_primitives::{BlockBody, SealedBlock, SealedHeader};
use reth_primitives_traits::InMemorySize;
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum BlockResponse<B = BlockBody> {
Full(SealedBlock<alloy_consensus::Header, B>),
Empty(SealedHeader),
}
impl<B> BlockResponse<B> {
pub const fn header(&self) -> &SealedHeader {
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<B: InMemorySize> InMemorySize for BlockResponse<B> {
#[inline]
fn size(&self) -> usize {
match self {
Self::Full(block) => SealedBlock::size(block),
Self::Empty(header) => SealedHeader::size(header),
}
}
}