From 9d61cf8130c1795bc3b9dff4c8de19a855e2d071 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 23 Jun 2025 15:45:38 +0300 Subject: [PATCH] chore: simplify `RpcConverter` (#17002) --- crates/optimism/rpc/src/eth/mod.rs | 10 +++----- .../rpc/rpc-types-compat/src/transaction.rs | 24 +++++++++---------- crates/rpc/rpc/src/eth/helpers/types.rs | 3 +-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 7d37873a4d..d4e8205068 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -65,10 +65,8 @@ impl OpNodeCore for T where T: RpcNodeCore {} pub struct OpEthApi { /// Gateway to node's core components. inner: Arc>, - /// Marker for the network types. - _nt: PhantomData, - tx_resp_builder: - RpcConverter>, + /// Converter for RPC types. + tx_resp_builder: RpcConverter>, } impl OpEthApi { @@ -82,7 +80,6 @@ impl OpEthApi { Arc::new(OpEthApiInner { eth_api, sequencer_client, min_suggested_priority_fee }); Self { inner: inner.clone(), - _nt: PhantomData, tx_resp_builder: RpcConverter::with_mapper(OpTxInfoMapper::new(inner)), } } @@ -120,8 +117,7 @@ where { type Error = OpEthApiError; type NetworkTypes = NetworkT; - type TransactionCompat = - RpcConverter>; + type TransactionCompat = RpcConverter>; fn tx_resp_builder(&self) -> &Self::TransactionCompat { &self.tx_resp_builder diff --git a/crates/rpc/rpc-types-compat/src/transaction.rs b/crates/rpc/rpc-types-compat/src/transaction.rs index 88a0d1eb7a..98421e68a8 100644 --- a/crates/rpc/rpc-types-compat/src/transaction.rs +++ b/crates/rpc/rpc-types-compat/src/transaction.rs @@ -303,60 +303,60 @@ pub struct TransactionConversionError(String); /// Generic RPC response object converter for primitives `N` and network `E`. #[derive(Debug)] -pub struct RpcConverter { - phantom: PhantomData<(N, E, Evm, Err)>, +pub struct RpcConverter { + phantom: PhantomData<(E, Evm, Err)>, mapper: Map, } -impl RpcConverter { +impl RpcConverter { /// Creates a new [`RpcConverter`] with the default mapper. pub const fn new() -> Self { Self::with_mapper(()) } } -impl RpcConverter { +impl RpcConverter { /// Creates a new [`RpcConverter`] with `mapper`. pub const fn with_mapper(mapper: Map) -> Self { Self { phantom: PhantomData, mapper } } /// Converts the generic types. - pub fn convert(self) -> RpcConverter { + pub fn convert(self) -> RpcConverter { RpcConverter::with_mapper(self.mapper) } /// Swaps the inner `mapper`. - pub fn map(self, mapper: Map2) -> RpcConverter { + pub fn map(self, mapper: Map2) -> RpcConverter { RpcConverter::with_mapper(mapper) } /// Converts the generic types and swaps the inner `mapper`. - pub fn convert_map( + pub fn convert_map( self, mapper: Map2, - ) -> RpcConverter { + ) -> RpcConverter { self.convert().map(mapper) } } -impl Clone for RpcConverter { +impl Clone for RpcConverter { fn clone(&self) -> Self { Self::with_mapper(self.mapper.clone()) } } -impl Default for RpcConverter { +impl Default for RpcConverter { fn default() -> Self { Self::new() } } -impl TransactionCompat for RpcConverter +impl TransactionCompat for RpcConverter where N: NodePrimitives, E: RpcTypes + Send + Sync + Unpin + Clone + Debug, - Evm: ConfigureEvm, + Evm: ConfigureEvm, TxTy: IntoRpcTx + Clone + Debug, TransactionRequest: TryIntoSimTx> + TryIntoTxEnv>, Err: From diff --git a/crates/rpc/rpc/src/eth/helpers/types.rs b/crates/rpc/rpc/src/eth/helpers/types.rs index 22300b37be..2e043b22a6 100644 --- a/crates/rpc/rpc/src/eth/helpers/types.rs +++ b/crates/rpc/rpc/src/eth/helpers/types.rs @@ -1,13 +1,12 @@ //! L1 `eth` API types. use alloy_network::Ethereum; -use reth_ethereum_primitives::EthPrimitives; use reth_evm_ethereum::EthEvmConfig; use reth_rpc_eth_types::EthApiError; use reth_rpc_types_compat::RpcConverter; /// An [`RpcConverter`] with its generics set to Ethereum specific. -pub type EthRpcConverter = RpcConverter; +pub type EthRpcConverter = RpcConverter; //tests for simulate #[cfg(test)]