@@ -2,6 +2,7 @@ package celestia
22
33import (
44 "encoding/hex"
5+ "errors"
56 "fmt"
67 "net/url"
78 "os"
@@ -25,6 +26,8 @@ const (
2526const (
2627 // RPCFlagName defines the flag for the rpc url
2728 RPCFlagName = "da.rpc"
29+ // TLSEnabledFlagName defines the flag for whether rpc TLS is enabled
30+ TLSEnabledFlagName = "da.tls-enabled"
2831 // AuthTokenFlagName defines the flag for the auth token
2932 AuthTokenFlagName = "da.auth_token"
3033 // NamespaceFlagName defines the flag for the namespace
@@ -36,6 +39,14 @@ const (
3639 // GasPriceFlagName defines the flag for gas price
3740 GasPriceFlagName = "da.gas_price"
3841
42+ // tx client config flags
43+ DefaultKeyNameFlagName = "da.tx-client.key-name"
44+ KeyringPathFlagName = "da.tx-client.keyring-path"
45+ CoreGRPCAddrFlagName = "da.tx-client.core-grpc.addr"
46+ CoreGRPCTLSEnabledFlagName = "da.tx-client.core-grpc.tls-enabled"
47+ CoreGRPCAuthTokenFlagName = "da.tx-client.core-grpc.auth-token"
48+ P2PNetworkFlagName = "da.tx-client.p2p-network"
49+
3950 // NamespaceSize is the size of the hex encoded namespace string
4051 NamespaceSize = 58
4152
@@ -54,6 +65,12 @@ func CLIFlags(envPrefix string) []cli.Flag {
5465 Value : defaultRPC ,
5566 EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_RPC" ),
5667 },
68+ & cli.BoolFlag {
69+ Name : TLSEnabledFlagName ,
70+ Usage : "enable TLS for the data availability rpc client" ,
71+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TLS_ENABLED" ),
72+ Value : true ,
73+ },
5774 & cli.StringFlag {
5875 Name : AuthTokenFlagName ,
5976 Usage : "authentication token of the data availability client" ,
@@ -93,25 +110,97 @@ func CLIFlags(envPrefix string) []cli.Flag {
93110 Value : defaultGasPrice ,
94111 EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_GAS_PRICE" ),
95112 },
113+ & cli.StringFlag {
114+ Name : DefaultKeyNameFlagName ,
115+ Usage : "celestia tx client key name" ,
116+ Value : "my_celes_key" ,
117+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_KEY_NAME" ),
118+ },
119+ & cli.StringFlag {
120+ Name : KeyringPathFlagName ,
121+ Usage : "celestia tx client keyring path e.g. ~/.celestia-light-mocha-4/keys" ,
122+ Value : "" ,
123+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_KEYRING_PATH" ),
124+ },
125+ & cli.StringFlag {
126+ Name : CoreGRPCAddrFlagName ,
127+ Usage : "celestia tx client core grpc addr" ,
128+ Value : "http://localhost:9090" ,
129+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_CORE_GRPC_ADDR" ),
130+ },
131+ & cli.BoolFlag {
132+ Name : CoreGRPCTLSEnabledFlagName ,
133+ Usage : "celestia tx client core grpc TLS" ,
134+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_CORE_GRPC_TLS_ENABLED" ),
135+ Value : true ,
136+ },
137+ & cli.StringFlag {
138+ Name : CoreGRPCAuthTokenFlagName ,
139+ Usage : "celestia tx client core grpc auth token" ,
140+ Value : "" ,
141+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_CORE_GRPC_AUTH_TOKEN" ),
142+ },
143+ & cli.StringFlag {
144+ Name : P2PNetworkFlagName ,
145+ Usage : "celestia tx client p2p network" ,
146+ Value : "mocha-4" ,
147+ EnvVars : opservice .PrefixEnvVar (envPrefix , "DA_TX_CLIENT_P2P_NETWORK" ),
148+ },
96149 }
97150}
98151
99152type CLIConfig struct {
100- Rpc string
101- AuthToken string
102- Namespace string
103- FallbackMode string
104- GasPrice float64
153+ Rpc string
154+ TLSEnabled bool
155+ AuthToken string
156+ Namespace string
157+ FallbackMode string
158+ GasPrice float64
159+ TxClientConfig TxClientConfig
160+ }
161+
162+ func (c CLIConfig ) TxClientEnabled () bool {
163+ return (c .TxClientConfig .KeyringPath != "" || c .TxClientConfig .CoreGRPCAuthToken != "" )
105164}
106165
107166func (c CLIConfig ) IsEnabled () bool {
108167 return c .Rpc != "" && c .AuthToken != "" && c .Namespace != ""
109168}
110169
170+ func (c CLIConfig ) CelestiaConfig () RPCClientConfig {
171+ ns , _ := hex .DecodeString (c .Namespace )
172+ var cfg * TxClientConfig
173+ if c .TxClientEnabled () {
174+ cfg = & c .TxClientConfig
175+ }
176+ return RPCClientConfig {
177+ URL : c .Rpc ,
178+ TLSEnabled : c .TLSEnabled ,
179+ AuthToken : c .AuthToken ,
180+ Namespace : ns ,
181+ TxClientConfig : cfg ,
182+ }
183+ }
184+
111185func (c CLIConfig ) Check () error {
112186 if ! c .IsEnabled () {
113187 return nil
114188 }
189+ if c .TxClientEnabled () {
190+ // If tx client is enabled, ensure tx client flags are set
191+ if c .TxClientConfig .DefaultKeyName == "" {
192+ return errors .New ("--da.tx-client.key-name must be set" )
193+ }
194+ if c .TxClientConfig .KeyringPath == "" {
195+ return errors .New ("--da.tx-client.keyring-path must be set" )
196+ }
197+ if c .TxClientConfig .CoreGRPCAddr == "" {
198+ return errors .New ("--da.tx-client.core-grpc.addr must be set" )
199+ }
200+ if c .TxClientConfig .P2PNetwork == "" {
201+ return errors .New ("--da.tx-client.p2p-network must be set" )
202+ }
203+ }
115204 if _ , err := url .Parse (c .Rpc ); err != nil {
116205 return fmt .Errorf ("rpc url is invalid: %w" , err )
117206 }
@@ -130,10 +219,19 @@ func NewCLIConfig() CLIConfig {
130219func ReadCLIConfig (ctx * cli.Context ) CLIConfig {
131220 return CLIConfig {
132221 Rpc : ctx .String (RPCFlagName ),
222+ TLSEnabled : ctx .Bool (TLSEnabledFlagName ),
133223 AuthToken : ctx .String (AuthTokenFlagName ),
134224 Namespace : ctx .String (NamespaceFlagName ),
135225 FallbackMode : ctx .String (FallbackModeFlagName ),
136226 GasPrice : ctx .Float64 (GasPriceFlagName ),
227+ TxClientConfig : TxClientConfig {
228+ DefaultKeyName : ctx .String (DefaultKeyNameFlagName ),
229+ KeyringPath : ctx .String (KeyringPathFlagName ),
230+ CoreGRPCAddr : ctx .String (CoreGRPCAddrFlagName ),
231+ CoreGRPCTLSEnabled : ctx .Bool (CoreGRPCTLSEnabledFlagName ),
232+ CoreGRPCAuthToken : ctx .String (CoreGRPCAuthTokenFlagName ),
233+ P2PNetwork : ctx .String (P2PNetworkFlagName ),
234+ },
137235 }
138236}
139237
@@ -173,5 +271,24 @@ func ReadCLIConfigFromEnv(envPrefix string) CLIConfig {
173271 }
174272 }
175273
274+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_KEY_NAME" ); value != "" {
275+ result .TxClientConfig .DefaultKeyName = value
276+ }
277+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_KEYRING_PATH" ); value != "" {
278+ result .TxClientConfig .KeyringPath = value
279+ }
280+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_CORE_GRPC_ADDR" ); value != "" {
281+ result .TxClientConfig .CoreGRPCAddr = value
282+ }
283+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_CORE_GRPC_TLS_ENABLED" ); value != "" {
284+ result .TxClientConfig .CoreGRPCTLSEnabled = value == "true"
285+ }
286+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_CORE_GRPC_AUTH_TOKEN" ); value != "" {
287+ result .TxClientConfig .CoreGRPCAuthToken = value
288+ }
289+ if value := os .Getenv (envPrefix + "_" + "DA_TX_CLIENT_P2P_NETWORK" ); value != "" {
290+ result .TxClientConfig .P2PNetwork = value
291+ }
292+
176293 return result
177294}
0 commit comments