Skip to content

Commit ee04b71

Browse files
committed
cmd/geth, cmd/utils: changed ParamsToAddress to return error
ParamsToAddress no longer aborts the process, it now returns an error instead so that the caller can handle the error properly.
1 parent 4b5c99d commit ee04b71

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

cmd/geth/main.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,20 @@ func execJSFiles(ctx *cli.Context) {
458458

459459
func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
460460
var err error
461-
addrHex = utils.ParamToAddress(addr, am)
462-
// Attempt to unlock the account 3 times
463-
attempts := 3
464-
for tries := 0; tries < attempts; tries++ {
465-
msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
466-
auth = getPassPhrase(ctx, msg, false, i)
467-
err = am.Unlock(common.HexToAddress(addrHex), auth)
468-
if err == nil {
469-
break
461+
addrHex, err = utils.ParamToAddress(addr, am)
462+
if err == nil {
463+
// Attempt to unlock the account 3 times
464+
attempts := 3
465+
for tries := 0; tries < attempts; tries++ {
466+
msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
467+
auth = getPassPhrase(ctx, msg, false, i)
468+
err = am.Unlock(common.HexToAddress(addrHex), auth)
469+
if err == nil {
470+
break
471+
}
470472
}
471473
}
474+
472475
if err != nil {
473476
utils.Fatalf("Unlock account failed '%v'", err)
474477
}

cmd/utils/flags.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
369369
clientID += "/" + customName
370370
}
371371
am := MakeAccountManager(ctx)
372+
etherbase, err := ParamToAddress(ctx.GlobalString(EtherbaseFlag.Name), am)
373+
if err != nil {
374+
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
375+
}
372376

373377
return &eth.Config{
374378
Name: common.MakeName(clientID, version),
@@ -380,7 +384,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
380384
LogFile: ctx.GlobalString(LogFileFlag.Name),
381385
Verbosity: ctx.GlobalInt(VerbosityFlag.Name),
382386
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
383-
Etherbase: common.HexToAddress(ParamToAddress(ctx.GlobalString(EtherbaseFlag.Name), am)),
387+
Etherbase: common.HexToAddress(etherbase),
384388
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
385389
AccountManager: am,
386390
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
@@ -508,7 +512,7 @@ func StartPProf(ctx *cli.Context) {
508512
}()
509513
}
510514

511-
func ParamToAddress(addr string, am *accounts.Manager) (addrHex string) {
515+
func ParamToAddress(addr string, am *accounts.Manager) (addrHex string, err error) {
512516
if !((len(addr) == 40) || (len(addr) == 42)) { // with or without 0x
513517
index, err := strconv.Atoi(addr)
514518
if err != nil {
@@ -517,7 +521,7 @@ func ParamToAddress(addr string, am *accounts.Manager) (addrHex string) {
517521

518522
addrHex, err = am.AddressByIndex(index)
519523
if err != nil {
520-
Fatalf("%v", err)
524+
return "", err
521525
}
522526
} else {
523527
addrHex = addr

0 commit comments

Comments
 (0)