@@ -22,6 +22,8 @@ import (
22
22
"github.com/ava-labs/avalanchego/utils/logging"
23
23
"github.com/spf13/cobra"
24
24
"go.uber.org/zap"
25
+
26
+ avagoConstants "github.com/ava-labs/avalanchego/utils/constants"
25
27
)
26
28
27
29
func init () {
@@ -91,22 +93,25 @@ func NewCommand() *cobra.Command {
91
93
}
92
94
93
95
var (
94
- avalancheGoBinPath string
95
- numNodes uint32
96
- pluginDir string
97
- globalNodeConfig string
98
- addNodeConfig string
99
- blockchainSpecsStr string
100
- customNodeConfigs string
101
- rootDataDir string
102
- chainConfigs string
103
- upgradeConfigs string
104
- subnetConfigs string
105
- reassignPortsIfUsed bool
106
- dynamicPorts bool
107
- networkID uint32
108
- force bool
109
- inPlace bool
96
+ avalancheGoBinPath string
97
+ numNodes uint32
98
+ pluginDir string
99
+ globalNodeConfig string
100
+ addNodeConfig string
101
+ blockchainSpecsStr string
102
+ customNodeConfigs string
103
+ rootDataDir string
104
+ chainConfigs string
105
+ upgradeConfigs string
106
+ subnetConfigs string
107
+ reassignPortsIfUsed bool
108
+ dynamicPorts bool
109
+ networkID uint32
110
+ force bool
111
+ inPlace bool
112
+ fuji bool
113
+ walletPrivateKey string
114
+ walletPrivateKeyPath string
110
115
)
111
116
112
117
func setLogs () error {
@@ -191,6 +196,12 @@ func newStartCommand() *cobra.Command {
191
196
constants .DefaultNumNodes ,
192
197
"number of nodes of the network" ,
193
198
)
199
+ cmd .PersistentFlags ().Uint32Var (
200
+ & numNodes ,
201
+ "num-nodes" ,
202
+ constants .DefaultNumNodes ,
203
+ "number of nodes of the network" ,
204
+ )
194
205
cmd .PersistentFlags ().StringVar (
195
206
& pluginDir ,
196
207
"plugin-dir" ,
@@ -257,16 +268,63 @@ func newStartCommand() *cobra.Command {
257
268
false ,
258
269
"true to assign dynamic ports" ,
259
270
)
271
+ cmd .PersistentFlags ().BoolVar (
272
+ & fuji ,
273
+ "fuji" ,
274
+ false ,
275
+ "true to set all nodes to join fuji network" ,
276
+ )
277
+ cmd .PersistentFlags ().StringVar (
278
+ & walletPrivateKey ,
279
+ "wallet-private-key" ,
280
+ "" ,
281
+ "[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern." ,
282
+ )
283
+ cmd .PersistentFlags ().StringVar (
284
+ & walletPrivateKeyPath ,
285
+ "wallet-private-key-path" ,
286
+ "" ,
287
+ "[optional] funding wallet private key path" ,
288
+ )
260
289
return cmd
261
290
}
262
291
292
+ func setWalletPrivateKeyOptions (opts * []client.OpOption ) error {
293
+ if walletPrivateKeyPath != "" && walletPrivateKey != "" {
294
+ return fmt .Errorf ("only one of wallet-private-key and wallet-private-key-path can be provided" )
295
+ }
296
+ if walletPrivateKey != "" {
297
+ ux .Print (log , logging .Yellow .Wrap ("funding wallet private key provided: %s" ), walletPrivateKey )
298
+ * opts = append (* opts , client .WithWalletPrivateKey (walletPrivateKey ))
299
+ }
300
+ if walletPrivateKeyPath != "" {
301
+ ux .Print (log , logging .Yellow .Wrap ("funding wallet private key path provided: %s" ), walletPrivateKeyPath )
302
+ // validate if it's a valid private key
303
+ if _ , err := os .Stat (walletPrivateKey ); err != nil {
304
+ return fmt .Errorf ("wallet private key doesn't exist: %w" , err )
305
+ }
306
+ // read the private key
307
+ keyBytes , err := os .ReadFile (walletPrivateKey )
308
+ if err != nil {
309
+ return fmt .Errorf ("failed to read wallet private key: %w" , err )
310
+ }
311
+ * opts = append (* opts , client .WithWalletPrivateKey (string (keyBytes )))
312
+ }
313
+ return nil
314
+ }
315
+
263
316
func startFunc (* cobra.Command , []string ) error {
264
317
cli , err := newClient ()
265
318
if err != nil {
266
319
return err
267
320
}
268
321
defer cli .Close ()
269
322
323
+ if fuji {
324
+ networkID = avagoConstants .FujiID
325
+ requestTimeout = 5 * time .Hour // increase timeout for fuji network
326
+ ux .Print (log , logging .Yellow .Wrap ("setting request timeout to " + requestTimeout .String ()))
327
+ }
270
328
opts := []client.OpOption {
271
329
client .WithNumNodes (numNodes ),
272
330
client .WithPluginDir (pluginDir ),
@@ -277,6 +335,10 @@ func startFunc(*cobra.Command, []string) error {
277
335
client .WithNetworkID (networkID ),
278
336
}
279
337
338
+ if err := setWalletPrivateKeyOptions (& opts ); err != nil {
339
+ return err
340
+ }
341
+
280
342
if globalNodeConfig != "" {
281
343
ux .Print (log , logging .Yellow .Wrap ("global node config provided, will be applied to all nodes: %s" ), globalNodeConfig )
282
344
// validate it's valid JSON
@@ -1288,6 +1350,18 @@ func newLoadSnapshotCommand() *cobra.Command {
1288
1350
false ,
1289
1351
"load snapshot in place, so as it always auto save" ,
1290
1352
)
1353
+ cmd .PersistentFlags ().StringVar (
1354
+ & walletPrivateKey ,
1355
+ "wallet-private-key" ,
1356
+ "" ,
1357
+ "[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern." ,
1358
+ )
1359
+ cmd .PersistentFlags ().StringVar (
1360
+ & walletPrivateKeyPath ,
1361
+ "wallet-private-key-path" ,
1362
+ "" ,
1363
+ "[optional] funding wallet private key path" ,
1364
+ )
1291
1365
return cmd
1292
1366
}
1293
1367
@@ -1305,6 +1379,10 @@ func loadSnapshotFunc(_ *cobra.Command, args []string) error {
1305
1379
client .WithReassignPortsIfUsed (reassignPortsIfUsed ),
1306
1380
}
1307
1381
1382
+ if err := setWalletPrivateKeyOptions (& opts ); err != nil {
1383
+ return err
1384
+ }
1385
+
1308
1386
if chainConfigs != "" {
1309
1387
chainConfigsMap := make (map [string ]string )
1310
1388
if err := json .Unmarshal ([]byte (chainConfigs ), & chainConfigsMap ); err != nil {
0 commit comments