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    >,
39{
40}
41
42impl<T> FullNodePrimitives for T where
43    T: NodePrimitives<
44        Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>,
45        BlockHeader: FullBlockHeader,
46        BlockBody: FullBlockBody<Transaction = Self::SignedTx>,
47        SignedTx: FullSignedTx,
48        Receipt: FullReceipt,
49    >
50{
51}
52
53/// Helper adapter type for accessing [`NodePrimitives`] block header types.
54pub type HeaderTy<N> = <N as NodePrimitives>::BlockHeader;
55
56/// Helper adapter type for accessing [`NodePrimitives`] block body types.
57pub type BodyTy<N> = <N as NodePrimitives>::BlockBody;
58
59/// Helper adapter type for accessing [`NodePrimitives`] block types.
60pub type BlockTy<N> = <N as NodePrimitives>::Block;
61
62/// Helper adapter type for accessing [`NodePrimitives`] receipt types.
63pub type ReceiptTy<N> = <N as NodePrimitives>::Receipt;
64
65/// Helper adapter type for accessing [`NodePrimitives`] signed transaction types.
66pub type TxTy<N> = <N as NodePrimitives>::SignedTx;