aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/usbwallet/ledger_wallet.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-23 22:49:05 +0800
committerGitHub <noreply@github.com>2017-02-23 22:49:05 +0800
commit357732a8404c9fe4d02f041d20a0d05381a3e6d1 (patch)
treeedaf8a63eb7f7434cd9b9cbd764b3c4c3d76191e /accounts/usbwallet/ledger_wallet.go
parent29fac7de448c85049a97cbec3dc0819122bd2cb0 (diff)
parentf89dd627760b43bd405cb3db1e5efdb100835db5 (diff)
downloadgo-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.gz
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.bz2
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.lz
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.xz
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.zst
go-tangerine-357732a8404c9fe4d02f041d20a0d05381a3e6d1.zip
Merge pull request #3696 from karalabe/contextual-logger
Contextual logger
Diffstat (limited to 'accounts/usbwallet/ledger_wallet.go')
-rw-r--r--accounts/usbwallet/ledger_wallet.go35
1 files changed, 17 insertions, 18 deletions
diff --git a/accounts/usbwallet/ledger_wallet.go b/accounts/usbwallet/ledger_wallet.go
index 235086d1e..6086660f9 100644
--- a/accounts/usbwallet/ledger_wallet.go
+++ b/accounts/usbwallet/ledger_wallet.go
@@ -33,9 +33,9 @@ import (
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/karalabe/hid"
"golang.org/x/net/context"
@@ -123,6 +123,8 @@ type ledgerWallet struct {
// must only ever hold a *read* lock to stateLock.
commsLock chan struct{} // Mutex (buf=1) for the USB comms without keeping the state locked
stateLock sync.RWMutex // Protects read and write access to the wallet struct fields
+
+ logger log.Logger // Contextual logger to tag the ledger with its id
}
// URL implements accounts.Wallet, returning the URL of the Ledger device.
@@ -220,8 +222,8 @@ func (w *ledgerWallet) Open(passphrase string) error {
// - libusb on Windows doesn't support hotplug, so we can't detect USB unplugs
// - communication timeout on the Ledger requires a device power cycle to fix
func (w *ledgerWallet) heartbeat() {
- glog.V(logger.Debug).Infof("%s health-check started", w.url.String())
- defer glog.V(logger.Debug).Infof("%s health-check stopped", w.url.String())
+ w.logger.Debug("Ledger health-check started")
+ defer w.logger.Debug("Ledger health-check stopped")
// Execute heartbeat checks until termination or error
var (
@@ -260,7 +262,7 @@ func (w *ledgerWallet) heartbeat() {
}
// In case of error, wait for termination
if err != nil {
- glog.V(logger.Debug).Infof("%s health-check failed: %v", w.url.String(), err)
+ w.logger.Debug("Ledger health-check failed", "error", err)
errc = <-w.healthQuit
}
errc <- err
@@ -348,8 +350,8 @@ func (w *ledgerWallet) Accounts() []accounts.Account {
// selfDerive is an account derivation loop that upon request attempts to find
// new non-zero accounts.
func (w *ledgerWallet) selfDerive() {
- glog.V(logger.Debug).Infof("%s self-derivation started", w.url.String())
- defer glog.V(logger.Debug).Infof("%s self-derivation stopped", w.url.String())
+ w.logger.Debug("Ledger self-derivation started")
+ defer w.logger.Debug("Ledger self-derivation stopped")
// Execute self-derivations until termination or error
var (
@@ -394,7 +396,7 @@ func (w *ledgerWallet) selfDerive() {
// Retrieve the next derived Ethereum account
if nextAddr == (common.Address{}) {
if nextAddr, err = w.ledgerDerive(nextPath); err != nil {
- glog.V(logger.Warn).Infof("%s self-derivation failed: %v", w.url.String(), err)
+ w.logger.Warn("Ledger account derivation failed", "error", err)
break
}
}
@@ -405,12 +407,12 @@ func (w *ledgerWallet) selfDerive() {
)
balance, err = w.deriveChain.BalanceAt(context, nextAddr, nil)
if err != nil {
- glog.V(logger.Warn).Infof("%s self-derivation balance retrieval failed: %v", w.url.String(), err)
+ w.logger.Warn("Ledger balance retrieval failed", "error", err)
break
}
nonce, err = w.deriveChain.NonceAt(context, nextAddr, nil)
if err != nil {
- glog.V(logger.Warn).Infof("%s self-derivation nonce retrieval failed: %v", w.url.String(), err)
+ w.logger.Warn("Ledger nonce retrieval failed", "error", err)
break
}
// If the next account is empty, stop self-derivation, but add it nonetheless
@@ -430,7 +432,7 @@ func (w *ledgerWallet) selfDerive() {
// Display a log message to the user for new (or previously empty accounts)
if _, known := w.paths[nextAddr]; !known || (!empty && nextAddr == w.deriveNextAddr) {
- glog.V(logger.Info).Infof("%s discovered %s (balance %22v, nonce %4d) at %s", w.url.String(), nextAddr.Hex(), balance, nonce, path)
+ w.logger.Info("Ledger discovered new account", "address", nextAddr.Hex(), "path", path, "balance", balance, "nonce", nonce)
}
// Fetch the next potential account
if !empty {
@@ -469,7 +471,7 @@ func (w *ledgerWallet) selfDerive() {
}
// In case of error, wait for termination
if err != nil {
- glog.V(logger.Debug).Infof("%s self-derivation failed: %s", w.url.String(), err)
+ w.logger.Debug("Ledger self-derivation failed", "error", err)
errc = <-w.deriveQuit
}
errc <- err
@@ -849,9 +851,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
apdu = nil
}
// Send over to the device
- if glog.V(logger.Detail) {
- glog.Infof("-> %s: %x", w.device.Path, chunk)
- }
+ w.logger.Trace("Data chunk sent to the Ledger", "chunk", hexutil.Bytes(chunk))
if _, err := w.device.Write(chunk); err != nil {
return nil, err
}
@@ -864,9 +864,8 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
if _, err := io.ReadFull(w.device, chunk); err != nil {
return nil, err
}
- if glog.V(logger.Detail) {
- glog.Infof("<- %s: %x", w.device.Path, chunk)
- }
+ w.logger.Trace("Data chunk received from the Ledger", "chunk", hexutil.Bytes(chunk))
+
// Make sure the transport header matches
if chunk[0] != 0x01 || chunk[1] != 0x01 || chunk[2] != 0x05 {
return nil, errReplyInvalidHeader