Skip to content

Commit

Permalink
[contrib] [models] refs fibercrypto#139 - Handle errors after changin…
Browse files Browse the repository at this point in the history
…g signature of GetSpentOutput and GetAddress

... still WiP
  • Loading branch information
olemis committed Mar 4, 2020
1 parent d52aef3 commit 6e9010a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
30 changes: 23 additions & 7 deletions src/contrib/skywallet/sky-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func getInputs(wlt core.Wallet, txn coin.Transaction, indexes []int) (inputs []*
if err != nil {
logSkyWallet.WithFields(
logrus.Fields{"err": err, "input": txn.In[idx]},
).Errorln("unable to find address index for input")
).Errorln("unable to find address index for input")
return nil, err
}
transactionInput.Index = proto.Uint32(inputIndex)
Expand All @@ -139,7 +139,7 @@ func spendingOutputFromRemote(inputHash cipher.SHA256) (*readable.SpentOutput, e
if err != nil {
logSkyWallet.WithFields(
logrus.Fields{"err": err, "in": inputHash},
).Errorln("unable to get output from backend")
).Errorln("unable to get output from backend")
return nil, err
}
return out, nil
Expand Down Expand Up @@ -201,7 +201,7 @@ func readableTxn2Transaction(txn skytypes.ReadableTxn) (*coin.Transaction, error
return skyTxn, nil
}

func rawTxn2Transaction (txn skytypes.SkycoinTxn) (*coin.Transaction, error) {
func rawTxn2Transaction(txn skytypes.SkycoinTxn) (*coin.Transaction, error) {
buf, err := txn.EncodeSkycoinTransaction()
if err != nil {

Expand Down Expand Up @@ -274,7 +274,7 @@ func (sw *SkyWallet) signTxn(txn *coin.Transaction, idxs []int, dt string) (*coi
if len(signatures) != len(transactionInputs) {
logSkyWallet.WithFields(
logrus.Fields{
"signatures_len": len(signatures),
"signatures_len": len(signatures),
"transactionInputs_len": len(transactionInputs)}).Errorln("signatures response len should match inputs one")
return nil, fce.ErrTxnSignFailure
}
Expand Down Expand Up @@ -317,7 +317,16 @@ func derivationType(txn core.Transaction) string {
wt := skyWallet.WalletTypeDeterministic
inputs := txn.GetInputs()
if len(inputs) > 0 {
addr := inputs[0].GetSpentOutput().GetAddress()
out, err := inputs[0].GetSpentOutput()
if err != nil {
// FIXME: Improve error handling
return ""
}
addr, err := out.GetAddress()
if err != nil {
// FIXME: Improve error handling
return ""
}
if addr.IsBip32() {
wt = skyWallet.WalletTypeBip44
}
Expand All @@ -328,7 +337,14 @@ func derivationType(txn core.Transaction) string {
func verifyInputsGrouping(txn core.Transaction) error {
areBip32 := derivationType(txn) == skyWallet.WalletTypeBip44
for _, in := range txn.GetInputs() {
addr := in.GetSpentOutput().GetAddress()
out, err := in.GetSpentOutput()
if err != nil {
return err
}
addr, err := out.GetAddress()
if err != nil {
return err
}
if addr.IsBip32() != areBip32 {
return errors.New("all inputs should be grouped by derivation type")
}
Expand Down Expand Up @@ -419,7 +435,7 @@ func (sw SkyWallet) GetSignerDescription() (string, error) {
logSkyWallet.WithField("devLabel", features.Label).Errorln("unable to get device label")
return "", fce.ErrNilValue
}
return urnPrefix+*features.Label, nil
return urnPrefix + *features.Label, nil
}

// Type assertions
Expand Down
21 changes: 9 additions & 12 deletions src/models/walletsModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package models

import (
hardware "github.com/fibercrypto/fibercryptowallet/src/contrib/skywallet"
fccore "github.com/fibercrypto/fibercryptowallet/src/core"
wlcore "github.com/fibercrypto/fibercryptowallet/src/main"
"github.com/fibercrypto/fibercryptowallet/src/util/logging"
"github.com/fibercrypto/skywallet-go/src/integration/proxy"
skyWallet "github.com/fibercrypto/skywallet-go/src/skywallet"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/qml"
skyWallet "github.com/fibercrypto/skywallet-go/src/skywallet"
wlcore "github.com/fibercrypto/fibercryptowallet/src/main"
fccore "github.com/fibercrypto/fibercryptowallet/src/core"
"time"
)

Expand Down Expand Up @@ -40,7 +40,7 @@ type WalletModel struct {
_ func(row int) `slot:"removeWallet"`
_ func([]*QWallet) `slot:"loadModel"`
_ func([]*QWallet) `slot:"updateModel"`
_ func() `slot:"sniffHw"`
_ func() `slot:"sniffHw"`
_ func(string) `slot:"changeExpanded"`
_ int `property:"count"`
receivChannel chan *updateWalletInfo
Expand All @@ -55,12 +55,12 @@ type QWallet struct {
_ string `property:"coinHours"`
_ string `property:"fileName"`
_ bool `property:"expand"`
_ bool `property:"hasHardwareWallet"`
_ bool `property:"hasHardwareWallet"`
}

func (walletModel *WalletModel) init() {
logWalletsModel.Info("Initialize Wallet model")
dev = proxy.NewSequencer(skyWallet.NewDevice(skyWallet.DeviceTypeUSB), true, func() string{
dev = proxy.NewSequencer(skyWallet.NewDevice(skyWallet.DeviceTypeUSB), true, func() string {
return "not implemented"
})
walletModel.SetRoles(map[int]*core.QByteArray{
Expand Down Expand Up @@ -98,7 +98,8 @@ func (walletModel *WalletModel) init() {
encrypted = true
}
walletModel.editWallet(wi.row, wi.wallet.Name(), encrypted, wi.wallet.Sky(), wi.wallet.CoinHours())
walletModel.ConnectSniffHw(walletModel.sniffHw)
walletModel.ConnectSniffHw(walletModel.sniffHw)
}
}
}()
}
Expand Down Expand Up @@ -158,16 +159,12 @@ func (walletModel *WalletModel) updateWallet(fn string) {
for row := 0; row < walletModel.rowCount(core.NewQModelIndex()); row++ {
index = walletModel.Index(row, 0, core.NewQModelIndex())
fileName := walletModel.data(index, FileName)
if fileName.ToString() == fn {
if fileName.ToString() == fn {
hwConnectedOn = append(hwConnectedOn, row)
walletModel.DataChanged(index, index, []int{HasHardwareWallet})
break
}
}
}
}
}()

}

func (walletModel *WalletModel) changeExpanded(id string) {
Expand Down

0 comments on commit 6e9010a

Please sign in to comment.