From 6772ed8c1e661991c8751c19d1f4c235476088fa Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Wed, 21 May 2025 17:49:51 +0200 Subject: [PATCH] feat: relax OpEthApi type constraints (#16398) --- crates/optimism/rpc/src/eth/mod.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 58278c8537..f2f636cb42 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -37,7 +37,7 @@ use reth_tasks::{ TaskSpawner, }; use reth_transaction_pool::TransactionPool; -use std::{fmt, sync::Arc}; +use std::{fmt, marker::PhantomData, sync::Arc}; use crate::{OpEthApiError, SequencerClient}; @@ -64,12 +64,21 @@ impl OpNodeCore for T where T: RpcNodeCore {} /// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented /// all the `Eth` helper traits and prerequisite traits. #[derive(Clone)] -pub struct OpEthApi { +pub struct OpEthApi { /// Gateway to node's core components. inner: Arc>, + /// Marker for the network types. + _nt: PhantomData, } -impl OpEthApi +impl OpEthApi { + /// Creates a new `OpEthApi`. + pub fn new(eth_api: EthApiNodeBackend, sequencer_client: Option) -> Self { + Self { inner: Arc::new(OpEthApiInner { eth_api, sequencer_client }), _nt: PhantomData } + } +} + +impl OpEthApi where N: OpNodeCore< Provider: BlockReaderIdExt @@ -95,13 +104,14 @@ where } } -impl EthApiTypes for OpEthApi +impl EthApiTypes for OpEthApi where - Self: Send + Sync, + Self: Send + Sync + std::fmt::Debug, N: OpNodeCore, + NetworkT: op_alloy_network::Network + Clone + std::fmt::Debug, { type Error = OpEthApiError; - type NetworkTypes = Optimism; + type NetworkTypes = NetworkT; type TransactionCompat = Self; fn tx_resp_builder(&self) -> &Self::TransactionCompat { @@ -113,7 +123,7 @@ impl RpcNodeCore for OpEthApi where N: OpNodeCore, { - type Primitives = OpPrimitives; + type Primitives = N::Primitives; type Provider = N::Provider; type Pool = N::Pool; type Evm = ::Evm; @@ -353,6 +363,6 @@ where None }; - Ok(OpEthApi { inner: Arc::new(OpEthApiInner { eth_api, sequencer_client }) }) + Ok(OpEthApi::new(eth_api, sequencer_client)) } }