Skip to content

Commit

Permalink
Minor updates based on chappjc review
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed May 19, 2022
1 parent 4471345 commit 7ed84e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
15 changes: 7 additions & 8 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ type baseWallet struct {
estimateFee func(RawRequester, uint64) (uint64, error) // TODO: resolve the awkwardness of an RPC-oriented func in a generic framework
decodeAddr dexbtc.AddressDecoder
stringAddr dexbtc.AddressStringer
net dex.Network

tipMtx sync.RWMutex
currentTip *block
Expand Down Expand Up @@ -871,7 +870,6 @@ func newUnconnectedWallet(cfg *BTCCloneCFG, walletCfg *WalletConfig) (*baseWalle
decodeAddr: addrDecoder,
stringAddr: addrStringer,
walletInfo: cfg.WalletInfo,
net: cfg.Network,
}

if w.estimateFee == nil {
Expand Down Expand Up @@ -1965,9 +1963,6 @@ func (btc *baseWallet) lookupWalletTxOutput(txHash *chainhash.Hash, vout uint32)
// returned slice will be in the same order as the argument.
func (btc *baseWallet) getTransactions(coins []dex.Bytes) ([]*GetTransactionResult, error) {
txs := make([]*GetTransactionResult, 0, len(coins))
if len(coins) == 0 {
return txs, nil
}

for _, coinID := range coins {
txHash, _, err := decodeCoinID(coinID)
Expand Down Expand Up @@ -2007,6 +2002,11 @@ func (btc *baseWallet) getTxFee(tx *wire.MsgTx) (uint64, error) {
in += uint64(prevMsgTx.TxOut[int(txIn.PreviousOutPoint.Index)].Value)
}

if in < out {
return 0, fmt.Errorf("tx %x has value of inputs %d < value of outputs %d",
tx.TxHash(), in, out)
}

return in - out, nil
}

Expand Down Expand Up @@ -2067,10 +2067,9 @@ func (btc *baseWallet) changeCanBeAccelerated(change *output, remainingSwaps boo
if utxo.TxID == changeTxHash && utxo.Vout == change.pt.vout {
if !remainingSwaps {
return errors.New("change locked by another order")
} else {
// change is locked by this order
return nil
}
// change is locked by this order
return nil
}
}

Expand Down
19 changes: 19 additions & 0 deletions client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3938,6 +3938,25 @@ func testGetTxFee(t *testing.T, segwit bool, walletType string) {
},
expectErr: true,
},
{
name: "tx out > in error",
tx: &wire.MsgTx{
TxIn: []*wire.TxIn{{
PreviousOutPoint: wire.OutPoint{
Hash: inputTx.TxHash(),
Index: 0,
}},
{PreviousOutPoint: wire.OutPoint{
Hash: inputTx.TxHash(),
Index: 2,
}},
},
TxOut: []*wire.TxOut{{
Value: 8e6,
}},
},
expectErr: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 7ed84e8

Please sign in to comment.