chore(sdk): Add NodePrimitives::BlockHeader and NodePrimitives::BlockBody (#12647)

This commit is contained in:
Emilia Hane
2024-11-21 18:03:05 +01:00
committed by GitHub
parent 2c7b404c24
commit 2093d2bd9a
9 changed files with 68 additions and 31 deletions

View File

@ -100,4 +100,4 @@ reth-codec = [
"dep:reth-codecs",
"dep:modular-bitfield",
"dep:byteorder",
]
]

View File

@ -1,6 +1,8 @@
use core::fmt;
use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx, FullTxType, MaybeSerde};
use crate::{
FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, FullSignedTx, FullTxType, MaybeSerde,
};
/// Configures all the primitive types of the node.
pub trait NodePrimitives:
@ -17,6 +19,28 @@ pub trait NodePrimitives:
+ Eq
+ MaybeSerde
+ 'static;
/// Block header primitive.
type BlockHeader: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ MaybeSerde
+ 'static;
/// Block body primitive.
type BlockBody: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ MaybeSerde
+ 'static;
/// Signed version of the transaction type.
type SignedTx: Send
+ Sync
@ -45,6 +69,8 @@ pub trait NodePrimitives:
impl NodePrimitives for () {
type Block = ();
type BlockHeader = ();
type BlockBody = ();
type SignedTx = ();
type TxType = ();
type Receipt = ();
@ -55,7 +81,11 @@ pub trait FullNodePrimitives:
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + 'static
{
/// Block primitive.
type Block: FullBlock<Body: BlockBody<Transaction = Self::SignedTx>>;
type Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>;
/// Block header primitive.
type BlockHeader: FullBlockHeader + 'static;
/// Block body primitive.
type BlockBody: FullBlockBody<Transaction = Self::SignedTx> + 'static;
/// Signed version of the transaction type.
type SignedTx: FullSignedTx;
/// Transaction envelope type ID.
@ -66,9 +96,11 @@ pub trait FullNodePrimitives:
impl<T> NodePrimitives for T
where
T: FullNodePrimitives<Block: 'static, SignedTx: 'static, Receipt: 'static, TxType: 'static>,
T: FullNodePrimitives,
{
type Block = T::Block;
type BlockHeader = T::BlockHeader;
type BlockBody = T::BlockBody;
type SignedTx = T::SignedTx;
type TxType = T::TxType;
type Receipt = T::Receipt;