aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-24 17:49:20 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-02-13 20:00:02 +0800
commit833e4d1319336fbb66fd8f1e473c24472d65b17b (patch)
tree74d45d86d0c59c19f0ff67831f04e0cad9776eef /cmd/utils
parent564b60520c68a1f06171abd705c01946b932492f (diff)
downloaddexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar.gz
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar.bz2
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar.lz
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar.xz
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.tar.zst
dexon-833e4d1319336fbb66fd8f1e473c24472d65b17b.zip
accounts, cmd, eth, internal, mobile, node: split account backends
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/flags.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 9ba33df80..1196a64b5 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -30,6 +30,7 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
+ "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
@@ -587,23 +588,27 @@ func MakeDatabaseHandles() int {
// MakeAddress converts an account specified directly as a hex encoded string or
// a key index in the key store to an internal account representation.
-func MakeAddress(accman *accounts.Manager, account string) (accounts.Account, error) {
+func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error) {
// If the specified account is a valid address, return it
if common.IsHexAddress(account) {
return accounts.Account{Address: common.HexToAddress(account)}, nil
}
// Otherwise try to interpret the account as a keystore index
index, err := strconv.Atoi(account)
- if err != nil {
+ if err != nil || index < 0 {
return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account)
}
- return accman.AccountByIndex(index)
+ accs := ks.Accounts()
+ if len(accs) <= index {
+ return accounts.Account{}, fmt.Errorf("index %d higher than number of accounts %d", index, len(accs))
+ }
+ return accs[index], nil
}
// MakeEtherbase retrieves the etherbase either from the directly specified
// command line flags or from the keystore if CLI indexed.
-func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address {
- accounts := accman.Accounts()
+func MakeEtherbase(ks *keystore.KeyStore, ctx *cli.Context) common.Address {
+ accounts := ks.Accounts()
if !ctx.GlobalIsSet(EtherbaseFlag.Name) && len(accounts) == 0 {
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
return common.Address{}
@@ -613,7 +618,7 @@ func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address {
return common.Address{}
}
// If the specified etherbase is a valid address, return it
- account, err := MakeAddress(accman, etherbase)
+ account, err := MakeAddress(ks, etherbase)
if err != nil {
Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
}
@@ -721,9 +726,10 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
if networks > 1 {
Fatalf("The %v flags are mutually exclusive", netFlags)
}
+ ks := stack.AccountManager().Backend(keystore.BackendType).(*keystore.KeyStore)
ethConf := &eth.Config{
- Etherbase: MakeEtherbase(stack.AccountManager(), ctx),
+ Etherbase: MakeEtherbase(ks, ctx),
ChainConfig: MakeChainConfig(ctx, stack),
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
LightMode: ctx.GlobalBool(LightModeFlag.Name),