Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): define helper trait FullNodePrimitives #12331

Merged
merged 11 commits into from
Nov 11, 2024
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/node/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ reth-db-api.workspace = true
reth-engine-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-trie-db.workspace = true

[features]
default = ["std"]
std = [
"reth-primitives-traits/std",
"reth-chainspec/std",
]
25 changes: 22 additions & 3 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

pub use reth_primitives_traits::{Block, BlockBody};
pub use reth_primitives_traits::{Block, BlockBody, FullBlock, FullReceipt, FullSignedTx};

use core::fmt;
use std::marker::PhantomData;
use core::{fmt, marker::PhantomData};

use reth_chainspec::EthChainSpec;
use reth_db_api::{
Expand All @@ -37,6 +37,25 @@ impl NodePrimitives for () {
type Receipt = ();
}

/// Helper trait that sets trait bounds on [`NodePrimitives`].
pub trait FullNodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug {
/// Block primitive.
type Block: FullBlock<Body: BlockBody<SignedTransaction = Self::SignedTx>>;
/// Signed version of the transaction type.
type SignedTx: FullSignedTx;
/// A receipt.
type Receipt: FullReceipt;
}

impl<T> NodePrimitives for T
where
T: FullNodePrimitives<Block: 'static, SignedTx: 'static, Receipt: 'static>,
{
type Block = T::Block;
type SignedTx = T::SignedTx;
type Receipt = T::Receipt;
}

/// The type that configures the essential types of an Ethereum-like node.
///
/// This includes the primitive types of a node and chain specification.
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ use crate::Block;

/// Abstraction for block's body.
pub trait BlockBody:
Clone
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ Default
+ serde::Serialize
+ for<'de> serde::Deserialize<'de>
+ alloy_rlp::Encodable
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ impl<T> FullBlock for T where T: Block<Header: Compact> + Compact {}
// todo: make with senders extension trait, so block can be impl by block type already containing
// senders
pub trait Block:
fmt::Debug
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ Default
+ serde::Serialize
+ for<'a> serde::Deserialize<'a>
+ From<(Self::Header, Self::Body)>
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod account;
pub use account::{Account, Bytecode};

pub mod receipt;
pub use receipt::Receipt;
pub use receipt::{FullReceipt, Receipt};

pub mod transaction;
pub use transaction::{
Expand Down
9 changes: 8 additions & 1 deletion crates/primitives-traits/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Receipt abstraction

use core::fmt;

use alloy_consensus::TxReceipt;
use reth_codecs::Compact;
use serde::{Deserialize, Serialize};
Expand All @@ -11,8 +13,13 @@ impl<T> FullReceipt for T where T: Receipt + Compact {}

/// Abstraction of a receipt.
pub trait Receipt:
TxReceipt
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ TxReceipt
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ Serialize
Expand Down
9 changes: 6 additions & 3 deletions crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Transaction abstraction

use core::{fmt::Debug, hash::Hash};
use core::{fmt, hash::Hash};

use alloy_primitives::{TxKind, B256};

Expand All @@ -12,9 +12,12 @@ pub mod signed;
#[allow(dead_code)]
/// Abstraction of a transaction.
pub trait Transaction:
Debug
+ Default
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ Eq
+ PartialEq
+ Hash
Expand Down
8 changes: 5 additions & 3 deletions crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ impl<T> FullSignedTx for T where T: SignedTransaction<Transaction: Compact> + Co

/// A signed transaction.
pub trait SignedTransaction:
fmt::Debug
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ Hash
+ Send
+ Sync
+ serde::Serialize
+ for<'a> serde::Deserialize<'a>
+ alloy_rlp::Encodable
Expand Down
23 changes: 12 additions & 11 deletions crates/primitives-traits/src/tx_type.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
use core::fmt;

use alloy_eips::eip2718::Eip2718Error;
use alloy_primitives::{U64, U8};
use alloy_rlp::{Decodable, Encodable};
use core::fmt::{Debug, Display};

/// Trait representing the behavior of a transaction type.
pub trait TxType:
Into<u8>
+ Into<U8>
Send
+ Sync
+ Unpin
+ Clone
+ Copy
+ Default
+ fmt::Debug
+ fmt::Display
+ PartialEq
+ Eq
+ PartialEq<u8>
+ Into<u8>
+ Into<U8>
+ TryFrom<u8, Error = Eip2718Error>
+ TryFrom<u64>
+ TryFrom<U64>
+ Debug
+ Display
+ Clone
+ Copy
+ Default
+ Encodable
+ Decodable
+ Send
+ Sync
+ 'static
{
}
Loading