11//! Scroll-Reth `eth_` endpoint implementation.
22
33use alloy_primitives:: U256 ;
4+ use eyre:: WrapErr ;
45use reth_chainspec:: { EthChainSpec , EthereumHardforks } ;
56use reth_evm:: ConfigureEvm ;
67use reth_network_api:: NetworkInfo ;
@@ -40,6 +41,8 @@ mod pending_block;
4041pub mod receipt;
4142pub mod transaction;
4243
44+ use crate :: SequencerClient ;
45+
4346/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
4447pub type EthApiNodeBackend < N > = EthApiInner <
4548 <N as RpcNodeCore >:: Provider ,
@@ -73,8 +76,8 @@ pub struct ScrollEthApi<N: ScrollNodeCore, NetworkT = Scroll> {
7376
7477impl < N : ScrollNodeCore , NetworkT > ScrollEthApi < N , NetworkT > {
7578 /// Creates a new [`ScrollEthApi`].
76- pub fn new ( eth_api : EthApiNodeBackend < N > ) -> Self {
77- let inner = Arc :: new ( ScrollEthApiInner { eth_api } ) ;
79+ pub fn new ( eth_api : EthApiNodeBackend < N > , sequencer_client : Option < SequencerClient > ) -> Self {
80+ let inner = Arc :: new ( ScrollEthApiInner { eth_api, sequencer_client } ) ;
7881 Self {
7982 inner : inner. clone ( ) ,
8083 _nt : PhantomData ,
@@ -98,6 +101,11 @@ where
98101 self . inner . eth_api ( )
99102 }
100103
104+ /// Returns the configured sequencer client, if any.
105+ pub fn sequencer_client ( & self ) -> Option < & SequencerClient > {
106+ self . inner . sequencer_client ( )
107+ }
108+
101109 /// Return a builder for the [`ScrollEthApi`].
102110 pub const fn builder ( ) -> ScrollEthApiBuilder {
103111 ScrollEthApiBuilder :: new ( )
@@ -307,23 +315,41 @@ impl<N: ScrollNodeCore, NetworkT> fmt::Debug for ScrollEthApi<N, NetworkT> {
307315pub struct ScrollEthApiInner < N : ScrollNodeCore > {
308316 /// Gateway to node's core components.
309317 pub eth_api : EthApiNodeBackend < N > ,
318+ /// Sequencer client, configured to forward submitted transactions to sequencer of given Scroll
319+ /// network.
320+ sequencer_client : Option < SequencerClient > ,
310321}
311322
312323impl < N : ScrollNodeCore > ScrollEthApiInner < N > {
313324 /// Returns a reference to the [`EthApiNodeBackend`].
314325 const fn eth_api ( & self ) -> & EthApiNodeBackend < N > {
315326 & self . eth_api
316327 }
328+
329+ /// Returns the configured sequencer client, if any.
330+ const fn sequencer_client ( & self ) -> Option < & SequencerClient > {
331+ self . sequencer_client . as_ref ( )
332+ }
317333}
318334
319335/// A type that knows how to build a [`ScrollEthApi`].
320336#[ derive( Debug , Default ) ]
321- pub struct ScrollEthApiBuilder { }
337+ pub struct ScrollEthApiBuilder {
338+ /// Sequencer client, configured to forward submitted transactions to sequencer of given Scroll
339+ /// network.
340+ sequencer_url : Option < String > ,
341+ }
322342
323343impl ScrollEthApiBuilder {
324344 /// Creates a [`ScrollEthApiBuilder`] instance.
325345 pub const fn new ( ) -> Self {
326- Self { }
346+ Self { sequencer_url : None }
347+ }
348+
349+ /// With a [`SequencerClient`].
350+ pub fn with_sequencer ( mut self , sequencer_url : Option < String > ) -> Self {
351+ self . sequencer_url = sequencer_url;
352+ self
327353 }
328354}
329355
@@ -335,6 +361,7 @@ where
335361 type EthApi = ScrollEthApi < N > ;
336362
337363 async fn build_eth_api ( self , ctx : EthApiCtx < ' _ , N > ) -> eyre:: Result < Self :: EthApi > {
364+ let Self { sequencer_url } = self ;
338365 let eth_api = reth_rpc:: EthApiBuilder :: new (
339366 ctx. components . provider ( ) . clone ( ) ,
340367 ctx. components . pool ( ) . clone ( ) ,
@@ -350,6 +377,16 @@ where
350377 . proof_permits ( ctx. config . proof_permits )
351378 . build_inner ( ) ;
352379
353- Ok ( ScrollEthApi :: new ( eth_api) )
380+ let sequencer_client = if let Some ( url) = sequencer_url {
381+ Some (
382+ SequencerClient :: new ( & url)
383+ . await
384+ . wrap_err_with ( || "Failed to init sequencer client with: {url}" ) ?,
385+ )
386+ } else {
387+ None
388+ } ;
389+
390+ Ok ( ScrollEthApi :: new ( eth_api, sequencer_client) )
354391 }
355392}
0 commit comments