mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(sdk): Add blanket impls for refs to prim traits (#12613)
This commit is contained in:
@ -27,6 +27,7 @@ byteorder = "1"
|
||||
derive_more.workspace = true
|
||||
roaring = "0.10.2"
|
||||
serde_with = { workspace = true, optional = true }
|
||||
auto_impl.workspace = true
|
||||
|
||||
# required by reth-codecs
|
||||
bytes.workspace = true
|
||||
|
||||
@ -5,6 +5,7 @@ use alloc::fmt;
|
||||
use alloy_consensus::Transaction;
|
||||
|
||||
/// Abstraction for block's body.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait BlockBody:
|
||||
Send
|
||||
+ Sync
|
||||
@ -19,7 +20,6 @@ pub trait BlockBody:
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ InMemorySize
|
||||
+ 'static
|
||||
{
|
||||
/// Ordered list of signed transactions as committed in block.
|
||||
// todo: requires trait for signed transaction
|
||||
|
||||
@ -26,7 +26,6 @@ pub trait BlockHeader:
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
+ InMemorySize
|
||||
+ 'static
|
||||
{
|
||||
}
|
||||
|
||||
@ -46,6 +45,5 @@ impl<T> BlockHeader for T where
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
+ InMemorySize
|
||||
+ 'static
|
||||
{
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> + Compact {}
|
||||
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
|
||||
// todo: make with senders extension trait, so block can be impl by block type already containing
|
||||
// senders
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait Block:
|
||||
Send
|
||||
+ Sync
|
||||
@ -32,7 +33,7 @@ pub trait Block:
|
||||
+ InMemorySize
|
||||
{
|
||||
/// Header part of the block.
|
||||
type Header: BlockHeader;
|
||||
type Header: BlockHeader + 'static;
|
||||
|
||||
/// The block's body contains the transactions in the block.
|
||||
type Body: Send + Sync + Unpin + 'static;
|
||||
|
||||
@ -10,9 +10,10 @@ use serde::{Deserialize, Serialize};
|
||||
/// Helper trait that unifies all behaviour required by receipt to support full node operations.
|
||||
pub trait FullReceipt: Receipt + Compact {}
|
||||
|
||||
impl<T> FullReceipt for T where T: Receipt + Compact {}
|
||||
impl<T> FullReceipt for T where T: ReceiptExt + Compact {}
|
||||
|
||||
/// Abstraction of a receipt.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait Receipt:
|
||||
Send
|
||||
+ Sync
|
||||
@ -28,7 +29,10 @@ pub trait Receipt:
|
||||
{
|
||||
/// Returns transaction type.
|
||||
fn tx_type(&self) -> u8;
|
||||
}
|
||||
|
||||
/// Extension if [`Receipt`] used in block execution.
|
||||
pub trait ReceiptExt: Receipt {
|
||||
/// Calculates the receipts root of the given receipts.
|
||||
fn receipts_root(receipts: &[&Self]) -> B256;
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/// Trait for calculating a heuristic for the in-memory size of a struct.
|
||||
#[auto_impl::auto_impl(&, Arc, Box)]
|
||||
pub trait InMemorySize {
|
||||
/// Returns a heuristic for the in-memory size of a struct.
|
||||
fn size(&self) -> usize;
|
||||
|
||||
@ -53,6 +53,7 @@ impl<T> Transaction for T where
|
||||
}
|
||||
|
||||
/// Extension trait of [`alloy_consensus::Transaction`].
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait TransactionExt: alloy_consensus::Transaction {
|
||||
/// Transaction envelope type ID.
|
||||
type Type: TxType;
|
||||
|
||||
@ -8,7 +8,7 @@ use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
|
||||
use reth_codecs::Compact;
|
||||
use revm_primitives::TxEnv;
|
||||
|
||||
use crate::{transaction::TransactionExt, FullTransaction, MaybeArbitrary, Transaction};
|
||||
use crate::{FullTransaction, MaybeArbitrary, Transaction};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compact {}
|
||||
@ -16,6 +16,7 @@ pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compac
|
||||
impl<T> FullSignedTx for T where T: SignedTransaction<Transaction: FullTransaction> + Compact {}
|
||||
|
||||
/// A signed transaction.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait SignedTransaction:
|
||||
Send
|
||||
+ Sync
|
||||
@ -32,7 +33,7 @@ pub trait SignedTransaction:
|
||||
+ alloy_rlp::Decodable
|
||||
+ Encodable2718
|
||||
+ Decodable2718
|
||||
+ TransactionExt
|
||||
+ alloy_consensus::Transaction
|
||||
+ MaybeArbitrary
|
||||
{
|
||||
/// Transaction type that is signed.
|
||||
@ -65,14 +66,6 @@ pub trait SignedTransaction:
|
||||
/// `reth_primitives::transaction::recover_signer_unchecked`.
|
||||
fn recover_signer_unchecked(&self) -> Option<Address>;
|
||||
|
||||
/// Create a new signed transaction from a transaction and its signature.
|
||||
///
|
||||
/// This will also calculate the transaction hash using its encoding.
|
||||
fn from_transaction_and_signature(
|
||||
transaction: Self::Transaction,
|
||||
signature: PrimitiveSignature,
|
||||
) -> Self;
|
||||
|
||||
/// Calculate transaction hash, eip2728 transaction does not contain rlp header and start with
|
||||
/// tx type.
|
||||
fn recalculate_hash(&self) -> B256 {
|
||||
@ -83,10 +76,14 @@ pub trait SignedTransaction:
|
||||
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
|
||||
}
|
||||
|
||||
impl<T: SignedTransaction> TransactionExt for T {
|
||||
type Type = <T::Transaction as TransactionExt>::Type;
|
||||
|
||||
fn signature_hash(&self) -> B256 {
|
||||
self.transaction().signature_hash()
|
||||
}
|
||||
/// Helper trait used in testing.
|
||||
#[cfg(feature = "test-utils")]
|
||||
pub trait SignedTransactionTesting: SignedTransaction {
|
||||
/// Create a new signed transaction from a transaction and its signature.
|
||||
///
|
||||
/// This will also calculate the transaction hash using its encoding.
|
||||
fn from_transaction_and_signature(
|
||||
transaction: Self::Transaction,
|
||||
signature: PrimitiveSignature,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user