mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(rpc): make TransactionCompat::fill stateful (#11732)
This commit is contained in:
@ -56,7 +56,7 @@ serde_json.workspace = true
|
||||
# misc
|
||||
thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
derive_more.workspace = true
|
||||
derive_more = { workspace = true, features = ["constructor", "deref"] }
|
||||
|
||||
[dev-dependencies]
|
||||
reth-optimism-chainspec.workspace = true
|
||||
|
||||
@ -39,7 +39,7 @@ use reth_tasks::{
|
||||
};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
use crate::{OpEthApiError, OpTxBuilder, SequencerClient};
|
||||
use crate::{OpEthApiError, SequencerClient};
|
||||
|
||||
/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
|
||||
pub type EthApiNodeBackend<N> = EthApiInner<
|
||||
@ -59,7 +59,7 @@ pub type EthApiNodeBackend<N> = EthApiInner<
|
||||
///
|
||||
/// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented
|
||||
/// all the `Eth` helper traits and prerequisite traits.
|
||||
#[derive(Clone, Deref)]
|
||||
#[derive(Deref)]
|
||||
pub struct OpEthApi<N: FullNodeComponents> {
|
||||
/// Gateway to node's core components.
|
||||
#[deref]
|
||||
@ -102,7 +102,11 @@ where
|
||||
{
|
||||
type Error = OpEthApiError;
|
||||
type NetworkTypes = Optimism;
|
||||
type TransactionCompat = OpTxBuilder;
|
||||
type TransactionCompat = Self;
|
||||
|
||||
fn tx_resp_builder(&self) -> &Self::TransactionCompat {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EthApiSpec for OpEthApi<N>
|
||||
@ -249,3 +253,12 @@ impl<N: FullNodeComponents> fmt::Debug for OpEthApi<N> {
|
||||
f.debug_struct("OpEthApi").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Clone for OpEthApi<N>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self { inner: self.inner.clone(), sequencer_client: self.sequencer_client.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ use alloy_rpc_types::TransactionInfo;
|
||||
use op_alloy_rpc_types::Transaction;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_primitives::TransactionSignedEcRecovered;
|
||||
use reth_provider::{BlockReaderIdExt, TransactionsProvider};
|
||||
use reth_provider::{BlockReaderIdExt, ReceiptProvider, TransactionsProvider};
|
||||
use reth_rpc::eth::EthTxBuilder;
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
|
||||
@ -88,22 +88,34 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds OP transaction response type.
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct OpTxBuilder;
|
||||
|
||||
impl TransactionCompat for OpTxBuilder {
|
||||
impl<N> TransactionCompat for OpEthApi<N>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
type Transaction = Transaction;
|
||||
|
||||
fn fill(tx: TransactionSignedEcRecovered, tx_info: TransactionInfo) -> Self::Transaction {
|
||||
fn fill(
|
||||
&self,
|
||||
tx: TransactionSignedEcRecovered,
|
||||
tx_info: TransactionInfo,
|
||||
) -> Self::Transaction {
|
||||
let signed_tx = tx.clone().into_signed();
|
||||
let hash = tx.hash;
|
||||
|
||||
let mut inner = EthTxBuilder::fill(tx, tx_info).inner;
|
||||
let mut inner = EthTxBuilder.fill(tx, tx_info).inner;
|
||||
|
||||
if signed_tx.is_deposit() {
|
||||
inner.gas_price = Some(signed_tx.max_fee_per_gas())
|
||||
}
|
||||
|
||||
let deposit_receipt_version = self
|
||||
.inner
|
||||
.provider()
|
||||
.receipt_by_hash(hash)
|
||||
.ok() // todo: change sig to return result
|
||||
.flatten()
|
||||
.and_then(|receipt| receipt.deposit_receipt_version);
|
||||
|
||||
Transaction {
|
||||
inner,
|
||||
source_hash: signed_tx.source_hash(),
|
||||
@ -111,7 +123,7 @@ impl TransactionCompat for OpTxBuilder {
|
||||
// only include is_system_tx if true: <https://github.com/ethereum-optimism/op-geth/blob/641e996a2dcf1f81bac9416cb6124f86a69f1de7/internal/ethapi/api.go#L1518-L1518>
|
||||
is_system_tx: (signed_tx.is_deposit() && signed_tx.is_system_transaction())
|
||||
.then_some(true),
|
||||
deposit_receipt_version: None, // todo: how to fill this field?
|
||||
deposit_receipt_version,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,5 +15,5 @@ pub mod eth;
|
||||
pub mod sequencer;
|
||||
|
||||
pub use error::{OpEthApiError, OptimismInvalidTransactionError, SequencerClientError};
|
||||
pub use eth::{transaction::OpTxBuilder, OpEthApi, OpReceiptBuilder};
|
||||
pub use eth::{OpEthApi, OpReceiptBuilder};
|
||||
pub use sequencer::SequencerClient;
|
||||
|
||||
Reference in New Issue
Block a user