mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
cmd/utils: streamline developer account setup and unlocking logic
This commit is contained in:
parent
5ef338d5d6
commit
5abf406387
1 changed files with 13 additions and 10 deletions
|
|
@ -1726,25 +1726,28 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
|||
Fatalf("Keystore is not available")
|
||||
}
|
||||
|
||||
isKeystoreNonEmpty := len(ks.Accounts()) > 0
|
||||
// Figure out the dev account address.
|
||||
// setEtherbase has been called above, configuring the miner address from command line flags.
|
||||
if cfg.Miner.PendingFeeRecipient != (common.Address{}) {
|
||||
developer = accounts.Account{Address: cfg.Miner.PendingFeeRecipient}
|
||||
} else if isKeystoreNonEmpty {
|
||||
developer = ks.Accounts()[0]
|
||||
} else {
|
||||
if accs := ks.Accounts(); len(accs) > 0 {
|
||||
developer = ks.Accounts()[0]
|
||||
} else {
|
||||
developer, err = ks.NewAccount(passphrase)
|
||||
if err != nil {
|
||||
Fatalf("Failed to create developer account: %v", err)
|
||||
}
|
||||
developer, err = ks.NewAccount(passphrase)
|
||||
if err != nil {
|
||||
Fatalf("Failed to create developer account: %v", err)
|
||||
}
|
||||
}
|
||||
// Make sure the address is configured as fee recipient, otherwise
|
||||
// the miner will fail to start.
|
||||
cfg.Miner.PendingFeeRecipient = developer.Address
|
||||
|
||||
// try to unlock the first keystore account
|
||||
if isKeystoreNonEmpty {
|
||||
if err := ks.Unlock(developer, passphrase); err != nil {
|
||||
Fatalf("Failed to unlock developer account: %v", err)
|
||||
}
|
||||
// Make sure the address is configured as fee recipient, otherwise
|
||||
// the miner will fail to start.
|
||||
cfg.Miner.PendingFeeRecipient = developer.Address
|
||||
}
|
||||
log.Info("Using developer account", "address", developer.Address)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue