From af8ada45e7d98527a21049e06a8bda307a083301 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 19 May 2015 13:40:41 -0500 Subject: [PATCH 1/2] Allow unlocking multiple accounts #1045 Separate accounts with spaces when using --unlock --- cmd/geth/main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index df0af3e79..28a558d68 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -364,11 +364,12 @@ func execJSFiles(ctx *cli.Context) { func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (passphrase string) { var err error // Load startup keys. XXX we are going to need a different format - // Attempt to unlock the account - passphrase = getPassPhrase(ctx, "", false) + if len(account) == 0 { utils.Fatalf("Invalid account address '%s'", account) } + // Attempt to unlock the account + passphrase = getPassPhrase(ctx, "Unlocking account "+account, false) err = am.Unlock(common.HexToAddress(account), passphrase) if err != nil { utils.Fatalf("Unlock account failed '%v'", err) @@ -384,15 +385,18 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) { am := eth.AccountManager() account := ctx.GlobalString(utils.UnlockedAccountFlag.Name) - if len(account) > 0 { - if account == "primary" { - primaryAcc, err := am.Primary() - if err != nil { - utils.Fatalf("no primary account: %v", err) + accounts := strings.Split(account, " ") + for _, account := range accounts { + if len(account) > 0 { + if account == "primary" { + primaryAcc, err := am.Primary() + if err != nil { + utils.Fatalf("no primary account: %v", err) + } + account = primaryAcc.Hex() } - account = primaryAcc.Hex() + unlockAccount(ctx, am, account) } - unlockAccount(ctx, am, account) } // Start auxiliary services if enabled. if ctx.GlobalBool(utils.RPCEnabledFlag.Name) { From 32b8565022d7d6ccb437769b5ed68121c5c34657 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 19 May 2015 14:46:32 -0500 Subject: [PATCH 2/2] Support multiple account unlock attempts --- cmd/geth/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 28a558d68..2afc92f10 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -368,9 +368,16 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass if len(account) == 0 { utils.Fatalf("Invalid account address '%s'", account) } - // Attempt to unlock the account - passphrase = getPassPhrase(ctx, "Unlocking account "+account, false) - err = am.Unlock(common.HexToAddress(account), passphrase) + // Attempt to unlock the account 3 times + attempts := 3 + for tries := 0; tries < attempts; tries++ { + msg := fmt.Sprintf("Unlocking account %s...%s | Attempt %d/%d", account[:8], account[len(account)-6:], tries+1, attempts) + passphrase = getPassPhrase(ctx, msg, false) + err = am.Unlock(common.HexToAddress(account), passphrase) + if err == nil { + break + } + } if err != nil { utils.Fatalf("Unlock account failed '%v'", err) }