Skip to content

Commit

Permalink
make device injectable and fix error handling in GetSignerUID ref fib…
Browse files Browse the repository at this point in the history
  • Loading branch information
stdevAlDen committed Oct 14, 2019
1 parent 32e545f commit 469135a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/hardware/sky-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (
)

type SkyWallet struct {
dev skyWallet.Devicer
}

// skyWallet.NewDevice(skyWallet.DeviceTypeUSB),
func NewSkyWallet(dev skyWallet.Devicer) *SkyWallet {
return &SkyWallet{
dev: dev,
}
}

// SignTransaction using hardware wallet
Expand Down Expand Up @@ -64,15 +72,18 @@ func (sw SkyWallet) SignTransaction(tr core.Transaction, pr core.PasswordReader,

// GetSignerUID this signer uid using the hardware wallet id
func (sw SkyWallet) GetSignerUID() core.UID {
device := skyWallet.NewDevice(skyWallet.DeviceTypeUSB)
device := sw.dev
if device == nil {
logrus.Error("error creating hardware wallet deice handler")
return "undefined" // i18n
// TODO i18n
logrus.Error("error, nil hardware wallet device handler")
return "undefined"
}
defer device.Close()
// FIXME: This should not be closed, it's a lower level detail.
// defer device.Close()
msg, err := device.GetFeatures()
if err != nil {
logrus.WithError(err).Error("error getting device features")
return "undefined"
}
switch msg.Kind {
case uint16(messages.MessageType_MessageType_Features):
Expand Down

0 comments on commit 469135a

Please sign in to comment.