Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypony220 committed Jan 4, 2025
1 parent 2c94d7b commit e5cba66
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
7 changes: 7 additions & 0 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ where
type Transaction = Transaction;
type Error = OpEthApiError;

fn fill_pending(
&self,
tx: RecoveredTx<OpTransactionSigned>,
) -> Result<Self::Transaction, Self::Error> {
self.fill(tx, TransactionInfo::default())
}

fn fill(
&self,
tx: RecoveredTx<OpTransactionSigned>,
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -250,7 +250,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
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)?));
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/rpc/rpc-eth-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -47,7 +44,7 @@ impl<T: SignedTransaction> TransactionSource<T> {
resp_builder: &Builder,
) -> Result<Builder::Transaction, Builder::Error> {
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()),
Expand Down
12 changes: 3 additions & 9 deletions crates/rpc/rpc-types-compat/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ pub fn from_recovered_with_block_context<Tx, T: TransactionCompat<Tx>>(
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, T: TransactionCompat<Tx>>(
tx: RecoveredTx<Tx>,
resp_builder: &T,
) -> Result<T::Transaction, T::Error> {
resp_builder.fill(tx, TransactionInfo::default())
}

/// Builds RPC transaction w.r.t. network.
pub trait TransactionCompat<T = TransactionSigned>:
Send + Sync + Unpin + Clone + fmt::Debug
Expand All @@ -45,6 +36,9 @@ pub trait TransactionCompat<T = TransactionSigned>:
/// RPC transaction error type.
type Error: error::Error + Into<jsonrpsee_types::ErrorObject<'static>>;

/// Wrapper for `fill()` with default `TransactionInfo`
fn fill_pending(&self, tx: RecoveredTx<T>) -> Result<Self::Transaction, Self::Error>;

/// Create a new rpc transaction result for a _pending_ signed transaction, setting block
/// environment related fields to `None`.
fn fill(
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions crates/rpc/rpc/src/eth/helpers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ where

type Error = EthApiError;

fn fill_pending(
&self,
tx: RecoveredTx<TransactionSigned>,
) -> Result<Self::Transaction, Self::Error> {
self.fill(tx, TransactionInfo::default())
}

fn fill(
&self,
tx: RecoveredTx<TransactionSigned>,
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/rpc/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit e5cba66

Please sign in to comment.