mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
cmd/geth: remove account indexing by number
This commit is contained in:
parent
f7088ba00c
commit
e1a7cc7aff
2 changed files with 7 additions and 32 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue