@@ -518,47 +518,41 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
518518
519519// MakeAddress converts an account specified directly as a hex encoded string or
520520// a key index in the key store to an internal account representation.
521- func MakeAddress (accman * accounts.Manager , account string ) common.Address {
521+ func MakeAddress (accman * accounts.Manager , account string ) ( a common.Address , err error ) {
522522 // If the specified account is a valid address, return it
523523 if common .IsHexAddress (account ) {
524- return common .HexToAddress (account )
524+ return common .HexToAddress (account ), nil
525525 }
526526 // Otherwise try to interpret the account as a keystore index
527527 index , err := strconv .Atoi (account )
528528 if err != nil {
529- Fatalf ( "Invalid account address or index: '%s' " , account )
529+ return a , fmt . Errorf ( "invalid account address or index %q " , account )
530530 }
531531 hex , err := accman .AddressByIndex (index )
532532 if err != nil {
533- Fatalf ( "Failed to retrieve requested account #%d: %v " , index , err )
533+ return a , fmt . Errorf ( "can't get account #%d (%v) " , index , err )
534534 }
535- return common .HexToAddress (hex )
535+ return common .HexToAddress (hex ), nil
536536}
537537
538538// MakeEtherbase retrieves the etherbase either from the directly specified
539539// command line flags or from the keystore if CLI indexed.
540540func MakeEtherbase (accman * accounts.Manager , ctx * cli.Context ) common.Address {
541- // If the specified etherbase is a valid address, return it
542- etherbase := ctx .GlobalString (EtherbaseFlag .Name )
543- if common .IsHexAddress (etherbase ) {
544- return common .HexToAddress (etherbase )
545- }
546- // If no etherbase was specified and no accounts are known, bail out
547541 accounts , _ := accman .Accounts ()
548- if etherbase == "" && len (accounts ) == 0 {
542+ if ! ctx . GlobalIsSet ( EtherbaseFlag . Name ) && len (accounts ) == 0 {
549543 glog .V (logger .Error ).Infoln ("WARNING: No etherbase set and no accounts found as default" )
550544 return common.Address {}
551545 }
552- // Otherwise try to interpret the parameter as a keystore index
553- index , err := strconv .Atoi (etherbase )
554- if err != nil {
555- Fatalf ("Invalid account address or index: '%s'" , etherbase )
546+ etherbase := ctx .GlobalString (EtherbaseFlag .Name )
547+ if etherbase == "" {
548+ return common.Address {}
556549 }
557- hex , err := accman .AddressByIndex (index )
550+ // If the specified etherbase is a valid address, return it
551+ addr , err := MakeAddress (accman , etherbase )
558552 if err != nil {
559- Fatalf ("Failed to set requested account #%d as etherbase : %v" , index , err )
553+ Fatalf ("Option %q : %v" , EtherbaseFlag . Name , err )
560554 }
561- return common . HexToAddress ( hex )
555+ return addr
562556}
563557
564558// MakeMinerExtra resolves extradata for the miner from the set command line flags
0 commit comments