reth_network_p2p/bodies/
response.rs1use alloy_consensus::BlockHeader;
2use alloy_primitives::{BlockNumber, U256};
3use reth_primitives_traits::{Block, InMemorySize, SealedBlock, SealedHeader};
4#[derive(PartialEq, Eq, Debug, Clone)]
6pub enum BlockResponse<B: Block> {
7 Full(SealedBlock<B>),
9 Empty(SealedHeader<B::Header>),
11}
12
13impl<B> BlockResponse<B>
14where
15 B: Block,
16{
17 pub fn block_number(&self) -> BlockNumber {
19 match self {
20 Self::Full(block) => block.number(),
21 Self::Empty(header) => header.number(),
22 }
23 }
24
25 pub fn difficulty(&self) -> U256 {
27 match self {
28 Self::Full(block) => block.difficulty(),
29 Self::Empty(header) => header.difficulty(),
30 }
31 }
32
33 pub fn into_body(self) -> Option<B::Body> {
35 match self {
36 Self::Full(block) => Some(block.into_body()),
37 Self::Empty(_) => None,
38 }
39 }
40
41 pub const fn body(&self) -> Option<&B::Body> {
43 match self {
44 Self::Full(block) => Some(block.body()),
45 Self::Empty(_) => None,
46 }
47 }
48}
49
50impl<B: Block> InMemorySize for BlockResponse<B> {
51 #[inline]
52 fn size(&self) -> usize {
53 match self {
54 Self::Full(block) => SealedBlock::size(block),
55 Self::Empty(header) => SealedHeader::size(header),
56 }
57 }
58}