reth_primitives_traits/block/
mod.rs

1//! Block abstraction.
2
3pub mod body;
4pub mod header;
5
6use alloc::fmt;
7use alloy_rlp::{Decodable, Encodable};
8
9use crate::{BlockBody, BlockHeader, FullBlockBody, FullBlockHeader, InMemorySize, MaybeSerde};
10
11/// Helper trait that unifies all behaviour required by block to support full node operations.
12pub trait FullBlock:
13    Block<Header: FullBlockHeader, Body: FullBlockBody> + alloy_rlp::Encodable + alloy_rlp::Decodable
14{
15}
16
17impl<T> FullBlock for T where
18    T: Block<Header: FullBlockHeader, Body: FullBlockBody>
19        + alloy_rlp::Encodable
20        + alloy_rlp::Decodable
21{
22}
23
24/// Helper trait to access [`BlockBody::Transaction`] given a [`Block`].
25pub type BlockTx<B> = <<B as Block>::Body as BlockBody>::Transaction;
26
27/// Abstraction of block data type.
28// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
29// todo: make with senders extension trait, so block can be impl by block type already containing
30// senders
31pub trait Block:
32    Send
33    + Sync
34    + Unpin
35    + Clone
36    + Default
37    + fmt::Debug
38    + PartialEq
39    + Eq
40    + InMemorySize
41    + MaybeSerde
42    + Encodable
43    + Decodable
44{
45    /// Header part of the block.
46    type Header: BlockHeader;
47
48    /// The block's body contains the transactions in the block.
49    type Body: BlockBody<OmmerHeader = Self::Header>;
50
51    /// Create new block instance.
52    fn new(header: Self::Header, body: Self::Body) -> Self;
53
54    /// Returns reference to block header.
55    fn header(&self) -> &Self::Header;
56
57    /// Returns reference to block body.
58    fn body(&self) -> &Self::Body;
59
60    /// Splits the block into its header and body.
61    fn split(self) -> (Self::Header, Self::Body);
62}