From f931c12150206dbd758fd382b1866707e0960ca4 Mon Sep 17 00:00:00 2001 From: islishude Date: Wed, 12 Mar 2025 20:20:39 +0800 Subject: [PATCH] cmd/utils: simplify developer account selection and unlocking logic --- cmd/utils/flags.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index abb6fc43c8..bf422d11d5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1726,12 +1726,11 @@ 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 { + } else if accs := ks.Accounts(); len(accs) > 0 { developer = ks.Accounts()[0] } else { developer, err = ks.NewAccount(passphrase) @@ -1744,7 +1743,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.Miner.PendingFeeRecipient = developer.Address // try to unlock the first keystore account - if isKeystoreNonEmpty { + if len(ks.Accounts()) > 0 { if err := ks.Unlock(developer, passphrase); err != nil { Fatalf("Failed to unlock developer account: %v", err) }