From e1a7cc7aff16421db062d5b3db41b70a5b37f279 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 6 Nov 2024 15:26:39 +0100 Subject: [PATCH] cmd/geth: remove account indexing by number --- cmd/geth/accountcmd.go | 14 +++++++------- cmd/utils/flags.go | 25 ------------------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 3e0f5f8908..c6d2a2f678 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/urfave/cli/v2" ) @@ -294,10 +295,10 @@ func accountUpdate(ctx *cli.Context) error { ks := backends[0].(*keystore.KeyStore) for _, addr := range ctx.Args().Slice() { - account, err := utils.MakeAddress(ks, addr) - if err != nil { - return fmt.Errorf("could not locate account: %w", err) + if !common.IsHexAddress(addr) { + return errors.New("address must be specified in hexadecimal form") } + account := accounts.Account{Address: common.HexToAddress(addr)} newPassword := utils.GetPassPhrase("Please give a NEW password. Do not forget this password.", true) updateFn := func(attempt int) error { prompt := fmt.Sprintf("Please provide the OLD password for account %s | Attempt %d/%d", addr, attempt+1, 3) @@ -305,10 +306,9 @@ func accountUpdate(ctx *cli.Context) error { return ks.Update(account, password, newPassword) } // let user attempt unlock thrice. - for attempts := 0; attempts < 3; attempts++ { - if err = updateFn(attempts); !errors.Is(err, keystore.ErrDecrypt) { - break // nil or some other type of error - } + err := updateFn(0) + for attempts := 1; attempts < 3 && errors.Is(err, keystore.ErrDecrypt); attempts++ { + err = updateFn(attempts) } if err != nil { return fmt.Errorf("could not update account: %w", err) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index dbc07c6034..3561e60369 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1260,31 +1260,6 @@ func MakeDatabaseHandles(max int) int { return int(raised / 2) // Leave half for networking and other stuff } -// MakeAddress converts an account specified directly as a hex encoded string or -// a key index in the key store to an internal account representation. -func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error) { - // If the specified account is a valid address, return it - if common.IsHexAddress(account) { - return accounts.Account{Address: common.HexToAddress(account)}, nil - } - // Otherwise try to interpret the account as a keystore index - index, err := strconv.Atoi(account) - if err != nil || index < 0 { - return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account) - } - log.Warn("-------------------------------------------------------------------") - log.Warn("Referring to accounts by order in the keystore folder is dangerous!") - log.Warn("This functionality is deprecated and will be removed in the future!") - log.Warn("Please use explicit addresses! (can search via `geth account list`)") - log.Warn("-------------------------------------------------------------------") - - accs := ks.Accounts() - if len(accs) <= index { - return accounts.Account{}, fmt.Errorf("index %d higher than number of accounts %d", index, len(accs)) - } - return accs[index], nil -} - // setEtherbase retrieves the etherbase from the directly specified command line flags. func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) { if ctx.IsSet(MinerEtherbaseFlag.Name) {