diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-13 21:03:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-13 21:03:16 +0800 |
commit | f8f428cc18c5f70814d7b3937128781bac14bffd (patch) | |
tree | d93d285d2ec22bd8ed646695c3db116c69fa3329 /cmd/utils/flags.go | |
parent | e23e86921b55cb1ee2fca6b6fb9ed91f5532f9fd (diff) | |
parent | e99c788155ddd754c73d2c81b6051dcbd42e6575 (diff) | |
download | go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.gz go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.bz2 go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.lz go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.xz go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.zst go-tangerine-f8f428cc18c5f70814d7b3937128781bac14bffd.zip |
Merge pull request #3592 from karalabe/hw-wallets
accounts: initial support for Ledger hardware wallets
Diffstat (limited to 'cmd/utils/flags.go')
-rw-r--r-- | cmd/utils/flags.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9ba33df80..92eb05e32 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().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) ethConf := ð.Config{ - Etherbase: MakeEtherbase(stack.AccountManager(), ctx), + Etherbase: MakeEtherbase(ks, ctx), ChainConfig: MakeChainConfig(ctx, stack), FastSync: ctx.GlobalBool(FastSyncFlag.Name), LightMode: ctx.GlobalBool(LightModeFlag.Name), |