From ed199f4c062a8d1912f325fc700de2530003038b Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Tue, 3 Mar 2020 18:55:21 -0500 Subject: [PATCH] fix linter ref #165 --- src/cli/integration/integration_test.go | 3 +-- src/integration/proxy/sequencer.go | 12 +++++++-- src/skywallet/helper.go | 2 +- src/skywallet/skywallet.go | 35 ++++++++++++++++++++----- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/cli/integration/integration_test.go b/src/cli/integration/integration_test.go index 9384e25..492b428 100644 --- a/src/cli/integration/integration_test.go +++ b/src/cli/integration/integration_test.go @@ -534,8 +534,8 @@ func TestRecovery(t *testing.T) { var stdInDone = false wg := sync.WaitGroup{} + wg.Add(2) go func() { - wg.Add(1) defer wg.Done() scanner := bufio.NewScanner(stdoutPipe) @@ -558,7 +558,6 @@ func TestRecovery(t *testing.T) { }() go func() { - wg.Add(1) defer wg.Done() scanner := bufio.NewScanner(stderrPipe) scanner.Split(bufio.ScanWords) diff --git a/src/integration/proxy/sequencer.go b/src/integration/proxy/sequencer.go index 93c101b..11401c0 100644 --- a/src/integration/proxy/sequencer.go +++ b/src/integration/proxy/sequencer.go @@ -22,18 +22,26 @@ type Sequencer struct { scan func(requestKind skywallet.InputRequestKind, title, message string) (string, error) } -// ActionCancelableFrom is used for masking options, for example: +// ActionConfirmFrom is used for masking options, for example: // 00000000 ActionConfirmNone // 00000001 ActionConfirmOkFromDevButton // 00000010 ActionConfirmCancelFromDevButton type ActionConfirmFrom uint8 +// ActionConfirmNone no thing to confirm var ActionConfirmNone ActionConfirmFrom = 0x0 +// ActionConfirmOkFromDevButton confirm in the device var ActionConfirmOkFromDevButton ActionConfirmFrom = 0x1 +// ActionConfirmCancelFromDevButton cancel from the device var ActionConfirmCancelFromDevButton ActionConfirmFrom = 0x2 +// ActionConfirmOkAndCancelFromDevButton ok and/or cancel from the device var ActionConfirmOkAndCancelFromDevButton ActionConfirmFrom = 0x4 +// ActionConfirmOkFromWireProtocol confirm ok though wire var ActionConfirmOkFromWireProtocol ActionConfirmFrom = 0x8 +// ActionConfirmCancelFromWireProtocol confirm cancel though wire var ActionConfirmCancelFromWireProtocol ActionConfirmFrom = 0x16 +// ActionConfirmOkAndCancelFromWireProtocol confirm ok and/or cancel though wire var ActionConfirmOkAndCancelFromWireProtocol ActionConfirmFrom = 0x32 +// ActionWordRequest a word was request var ActionWordRequest ActionConfirmFrom = 0x64 // mixActionConfirmFrom create a merged value from all the masks @@ -88,7 +96,7 @@ func (sq *Sequencer) handleInputReaderResponse(err error) error { return err } -func (sq *Sequencer) handleInputReaderCanceled(err error) error { +func (sq *Sequencer) handleInputReaderCanceled(_ error) error { msg, err := sq.dev.Cancel() if err != nil { sq.log.WithError(err).Errorln("unable to cancel command") diff --git a/src/skywallet/helper.go b/src/skywallet/helper.go index b26b0d1..e908cac 100644 --- a/src/skywallet/helper.go +++ b/src/skywallet/helper.go @@ -103,7 +103,7 @@ func NewDriver(deviceType DeviceType, emulatorAddress ...string) (*Driver, error if len(emulatorAddress) == 0 { emulatorAddress = []string{"127.0.0.1"} } else if len(emulatorAddress) > 1 { - return nil, ErrInvalidArgCountForEmulatorIpAddress + return nil, ErrInvalidArgCountForEmulatorIPAddress } udpBus, err := usb.InitUDP([]int{EmulatorPort}, emulatorAddress[0]) if err != nil { diff --git a/src/skywallet/skywallet.go b/src/skywallet/skywallet.go index 862f7db..a059a76 100644 --- a/src/skywallet/skywallet.go +++ b/src/skywallet/skywallet.go @@ -46,16 +46,16 @@ var ( ErrDeviceTypeEmulator = errors.New("device type cannot be emulator") // ErrInvalidWordCount is returned if word count is not valid mnemonic word length ErrInvalidWordCount = errors.New("word count must be 12 or 24") - // ErrInvalidArgCountForEmulatorIpAddress emulator ip address is the only one expected argument for emulatorAddress - ErrInvalidArgCountForEmulatorIpAddress = errors.New("emulator ip address is the only one expected argument for emulatorAddress") + // ErrInvalidArgCountForEmulatorIPAddress emulator ip address is the only one expected argument for emulatorAddress + ErrInvalidArgCountForEmulatorIPAddress = errors.New("emulator ip address is the only one expected argument for emulatorAddress") // ErrNoDeviceConnected is returned if no device is connected to the system ErrNoDeviceConnected = errors.New("no device connected") // ErrInvalidWalletType a valid wallet type should be specified ErrInvalidWalletType = errors.New("invalid wallet type, options are: " + WalletTypeDeterministic + " or " + WalletTypeBip44) - // ErrUserCancelledWithDeviceButton the requested operation has been cancelled from the device input button - ErrUserCancelledWithDeviceButton = errors.New("the requested operation has been cancelled from the device input button") - // ErrUserCancelledFromInputReader the requested operation has been cancelled from the device input button - ErrUserCancelledFromInputReader = errors.New("the requested operation has been cancelled from the user interaction") + // ErrUserCancelledWithDeviceButton the requested operation has been canceled from the device input button + ErrUserCancelledWithDeviceButton = errors.New("the requested operation has been canceled from the device input button") + // ErrUserCancelledFromInputReader the requested operation has been canceled from the device input button + ErrUserCancelledFromInputReader = errors.New("the requested operation has been canceled from the user interaction") ) const ( @@ -70,13 +70,20 @@ const ( firstHardenedChild = uint32(0x80000000) ) +// InputRequestKind specify the input required for the reader type InputRequestKind uint32 const ( + // RequestKindPinMatrix require an input reader for a matrix RequestKindPinMatrix InputRequestKind = iota + // RequestKindPassphrase require an input reader for a pass phrase RequestKindPassphrase + // RequestKindWord require an input reader for a word RequestKindWord + // RequestInformUserOnlyOk no special input, just accept RequestInformUserOnlyOk + // RequestInformUserOnlyCancel just cancel if required RequestInformUserOnlyCancel + // RequestInformUserOkAndCancel use ok or cancel inpt reader as required RequestInformUserOkAndCancel ) @@ -84,19 +91,33 @@ const ( // Devicer provides api for the hw wallet functions type Devicer interface { + // AddressGen generate addresses AddressGen(addressN, startIndex uint32, confirmAddress bool, walletType string) (wire.Message, error) + // ApplySettings to the device ApplySettings(usePassphrase *bool, label string, language string) (wire.Message, error) + // Backup create a seed backup Backup() (wire.Message, error) + // Cancel cancel current operation Cancel() (wire.Message, error) + // CheckMessageSignature check if a message signature is valid CheckMessageSignature(message, signature, address string) (wire.Message, error) + // ChangePin change device PIN ChangePin(removePin *bool) (wire.Message, error) + // Connected check if the is a device connected Connected() bool + // Available check if the device is reachable Available() bool + // EraseFirmware erase device firmware (bootloader mode). EraseFirmware(length uint32) (wire.Message, error) + // UploadFirmware upload a new firmware (bootloader mode). UploadFirmware(payload []byte, hash [32]byte) (wire.Message, error) + // GetFeatures return the device features GetFeatures() (wire.Message, error) + // GenerateMnemonic generate a mnemonic GenerateMnemonic(wordCount uint32, usePassphrase bool) (wire.Message, error) + // Recovery a device mnemonic Recovery(wordCount uint32, usePassphrase *bool, dryRun bool) (wire.Message, error) + // SetMnemonic sets a specific mnemonic SetMnemonic(mnemonic string) (wire.Message, error) TransactionSign(inputs []*messages.SkycoinTransactionInput, outputs []*messages.SkycoinTransactionOutput, walletType string) (wire.Message, error) SignMessage(addressN, addressIndex int, message string, walletType string) (wire.Message, error) @@ -596,6 +617,7 @@ func (d *Device) Available() bool { return true } +// EraseFirmware erase current firmware func (d *Device) EraseFirmware(length uint32) (wire.Message, error) { if d.Driver.DeviceType() != DeviceTypeUSB { return wire.Message{}, ErrDeviceTypeEmulator @@ -614,6 +636,7 @@ func (d *Device) EraseFirmware(length uint32) (wire.Message, error) { return d.Driver.SendToDevice(d.dev, eraseFirmwareChunks) } +// UploadFirmware upload a new firmware func (d *Device) UploadFirmware(payload []byte, hash [32]byte) (wire.Message, error) { if d.Driver.DeviceType() != DeviceTypeUSB { return wire.Message{}, ErrDeviceTypeEmulator