From 4c268e65a083e43ec5a2b96b9c93819dedd97acf Mon Sep 17 00:00:00 2001 From: meowsbits Date: Wed, 22 Jul 2020 22:47:34 -0500 Subject: [PATCH] cmd/utils: implement configurable developer (--dev) account options (#21301) * geth,utils: implement configurable developer account options Prior to this change --dev (developer) mode generated one account with an empty password, irrespective of existing --password and --miner.etherbase options. This change makes --dev mode compatible with these existing flags. --dev mode may now be used in conjunction with --password and --miner.etherbase flags to configure the developer faucet using an existing keystore or in creating a new account. Signed-off-by: meows * main: remove key/pass flags from usage developer section These flags are included already in other sections, and it is not desired to duplicate them. They were originally included in this section along with added support for these flags in the developer mode. Signed-off-by: meows --- cmd/utils/flags.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d5414b771a..949e1a9e1b 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1612,18 +1612,28 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } // Create new developer account or reuse existing one var ( - developer accounts.Account - err error + developer accounts.Account + passphrase string + err error ) - if accs := ks.Accounts(); len(accs) > 0 { + if list := MakePasswordList(ctx); len(list) > 0 { + // Just take the first value. Although the function returns a possible multiple values and + // some usages iterate through them as attempts, that doesn't make sense in this setting, + // when we're definitely concerned with only one account. + passphrase = list[0] + } + // setEtherbase has been called above, configuring the miner address from command line flags. + if cfg.Miner.Etherbase != (common.Address{}) { + developer = accounts.Account{Address: cfg.Miner.Etherbase} + } else if accs := ks.Accounts(); len(accs) > 0 { developer = ks.Accounts()[0] } else { - developer, err = ks.NewAccount("") + developer, err = ks.NewAccount(passphrase) if err != nil { Fatalf("Failed to create developer account: %v", err) } } - if err := ks.Unlock(developer, ""); err != nil { + if err := ks.Unlock(developer, passphrase); err != nil { Fatalf("Failed to unlock developer account: %v", err) } log.Info("Using developer account", "address", developer.Address)