reth_network_p2p/bodies/
response.rs
1use 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
42impl<B: Block> InMemorySize for BlockResponse<B> {
43 #[inline]
44 fn size(&self) -> usize {
45 match self {
46 Self::Full(block) => SealedBlock::size(block),
47 Self::Empty(header) => SealedHeader::size(header),
48 }
49 }
50}