reth_primitives_traits/
node.rs

1use crate::{
2    Block, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, FullSignedTx,
3    MaybeSerdeBincodeCompat, Receipt,
4};
5use core::fmt;
6
7/// Configures all the primitive types of the node.
8///
9/// This trait defines the core types used throughout the node for representing
10/// blockchain data. It serves as the foundation for type consistency across
11/// different node implementations.
12pub trait NodePrimitives:
13    Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + 'static
14{
15    /// Block primitive.
16    type Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody> + MaybeSerdeBincodeCompat;
17    /// Block header primitive.
18    type BlockHeader: FullBlockHeader;
19    /// Block body primitive.
20    type BlockBody: FullBlockBody<Transaction = Self::SignedTx, OmmerHeader = Self::BlockHeader>;
21    /// Signed version of the transaction type.
22    ///
23    /// This represents the transaction as it exists in the blockchain - the consensus
24    /// format that includes the signature and can be included in a block.
25    type SignedTx: FullSignedTx;
26    /// A receipt.
27    type Receipt: Receipt;
28}
29/// Helper trait that sets trait bounds on [`NodePrimitives`].
30pub trait FullNodePrimitives
31where
32    Self: NodePrimitives<
33            Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>,
34            BlockHeader: FullBlockHeader,
35            BlockBody: FullBlockBody<Transaction = Self::SignedTx>,
36            SignedTx: FullSignedTx,
37            Receipt: FullReceipt,
38        > + Send
39        + Sync
40        + Unpin
41        + Clone
42        + Default
43        + fmt::Debug
44        + PartialEq
45        + Eq
46        + 'static,
47{
48}
49
50impl<T> FullNodePrimitives for T where
51    T: NodePrimitives<
52            Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>,
53            BlockHeader: FullBlockHeader,
54            BlockBody: FullBlockBody<Transaction = Self::SignedTx>,
55            SignedTx: FullSignedTx,
56            Receipt: FullReceipt,
57        > + Send
58        + Sync
59        + Unpin
60        + Clone
61        + Default
62        + fmt::Debug
63        + PartialEq
64        + Eq
65        + 'static
66{
67}
68
69/// Helper adapter type for accessing [`NodePrimitives`] block header types.
70pub type HeaderTy<N> = <N as NodePrimitives>::BlockHeader;
71
72/// Helper adapter type for accessing [`NodePrimitives`] block body types.
73pub type BodyTy<N> = <N as NodePrimitives>::BlockBody;
74
75/// Helper adapter type for accessing [`NodePrimitives`] block types.
76pub type BlockTy<N> = <N as NodePrimitives>::Block;
77
78/// Helper adapter type for accessing [`NodePrimitives`] receipt types.
79pub type ReceiptTy<N> = <N as NodePrimitives>::Receipt;
80
81/// Helper adapter type for accessing [`NodePrimitives`] signed transaction types.
82pub type TxTy<N> = <N as NodePrimitives>::SignedTx;