@@ -8,7 +8,12 @@ import (
88
99 "github.com/ethereum/go-ethereum/common"
1010 "github.com/ethereum/go-ethereum/crypto"
11+ "github.com/ethereum/go-ethereum/ethclient"
12+ "github.com/ethereum/go-ethereum/log"
1113 "github.com/urfave/cli/v2"
14+
15+ espressoClient "github.com/EspressoSystems/espresso-network/sdks/go/client"
16+ espressoLightClient "github.com/EspressoSystems/espresso-network/sdks/go/light-client"
1217)
1318
1419// espressoFlags returns the flag names for espresso
2833 LightClientAddrFlagName = espressoFlags ("light-client-addr" )
2934 L1UrlFlagName = espressoFlags ("l1-url" )
3035 TestingBatcherPrivateKeyFlagName = espressoFlags ("testing-batcher-private-key" )
36+ OriginHeight = espressoFlags ("origin-height" )
37+ NamespaceFlagName = espressoFlags ("namespace" )
38+ RollupL1UrlFlagName = espressoFlags ("rollup-l1-url" )
3139)
3240
3341func CLIFlags (envPrefix string , category string ) []cli.Flag {
@@ -77,6 +85,24 @@ func CLIFlags(envPrefix string, category string) []cli.Flag {
7785 EnvVars : espressoEnvs (envPrefix , "TESTING_BATCHER_PRIVATE_KEY" ),
7886 Category : category ,
7987 },
88+ & cli.Uint64Flag {
89+ Name : OriginHeight ,
90+ Usage : "Espresso transactions below this height will not be considered" ,
91+ EnvVars : espressoEnvs (envPrefix , "ORIGIN_HEIGHT" ),
92+ Category : category ,
93+ },
94+ & cli.Uint64Flag {
95+ Name : NamespaceFlagName ,
96+ Usage : "Namespace of Espresso transactions" ,
97+ EnvVars : espressoEnvs (envPrefix , "NAMESPACE" ),
98+ Category : category ,
99+ },
100+ & cli.StringFlag {
101+ Name : RollupL1UrlFlagName ,
102+ Usage : "RPC URL of L1 backing the Rollup we're streaming for" ,
103+ EnvVars : espressoEnvs (envPrefix , "ROLLUP_L1_URL" ),
104+ Category : category ,
105+ },
80106 }
81107}
82108
@@ -87,7 +113,10 @@ type CLIConfig struct {
87113 QueryServiceURLs []string
88114 LightClientAddr common.Address
89115 L1URL string
116+ RollupL1URL string
90117 TestingBatcherPrivateKey * ecdsa.PrivateKey
118+ Namespace uint64
119+ OriginHeight uint64
91120}
92121
93122func (c CLIConfig ) Check () error {
@@ -102,6 +131,12 @@ func (c CLIConfig) Check() error {
102131 if c .L1URL == "" {
103132 return fmt .Errorf ("L1 URL is required when Espresso is enabled" )
104133 }
134+ if c .RollupL1URL == "" {
135+ return fmt .Errorf ("rollup L1 URL is required when Espresso is enabled" )
136+ }
137+ if c .Namespace == 0 {
138+ return fmt .Errorf ("namespace is required when Espresso is enabled" )
139+ }
105140 }
106141 return nil
107142}
@@ -112,6 +147,9 @@ func ReadCLIConfig(c *cli.Context) CLIConfig {
112147 PollInterval : c .Duration (PollIntervalFlagName ),
113148 UseFetchAPI : c .Bool (UseFetchApiFlagName ),
114149 L1URL : c .String (L1UrlFlagName ),
150+ RollupL1URL : c .String (RollupL1UrlFlagName ),
151+ Namespace : c .Uint64 (NamespaceFlagName ),
152+ OriginHeight : c .Uint64 (OriginHeight ),
115153 }
116154
117155 config .QueryServiceURLs = c .StringSlice (QueryServiceUrlsFlagName )
@@ -128,3 +166,48 @@ func ReadCLIConfig(c *cli.Context) CLIConfig {
128166
129167 return config
130168}
169+
170+ func BatchStreamerFromCLIConfig [B Batch ](
171+ cfg CLIConfig ,
172+ log log.Logger ,
173+ unmarshalBatch func ([]byte ) (* B , error ),
174+ ) (* BatchStreamer [B ], error ) {
175+ if ! cfg .Enabled {
176+ return nil , fmt .Errorf ("Espresso is not enabled" )
177+ }
178+
179+ l1Client , err := ethclient .Dial (cfg .L1URL )
180+ if err != nil {
181+ return nil , fmt .Errorf ("failed to dial L1 RPC at %s: %w" , cfg .L1URL , err )
182+ }
183+
184+ RollupL1Client , err := ethclient .Dial (cfg .RollupL1URL )
185+ if err != nil {
186+ return nil , fmt .Errorf ("failed to dial Rollup L1 RPC at %s: %w" , cfg .RollupL1URL , err )
187+ }
188+
189+ espressoClient , err := espressoClient .NewMultipleNodesClient (cfg .QueryServiceURLs )
190+ if err != nil {
191+ return nil , fmt .Errorf ("failed to create Espresso client: %w" , err )
192+ }
193+
194+ espressoLightClient , err := espressoLightClient .NewLightclientCaller (cfg .LightClientAddr , l1Client )
195+ if err != nil {
196+ return nil , fmt .Errorf ("failed to create Espresso light client" )
197+ }
198+
199+ streamer := NewEspressoStreamer (
200+ cfg .Namespace ,
201+ NewAdaptL1BlockRefClient (l1Client ),
202+ NewAdaptL1BlockRefClient (RollupL1Client ),
203+ espressoClient ,
204+ espressoLightClient ,
205+ log ,
206+ unmarshalBatch ,
207+ cfg .PollInterval ,
208+ cfg .OriginHeight ,
209+ )
210+ streamer .UseFetchApi = cfg .UseFetchAPI
211+
212+ return streamer , nil
213+ }
0 commit comments