diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index a8ec7e3f8b2..7300aba8d4f 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -1,5 +1,6 @@ -use alloy_eips::eip7702::SignedAuthorization; -use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256}; +use alloc::vec::Vec; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; +use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, B256, U256}; use alloy_serde::WithOtherFields; use crate::BlockTransactions; @@ -63,10 +64,24 @@ pub trait ReceiptResponse { /// Transaction JSON-RPC response. pub trait TransactionResponse { + /// Signature type of the transaction + type Signature; /// Hash of the transaction #[doc(alias = "transaction_hash")] fn tx_hash(&self) -> TxHash; + /// Nonce + fn nonce(&self) -> u64; + + /// Block hash + fn block_hash(&self) -> Option; + + /// Block number + fn block_number(&self) -> Option; + + /// Transaction Index + fn transaction_index(&self) -> Option; + /// Sender of the transaction fn from(&self) -> Address; @@ -76,12 +91,42 @@ pub trait TransactionResponse { /// Transferred value fn value(&self) -> U256; + /// Gas Price + fn gas_price(&self) -> Option; + /// Gas limit fn gas(&self) -> u128; + /// Max BaseFeePerGas the user is willing to pay + fn max_fee_per_gas(&self) -> Option; + + /// The miner's tip + fn max_priority_fee_per_gas(&self) -> Option; + + /// Configured max fee per blob gas for eip-4844 transactions + fn max_fee_per_blob_gas(&self) -> Option; + /// Input data #[doc(alias = "calldata")] fn input(&self) -> &Bytes; + + /// Transaction signature + fn signature(&self) -> Option; + + /// The chain id of the transaction + fn chain_id(&self) -> Option; + + /// Contains the blob hashes for eip-4844 transactions + fn blob_versioned_hashes(&self) -> Option>; + + /// EIP2930 access list + fn access_list(&self) -> Option; + + /// Transaction type + fn transaction_type(&self) -> Option; + + /// The signed authorization list + fn authorization_list(&self) -> Option>; } /// Header JSON-RPC response. @@ -152,10 +197,28 @@ pub trait BlockResponse { } impl TransactionResponse for WithOtherFields { + type Signature = T::Signature; + fn tx_hash(&self) -> TxHash { self.inner.tx_hash() } + fn nonce(&self) -> u64 { + self.inner.nonce() + } + + fn block_hash(&self) -> Option { + self.inner.block_hash() + } + + fn block_number(&self) -> Option { + self.inner.block_number() + } + + fn transaction_index(&self) -> Option { + self.inner.transaction_index() + } + fn from(&self) -> Address { self.inner.from() } @@ -168,13 +231,53 @@ impl TransactionResponse for WithOtherFields { self.inner.value() } + fn gas_price(&self) -> Option { + self.inner.gas_price() + } + fn gas(&self) -> u128 { self.inner.gas() } + fn max_fee_per_gas(&self) -> Option { + self.inner.max_fee_per_gas() + } + + fn max_priority_fee_per_gas(&self) -> Option { + self.inner.max_priority_fee_per_gas() + } + + fn max_fee_per_blob_gas(&self) -> Option { + self.inner.max_fee_per_blob_gas() + } + fn input(&self) -> &Bytes { self.inner.input() } + + fn signature(&self) -> Option { + self.inner.signature() + } + + fn chain_id(&self) -> Option { + self.inner.chain_id() + } + + fn blob_versioned_hashes(&self) -> Option> { + self.inner.blob_versioned_hashes() + } + + fn access_list(&self) -> Option { + self.inner.access_list() + } + + fn transaction_type(&self) -> Option { + self.inner.transaction_type() + } + + fn authorization_list(&self) -> Option> { + self.inner.authorization_list() + } } impl ReceiptResponse for WithOtherFields { diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 824f942f143..c1432f1d1da 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -339,10 +339,28 @@ impl TryFrom for TxEnvelope { } impl TransactionResponse for Transaction { + type Signature = Signature; + fn tx_hash(&self) -> B256 { self.hash } + fn nonce(&self) -> u64 { + self.nonce + } + + fn block_hash(&self) -> Option { + self.block_hash + } + + fn block_number(&self) -> Option { + self.block_number + } + + fn transaction_index(&self) -> Option { + self.transaction_index + } + fn from(&self) -> Address { self.from } @@ -355,14 +373,55 @@ impl TransactionResponse for Transaction { self.value } + fn gas_price(&self) -> Option { + self.gas_price + } + fn gas(&self) -> u128 { self.gas } + fn max_fee_per_gas(&self) -> Option { + self.max_fee_per_gas + } + + fn max_priority_fee_per_gas(&self) -> Option { + self.max_priority_fee_per_gas + } + + fn max_fee_per_blob_gas(&self) -> Option { + self.max_fee_per_blob_gas + } + fn input(&self) -> &Bytes { &self.input } + + fn signature(&self) -> Option { + self.signature + } + + fn chain_id(&self) -> Option { + self.chain_id + } + + fn blob_versioned_hashes(&self) -> Option> { + self.blob_versioned_hashes.clone() + } + + fn access_list(&self) -> Option { + self.access_list.clone() + } + + fn transaction_type(&self) -> Option { + self.transaction_type + } + + fn authorization_list(&self) -> Option> { + self.authorization_list.clone() + } } + #[cfg(test)] mod tests { use super::*;