From 92256194342332085e1997b0e48a7ff78539564a Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Fri, 5 Oct 2018 11:35:56 +0200 Subject: [PATCH] use formatted logger in all packages --- lightwallet/installer.go | 9 ++------- lightwallet/lightwallet.go | 5 +++++ lightwallet/normal_channel.go | 6 ++---- lightwallet/secure_channel.go | 4 +--- 4 files changed, 10 insertions(+), 14 deletions(-) create mode 100644 lightwallet/lightwallet.go diff --git a/lightwallet/installer.go b/lightwallet/installer.go index cf5e7e0..ae28739 100644 --- a/lightwallet/installer.go +++ b/lightwallet/installer.go @@ -8,7 +8,6 @@ import ( "github.com/status-im/status-go/smartcard/apdu" "github.com/status-im/status-go/smartcard/globalplatform" - "github.com/status-im/status-go/smartcard/hexutils" ) var ( @@ -174,7 +173,7 @@ func (i *Installer) installApplet(capFile *os.File) (*Secrets, error) { for load.Next() { cmd := load.GetCommand() - _, err = i.send(fmt.Sprintf("load %d", load.Index()), cmd) + _, err = i.send(fmt.Sprintf("load %d of 32", load.Index()), cmd) if err != nil { return nil, err } @@ -199,7 +198,7 @@ func (i *Installer) installApplet(capFile *os.File) (*Secrets, error) { } func (i *Installer) send(description string, cmd *apdu.Command, allowedResponses ...uint16) (*apdu.Response, error) { - fmt.Printf("-------------------------\nsending %s\n", description) + logger.Debug("sending apdu command", "name", description) resp, err := i.c.Send(cmd) if err != nil { return nil, err @@ -225,7 +224,3 @@ func generateHostChallenge() ([]byte, error) { _, err := rand.Read(c) return c, err } - -func l(message string, raw []byte) { - fmt.Printf("%s %s\n", message, hexutils.BytesToHexWithSpaces(raw)) -} diff --git a/lightwallet/lightwallet.go b/lightwallet/lightwallet.go new file mode 100644 index 0000000..918bead --- /dev/null +++ b/lightwallet/lightwallet.go @@ -0,0 +1,5 @@ +package lightwallet + +import "github.com/ethereum/go-ethereum/log" + +var logger = log.New("package", "status-go/smartcard/lightwallet") diff --git a/lightwallet/normal_channel.go b/lightwallet/normal_channel.go index 1ae7276..3da0685 100644 --- a/lightwallet/normal_channel.go +++ b/lightwallet/normal_channel.go @@ -1,8 +1,6 @@ package lightwallet import ( - "fmt" - "github.com/status-im/status-go/smartcard/apdu" "github.com/status-im/status-go/smartcard/globalplatform" "github.com/status-im/status-go/smartcard/hexutils" @@ -26,12 +24,12 @@ func (c *NormalChannel) Send(cmd *apdu.Command) (*apdu.Response, error) { return nil, err } - fmt.Printf("COMMAND %s\n", hexutils.BytesToHexWithSpaces(rawCmd)) + logger.Debug("apdu command", "hex", hexutils.BytesToHexWithSpaces(rawCmd)) rawResp, err := c.t.Transmit(rawCmd) if err != nil { return nil, err } - fmt.Printf("RESPONSE %s\n", hexutils.BytesToHexWithSpaces(rawResp)) + logger.Debug("apdu response", "hex", hexutils.BytesToHexWithSpaces(rawResp)) resp, err := apdu.ParseResponse(rawResp) if err != nil { diff --git a/lightwallet/secure_channel.go b/lightwallet/secure_channel.go index fe1344a..5d462e3 100644 --- a/lightwallet/secure_channel.go +++ b/lightwallet/secure_channel.go @@ -1,8 +1,6 @@ package lightwallet import ( - "fmt" - "github.com/status-im/status-go/smartcard/apdu" "github.com/status-im/status-go/smartcard/globalplatform" "github.com/status-im/status-go/smartcard/hexutils" @@ -28,7 +26,7 @@ func (c *SecureChannel) Send(cmd *apdu.Command) (*apdu.Response, error) { return nil, err } - fmt.Printf("WRAPPING %s\n", hexutils.BytesToHexWithSpaces(rawCmd)) + logger.Debug("wrapping apdu command", "hex", hexutils.BytesToHexWithSpaces(rawCmd)) wrappedCmd, err := c.w.Wrap(cmd) if err != nil { return nil, err