@@ -289,6 +289,30 @@ func newStartCommand() *cobra.Command {
289
289
return cmd
290
290
}
291
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
+
292
316
func startFunc (* cobra.Command , []string ) error {
293
317
cli , err := newClient ()
294
318
if err != nil {
@@ -309,25 +333,8 @@ func startFunc(*cobra.Command, []string) error {
309
333
client .WithNetworkID (networkID ),
310
334
}
311
335
312
- if walletPrivateKeyPath != "" && walletPrivateKey != "" {
313
- return fmt .Errorf ("only one of wallet-private-key and wallet-private-key-path can be provided" )
314
- }
315
- if walletPrivateKey != "" {
316
- ux .Print (log , logging .Yellow .Wrap ("funding wallet private key provided: %s" ), walletPrivateKey )
317
- opts = append (opts , client .WithWalletPrivateKey (walletPrivateKey ))
318
- }
319
- if walletPrivateKeyPath != "" {
320
- ux .Print (log , logging .Yellow .Wrap ("funding wallet private key path provided: %s" ), walletPrivateKeyPath )
321
- // validate if it's a valid private key
322
- if _ , err := os .Stat (walletPrivateKey ); err != nil {
323
- return fmt .Errorf ("wallet private key doesn't exist: %w" , err )
324
- }
325
- // read the private key
326
- keyBytes , err := os .ReadFile (walletPrivateKey )
327
- if err != nil {
328
- return fmt .Errorf ("failed to read wallet private key: %w" , err )
329
- }
330
- opts = append (opts , client .WithWalletPrivateKey (string (keyBytes )))
336
+ if err := setWalletPrivateKeyOptions (& opts ); err != nil {
337
+ return err
331
338
}
332
339
333
340
if globalNodeConfig != "" {
@@ -1341,6 +1348,18 @@ func newLoadSnapshotCommand() *cobra.Command {
1341
1348
false ,
1342
1349
"load snapshot in place, so as it always auto save" ,
1343
1350
)
1351
+ cmd .PersistentFlags ().StringVar (
1352
+ & walletPrivateKey ,
1353
+ "wallet-private-key" ,
1354
+ "" ,
1355
+ "[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern." ,
1356
+ )
1357
+ cmd .PersistentFlags ().StringVar (
1358
+ & walletPrivateKeyPath ,
1359
+ "wallet-private-key-path" ,
1360
+ "" ,
1361
+ "[optional] funding wallet private key path" ,
1362
+ )
1344
1363
return cmd
1345
1364
}
1346
1365
@@ -1358,6 +1377,10 @@ func loadSnapshotFunc(_ *cobra.Command, args []string) error {
1358
1377
client .WithReassignPortsIfUsed (reassignPortsIfUsed ),
1359
1378
}
1360
1379
1380
+ if err := setWalletPrivateKeyOptions (& opts ); err != nil {
1381
+ return err
1382
+ }
1383
+
1361
1384
if chainConfigs != "" {
1362
1385
chainConfigsMap := make (map [string ]string )
1363
1386
if err := json .Unmarshal ([]byte (chainConfigs ), & chainConfigsMap ); err != nil {
0 commit comments