diff options
Diffstat (limited to 'cmd/geth/accountcmd.go')
-rw-r--r-- | cmd/geth/accountcmd.go | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index cd398eadb..b7c411e82 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -19,14 +19,14 @@ package main import ( "fmt" "io/ioutil" + "os" "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/console" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "gopkg.in/urfave/cli.v1" ) @@ -196,18 +196,19 @@ func accountList(ctx *cli.Context) error { func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i int, passwords []string) (accounts.Account, string) { account, err := utils.MakeAddress(ks, address) if err != nil { - utils.Fatalf("Could not list accounts: %v", err) + fmt.Printf("Fatal: Could not list accounts: %v\n", err) + os.Exit(1) } 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) err = ks.Unlock(account, password) if err == nil { - glog.V(logger.Info).Infof("Unlocked account %x", account.Address) + log.Info(fmt.Sprintf("Unlocked account %x", account.Address)) return account, password } if err, ok := err.(*keystore.AmbiguousAddrError); ok { - glog.V(logger.Info).Infof("Unlocked account %x", account.Address) + log.Info(fmt.Sprintf("Unlocked account %x", account.Address)) return ambiguousAddrRecovery(ks, err, password), password } if err != keystore.ErrDecrypt { @@ -216,7 +217,9 @@ func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i in } } // All trials expended to unlock account, bail out - utils.Fatalf("Failed to unlock account %s (%v)", address, err) + fmt.Printf("Fatal: Failed to unlock account %s (%v)\n", address, err) + os.Exit(1) + return accounts.Account{}, "" } @@ -236,15 +239,18 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string) } password, err := console.Stdin.PromptPassword("Passphrase: ") if err != nil { - utils.Fatalf("Failed to read passphrase: %v", err) + fmt.Printf("Fatal: Failed to read passphrase: %v\n", err) + os.Exit(1) } if confirmation { confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ") if err != nil { - utils.Fatalf("Failed to read passphrase confirmation: %v", err) + fmt.Printf("Fatal: Failed to read passphrase confirmation: %v\n", err) + os.Exit(1) } if password != confirm { - utils.Fatalf("Passphrases do not match") + fmt.Printf("Fatal: Passphrases do not match\n") + os.Exit(1) } } return password @@ -264,7 +270,8 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr } } if match == nil { - utils.Fatalf("None of the listed files could be unlocked.") + fmt.Printf("Fatal: None of the listed files could be unlocked.\n") + os.Exit(1) } fmt.Printf("Your passphrase unlocked %s\n", match.URL) fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:") @@ -284,7 +291,8 @@ func accountCreate(ctx *cli.Context) error { ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) account, err := ks.NewAccount(password) if err != nil { - utils.Fatalf("Failed to create account: %v", err) + fmt.Printf("Fatal: Failed to create account: %v\n", err) + os.Exit(1) } fmt.Printf("Address: {%x}\n", account.Address) return nil @@ -294,7 +302,8 @@ func accountCreate(ctx *cli.Context) error { // one, also providing the possibility to change the pass-phrase. func accountUpdate(ctx *cli.Context) error { if len(ctx.Args()) == 0 { - utils.Fatalf("No accounts specified to update") + fmt.Printf("Fatal: No accounts specified to update\n") + os.Exit(1) } stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) @@ -302,7 +311,8 @@ func accountUpdate(ctx *cli.Context) error { account, oldPassword := unlockAccount(ctx, ks, ctx.Args().First(), 0, nil) newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil) if err := ks.Update(account, oldPassword, newPassword); err != nil { - utils.Fatalf("Could not update the account: %v", err) + fmt.Printf("Fatal: Could not update the account: %v\n", err) + os.Exit(1) } return nil } @@ -310,11 +320,13 @@ func accountUpdate(ctx *cli.Context) error { func importWallet(ctx *cli.Context) error { keyfile := ctx.Args().First() if len(keyfile) == 0 { - utils.Fatalf("keyfile must be given as argument") + fmt.Printf("Fatal: keyfile must be given as argument\n") + os.Exit(1) } keyJson, err := ioutil.ReadFile(keyfile) if err != nil { - utils.Fatalf("Could not read wallet file: %v", err) + fmt.Printf("Fatal: Could not read wallet file: %v\n", err) + os.Exit(1) } stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) @@ -323,7 +335,8 @@ func importWallet(ctx *cli.Context) error { ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) acct, err := ks.ImportPreSaleKey(keyJson, passphrase) if err != nil { - utils.Fatalf("%v", err) + fmt.Printf("Fatal: %v\n", err) + os.Exit(1) } fmt.Printf("Address: {%x}\n", acct.Address) return nil @@ -332,11 +345,13 @@ func importWallet(ctx *cli.Context) error { func accountImport(ctx *cli.Context) error { keyfile := ctx.Args().First() if len(keyfile) == 0 { - utils.Fatalf("keyfile must be given as argument") + fmt.Printf("Fatal: keyfile must be given as argument\n") + os.Exit(1) } key, err := crypto.LoadECDSA(keyfile) if err != nil { - utils.Fatalf("Failed to load the private key: %v", err) + fmt.Printf("Fatal: Failed to load the private key: %v\n", err) + os.Exit(1) } stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) @@ -344,7 +359,8 @@ func accountImport(ctx *cli.Context) error { ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) acct, err := ks.ImportECDSA(key, passphrase) if err != nil { - utils.Fatalf("Could not create the account: %v", err) + fmt.Printf("Fatal: Could not create the account: %v\n", err) + os.Exit(1) } fmt.Printf("Address: {%x}\n", acct.Address) return nil |