diff --git a/crates/optimism/rpc/src/eth/transaction.rs b/crates/optimism/rpc/src/eth/transaction.rs index 05fbb0a95349..99fe19d7527c 100644 --- a/crates/optimism/rpc/src/eth/transaction.rs +++ b/crates/optimism/rpc/src/eth/transaction.rs @@ -82,6 +82,13 @@ where type Transaction = Transaction; type Error = OpEthApiError; + fn fill_pending( + &self, + tx: RecoveredTx, + ) -> Result { + self.fill(tx, TransactionInfo::default()) + } + fn fill( &self, tx: RecoveredTx, diff --git a/crates/rpc/rpc-eth-api/src/helpers/transaction.rs b/crates/rpc/rpc-eth-api/src/helpers/transaction.rs index 6096cb3579ff..75f538618287 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/transaction.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/transaction.rs @@ -21,7 +21,7 @@ use reth_provider::{ TransactionsProvider, }; use reth_rpc_eth_types::{utils::binary_search, EthApiError, SignError, TransactionSource}; -use reth_rpc_types_compat::transaction::{from_recovered, from_recovered_with_block_context}; +use reth_rpc_types_compat::transaction::{from_recovered_with_block_context, TransactionCompat}; use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool}; use std::sync::Arc; @@ -250,7 +250,7 @@ pub trait EthTransactions: LoadTransaction { RpcNodeCore::pool(self).get_transaction_by_sender_and_nonce(sender, nonce) { let transaction = tx.transaction.clone_into_consensus(); - return Ok(Some(from_recovered(transaction, self.tx_resp_builder())?)); + return Ok(Some(self.tx_resp_builder().fill_pending(transaction)?)); } } diff --git a/crates/rpc/rpc-eth-types/src/transaction.rs b/crates/rpc/rpc-eth-types/src/transaction.rs index f994638d3af8..79fa92973332 100644 --- a/crates/rpc/rpc-eth-types/src/transaction.rs +++ b/crates/rpc/rpc-eth-types/src/transaction.rs @@ -6,10 +6,7 @@ use alloy_primitives::B256; use alloy_rpc_types_eth::TransactionInfo; use reth_primitives::{RecoveredTx, TransactionSigned}; use reth_primitives_traits::SignedTransaction; -use reth_rpc_types_compat::{ - transaction::{from_recovered, from_recovered_with_block_context}, - TransactionCompat, -}; +use reth_rpc_types_compat::{transaction::from_recovered_with_block_context, TransactionCompat}; /// Represents from where a transaction was fetched. #[derive(Debug, Clone, Eq, PartialEq)] @@ -47,7 +44,7 @@ impl TransactionSource { resp_builder: &Builder, ) -> Result { match self { - Self::Pool(tx) => from_recovered(tx, resp_builder), + Self::Pool(tx) => resp_builder.fill_pending(tx), Self::Block { transaction, index, block_hash, block_number, base_fee } => { let tx_info = TransactionInfo { hash: Some(transaction.trie_hash()), diff --git a/crates/rpc/rpc-types-compat/src/transaction.rs b/crates/rpc/rpc-types-compat/src/transaction.rs index b5515ce9e23d..943b49df7b66 100644 --- a/crates/rpc/rpc-types-compat/src/transaction.rs +++ b/crates/rpc/rpc-types-compat/src/transaction.rs @@ -20,15 +20,6 @@ pub fn from_recovered_with_block_context>( resp_builder.fill(tx, tx_info) } -/// Create a new rpc transaction result for a _pending_ signed transaction, setting block -/// environment related fields to `None`. -pub fn from_recovered>( - tx: RecoveredTx, - resp_builder: &T, -) -> Result { - resp_builder.fill(tx, TransactionInfo::default()) -} - /// Builds RPC transaction w.r.t. network. pub trait TransactionCompat: Send + Sync + Unpin + Clone + fmt::Debug @@ -45,6 +36,9 @@ pub trait TransactionCompat: /// RPC transaction error type. type Error: error::Error + Into>; + /// Wrapper for `fill()` with default `TransactionInfo` + fn fill_pending(&self, tx: RecoveredTx) -> Result; + /// Create a new rpc transaction result for a _pending_ signed transaction, setting block /// environment related fields to `None`. fn fill( diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index 6441db70459a..337fbb91e06d 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -23,7 +23,6 @@ use reth_rpc_eth_types::{ EthApiError, EthFilterConfig, EthStateCache, EthSubscriptionIdProvider, }; use reth_rpc_server_types::{result::rpc_error_with_code, ToRpcResult}; -use reth_rpc_types_compat::transaction::from_recovered; use reth_tasks::TaskSpawner; use reth_transaction_pool::{NewSubpoolTransactionStream, PoolTransaction, TransactionPool}; use std::{ @@ -637,7 +636,7 @@ where let mut prepared_stream = self.txs_stream.lock().await; while let Ok(tx) = prepared_stream.try_recv() { - match from_recovered(tx.transaction.to_consensus(), &self.tx_resp_builder) { + match self.tx_resp_builder.fill_pending(tx.transaction.to_consensus()) { Ok(tx) => pending_txs.push(tx), Err(err) => { error!(target: "rpc", diff --git a/crates/rpc/rpc/src/eth/helpers/types.rs b/crates/rpc/rpc/src/eth/helpers/types.rs index 82bb5877f755..8147352df83c 100644 --- a/crates/rpc/rpc/src/eth/helpers/types.rs +++ b/crates/rpc/rpc/src/eth/helpers/types.rs @@ -37,6 +37,13 @@ where type Error = EthApiError; + fn fill_pending( + &self, + tx: RecoveredTx, + ) -> Result { + self.fill(tx, TransactionInfo::default()) + } + fn fill( &self, tx: RecoveredTx, diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index fc02b0da0671..c38028a33e2e 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -19,7 +19,6 @@ use reth_rpc_eth_api::{ }; use reth_rpc_eth_types::logs_utils; use reth_rpc_server_types::result::{internal_rpc_err, invalid_params_rpc_err}; -use reth_rpc_types_compat::transaction::from_recovered; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use reth_transaction_pool::{NewTransactionEvent, PoolConsensusTx, TransactionPool}; use serde::Serialize; @@ -119,10 +118,11 @@ where Params::Bool(true) => { // full transaction objects requested let stream = pubsub.full_pending_transaction_stream().filter_map(|tx| { - let tx_value = match from_recovered( - tx.transaction.to_consensus(), - pubsub.eth_api.tx_resp_builder(), - ) { + let tx_value = match pubsub + .eth_api + .tx_resp_builder() + .fill_pending(tx.transaction.to_consensus()) + { Ok(tx) => Some(tx), Err(err) => { error!(target = "rpc", diff --git a/crates/rpc/rpc/src/txpool.rs b/crates/rpc/rpc/src/txpool.rs index a8d783406773..dc5f214b5642 100644 --- a/crates/rpc/rpc/src/txpool.rs +++ b/crates/rpc/rpc/src/txpool.rs @@ -9,7 +9,7 @@ use alloy_rpc_types_txpool::{ use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_rpc_api::TxPoolApiServer; -use reth_rpc_types_compat::{transaction::from_recovered, TransactionCompat}; +use reth_rpc_types_compat::TransactionCompat; use reth_transaction_pool::{ AllPoolTransactions, PoolConsensusTx, PoolTransaction, TransactionPool, }; @@ -50,7 +50,7 @@ where { content.entry(tx.sender()).or_default().insert( tx.nonce().to_string(), - from_recovered(tx.clone_into_consensus(), resp_builder)?, + resp_builder.fill_pending(tx.clone_into_consensus())?, ); Ok(())