diff --git a/crates/primitives-traits/Cargo.toml b/crates/primitives-traits/Cargo.toml index 9634da40f47c..74ff802b6df7 100644 --- a/crates/primitives-traits/Cargo.toml +++ b/crates/primitives-traits/Cargo.toml @@ -44,7 +44,6 @@ reth-testing-utils.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary"] } alloy-consensus = { workspace = true, features = ["arbitrary"] } -arbitrary = { workspace = true, features = ["derive"] } bincode.workspace = true proptest-arbitrary-interop.workspace = true proptest.workspace = true diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index 57d1119b0351..0489a250bbd1 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -14,6 +14,7 @@ extern crate alloc; /// Common constants. pub mod constants; + pub use constants::gas_units::{format_gas, format_gas_throughput}; /// Minimal account @@ -24,7 +25,7 @@ pub mod receipt; pub use receipt::Receipt; pub mod transaction; -pub use transaction::{signed::SignedTransaction, Transaction}; +pub use transaction::{signed::SignedTransaction, FullTransaction, Transaction}; mod integer_list; pub use integer_list::{IntegerList, IntegerListError}; diff --git a/crates/primitives-traits/src/transaction/mod.rs b/crates/primitives-traits/src/transaction/mod.rs index a306c5f76ed5..a1ad81ab3270 100644 --- a/crates/primitives-traits/src/transaction/mod.rs +++ b/crates/primitives-traits/src/transaction/mod.rs @@ -1,28 +1,61 @@ //! Transaction abstraction -pub mod signed; +use core::{fmt::Debug, hash::Hash}; -use alloc::fmt; +use alloy_primitives::{TxKind, B256}; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; -/// Helper trait that unifies all behaviour required by transaction to support full node operations. -pub trait FullTransaction: Transaction + Compact {} - -impl FullTransaction for T where T: Transaction + Compact {} +pub mod signed; +#[allow(dead_code)] /// Abstraction of a transaction. pub trait Transaction: - alloy_consensus::Transaction + Debug + + Default + Clone - + fmt::Debug - + PartialEq + Eq - + Default + + PartialEq + + Hash + + Serialize + alloy_rlp::Encodable + alloy_rlp::Decodable - + Serialize + for<'de> Deserialize<'de> + + alloy_consensus::Transaction + + MaybeArbitrary { + /// Heavy operation that return signature hash over rlp encoded transaction. + /// It is only for signature signing or signer recovery. + fn signature_hash(&self) -> B256; + + /// Gets the transaction's [`TxKind`], which is the address of the recipient or + /// [`TxKind::Create`] if the transaction is a contract creation. + fn kind(&self) -> TxKind; + + /// Returns true if the tx supports dynamic fees + fn is_dynamic_fee(&self) -> bool; + + /// Returns the effective gas price for the given base fee. + fn effective_gas_price(&self, base_fee: Option) -> u128; + + /// This encodes the transaction _without_ the signature, and is only suitable for creating a + /// hash intended for signing. + fn encode_without_signature(&self, out: &mut dyn bytes::BufMut); + + /// Calculates a heuristic for the in-memory size of the [Transaction]. + fn size(&self) -> usize; } + +#[cfg(not(feature = "arbitrary"))] +/// Helper trait that requires arbitrary implementation if the feature is enabled. +pub trait MaybeArbitrary {} + +#[cfg(feature = "arbitrary")] +/// Helper trait that requires arbitrary implementation if the feature is enabled. +pub trait MaybeArbitrary: for<'a> arbitrary::Arbitrary<'a> {} + +/// Helper trait that unifies all behaviour required by transaction to support full node operations. +pub trait FullTransaction: Transaction + Compact {} + +impl FullTransaction for T where T: Transaction + Compact {}