Merge pull request #1046 from tgerring/issue1045
Allow unlocking multiple accounts
This commit is contained in:
commit
b14ee6ce16
|
@ -364,12 +364,20 @@ func execJSFiles(ctx *cli.Context) {
|
||||||
func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (passphrase string) {
|
func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (passphrase string) {
|
||||||
var err error
|
var err error
|
||||||
// Load startup keys. XXX we are going to need a different format
|
// 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 {
|
if len(account) == 0 {
|
||||||
utils.Fatalf("Invalid account address '%s'", account)
|
utils.Fatalf("Invalid account address '%s'", account)
|
||||||
}
|
}
|
||||||
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 {
|
if err != nil {
|
||||||
utils.Fatalf("Unlock account failed '%v'", err)
|
utils.Fatalf("Unlock account failed '%v'", err)
|
||||||
}
|
}
|
||||||
|
@ -384,15 +392,18 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
||||||
am := eth.AccountManager()
|
am := eth.AccountManager()
|
||||||
|
|
||||||
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
||||||
if len(account) > 0 {
|
accounts := strings.Split(account, " ")
|
||||||
if account == "primary" {
|
for _, account := range accounts {
|
||||||
primaryAcc, err := am.Primary()
|
if len(account) > 0 {
|
||||||
if err != nil {
|
if account == "primary" {
|
||||||
utils.Fatalf("no primary account: %v", err)
|
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.
|
// Start auxiliary services if enabled.
|
||||||
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
|
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
|
||||||
|
|
Loading…
Reference in New Issue