aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/accountcmd.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-04-02 00:10:58 +0800
committerFelix Lange <fjl@twurst.com>2016-04-12 21:59:18 +0800
commit91aaddaeb38ff25118896fb436a938d14636760b (patch)
tree4cdf271558b1038a83426c4489988fc4a6954851 /cmd/geth/accountcmd.go
parentea005a02950513603b7346ef39bc76dc53b82863 (diff)
downloadgo-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar.gz
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar.bz2
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar.lz
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar.xz
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.tar.zst
go-tangerine-91aaddaeb38ff25118896fb436a938d14636760b.zip
cmd/geth: add recovery procedure for AmbiguousAddrError
Diffstat (limited to 'cmd/geth/accountcmd.go')
-rw-r--r--cmd/geth/accountcmd.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go
index 86175d05f..0bd60d701 100644
--- a/cmd/geth/accountcmd.go
+++ b/cmd/geth/accountcmd.go
@@ -181,10 +181,19 @@ func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i
for trials := 0; trials < 3; trials++ {
prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
password := getPassPhrase(prompt, false, i, passwords)
- if err = accman.Unlock(account, password); err == nil {
+ err = accman.Unlock(account, password)
+ if err == nil {
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
return account, password
}
+ if err, ok := err.(*accounts.AmbiguousAddrError); ok {
+ glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
+ return ambiguousAddrRecovery(accman, err, password), password
+ }
+ if err != accounts.ErrDecrypt {
+ // No need to prompt again if the error is not decryption-related.
+ break
+ }
}
// All trials expended to unlock account, bail out
utils.Fatalf("Failed to unlock account %s (%v)", address, err)
@@ -221,6 +230,32 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string)
return password
}
+func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrError, auth string) accounts.Account {
+ fmt.Printf("Multiple key files exist for address %x:\n", err.Addr)
+ for _, a := range err.Matches {
+ fmt.Println(" ", a.File)
+ }
+ fmt.Println("Testing your passphrase against all of them...")
+ var match *accounts.Account
+ for _, a := range err.Matches {
+ if err := am.Unlock(a, auth); err == nil {
+ match = &a
+ break
+ }
+ }
+ if match == nil {
+ utils.Fatalf("None of the listed files could be unlocked.")
+ }
+ fmt.Printf("Your passphrase unlocked %s\n", match.File)
+ fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
+ for _, a := range err.Matches {
+ if a != *match {
+ fmt.Println(" ", a.File)
+ }
+ }
+ return *match
+}
+
// accountCreate creates a new account into the keystore defined by the CLI flags.
func accountCreate(ctx *cli.Context) {
accman := utils.MakeAccountManager(ctx)