aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-13 21:03:16 +0800
committerGitHub <noreply@github.com>2017-02-13 21:03:16 +0800
commitf8f428cc18c5f70814d7b3937128781bac14bffd (patch)
treed93d285d2ec22bd8ed646695c3db116c69fa3329 /cmd/swarm
parente23e86921b55cb1ee2fca6b6fb9ed91f5532f9fd (diff)
parente99c788155ddd754c73d2c81b6051dcbd42e6575 (diff)
downloaddexon-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.gz
dexon-f8f428cc18c5f70814d7b3937128781bac14bffd.tar.zst
dexon-f8f428cc18c5f70814d7b3937128781bac14bffd.zip
Merge pull request #3592 from karalabe/hw-wallets
accounts: initial support for Ledger hardware wallets
Diffstat (limited to 'cmd/swarm')
-rw-r--r--cmd/swarm/main.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 7d76d55c1..14adc3b10 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -26,6 +26,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/accounts"
+ "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console"
@@ -336,29 +337,36 @@ func getAccount(ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
return key
}
// Otherwise try getting it from the keystore.
- return decryptStoreAccount(stack.AccountManager(), keyid)
+ am := stack.AccountManager()
+ ks := am.Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
+
+ return decryptStoreAccount(ks, keyid)
}
-func decryptStoreAccount(accman *accounts.Manager, account string) *ecdsa.PrivateKey {
+func decryptStoreAccount(ks *keystore.KeyStore, account string) *ecdsa.PrivateKey {
var a accounts.Account
var err error
if common.IsHexAddress(account) {
- a, err = accman.Find(accounts.Account{Address: common.HexToAddress(account)})
- } else if ix, ixerr := strconv.Atoi(account); ixerr == nil {
- a, err = accman.AccountByIndex(ix)
+ a, err = ks.Find(accounts.Account{Address: common.HexToAddress(account)})
+ } else if ix, ixerr := strconv.Atoi(account); ixerr == nil && ix > 0 {
+ if accounts := ks.Accounts(); len(accounts) > ix {
+ a = accounts[ix]
+ } else {
+ err = fmt.Errorf("index %d higher than number of accounts %d", ix, len(accounts))
+ }
} else {
utils.Fatalf("Can't find swarm account key %s", account)
}
if err != nil {
utils.Fatalf("Can't find swarm account key: %v", err)
}
- keyjson, err := ioutil.ReadFile(a.File)
+ keyjson, err := ioutil.ReadFile(a.URL.Path)
if err != nil {
utils.Fatalf("Can't load swarm account key: %v", err)
}
for i := 1; i <= 3; i++ {
passphrase := promptPassphrase(fmt.Sprintf("Unlocking swarm account %s [%d/3]", a.Address.Hex(), i))
- key, err := accounts.DecryptKey(keyjson, passphrase)
+ key, err := keystore.DecryptKey(keyjson, passphrase)
if err == nil {
return key.PrivateKey
}