From 24a1b5a5988ba9b43ab907c905b9fb0b8a12cfef Mon Sep 17 00:00:00 2001 From: JoeGruff Date: Fri, 5 May 2023 15:43:59 +0900 Subject: [PATCH] client/btc: Use coin specific tx hashes. --- client/asset/btc/btc.go | 22 +++++++++++----------- client/asset/btc/btc_test.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/asset/btc/btc.go b/client/asset/btc/btc.go index 5ac495bef8..01c3dbe919 100644 --- a/client/asset/btc/btc.go +++ b/client/asset/btc/btc.go @@ -3109,7 +3109,7 @@ func accelerateOrder(btc *baseWallet, swapCoins, accelerationCoins []dex.Bytes, delete(btc.fundingCoins, newOutPoint(changeTxHash, changeVout)) if newChange == nil { - return nil, signedTx.TxHash().String(), nil + return nil, btc.hashTx(signedTx).String(), nil } // Add the new change to the cache if needed. We check if @@ -3137,7 +3137,7 @@ func accelerateOrder(btc *baseWallet, swapCoins, accelerationCoins []dex.Bytes, // return nil error since tx is already broadcast, and core needs to update // the change coin - return newChange, signedTx.TxHash().String(), nil + return newChange, btc.hashTx(signedTx).String(), nil } // AccelerationEstimate takes the same parameters as AccelerateOrder, but @@ -4391,8 +4391,8 @@ func (btc *baseWallet) send(address string, val uint64, feeRate uint64, subtract return nil, 0, 0, err } - txHash := msgTx.TxHash() - return &txHash, 0, toSend, nil + txHash := btc.hashTx(msgTx) + return txHash, 0, toSend, nil } // SwapConfirmations gets the number of confirmations for the specified swap @@ -4858,7 +4858,7 @@ func (btc *baseWallet) signTxAndAddChange(baseTx *wire.MsgTx, addr btcutil.Addre totalOut += uint64(changeOutput.Value) } else { btc.log.Debugf("Foregoing change worth up to %v in tx %v because it is dust", - changeOutput.Value, msgTx.TxHash()) + changeOutput.Value, btc.hashTx(msgTx)) } txHash := btc.hashTx(msgTx) @@ -5314,23 +5314,23 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time return nil, nil, fmt.Errorf("failed to sign bond tx: %w", err) } - txid := signedTx.TxHash() + txid := btc.hashTx(signedTx) - signedTxBytes, err := serializeMsgTx(signedTx) + signedTxBytes, err := btc.serializeTx(signedTx) if err != nil { return nil, nil, err } - unsignedTxBytes, err := serializeMsgTx(baseTx) + unsignedTxBytes, err := btc.serializeTx(baseTx) if err != nil { return nil, nil, err } // Prep the redeem / refund tx. - redeemMsgTx, err := btc.makeBondRefundTxV0(&txid, 0, amt, bondScript, bondKey, feeRate) + redeemMsgTx, err := btc.makeBondRefundTxV0(txid, 0, amt, bondScript, bondKey, feeRate) if err != nil { return nil, nil, fmt.Errorf("unable to create bond redemption tx: %w", err) } - redeemTx, err := serializeMsgTx(redeemMsgTx) + redeemTx, err := btc.serializeTx(redeemMsgTx) if err != nil { return nil, nil, fmt.Errorf("failed to serialize bond redemption tx: %w", err) } @@ -5339,7 +5339,7 @@ func (btc *baseWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time Version: ver, AssetID: btc.cloneParams.AssetID, Amount: amt, - CoinID: toCoinID(&txid, 0), + CoinID: toCoinID(txid, 0), Data: bondScript, SignedTx: signedTxBytes, UnsignedTx: unsignedTxBytes, diff --git a/client/asset/btc/btc_test.go b/client/asset/btc/btc_test.go index fa62494179..909b7110db 100644 --- a/client/asset/btc/btc_test.go +++ b/client/asset/btc/btc_test.go @@ -3976,7 +3976,7 @@ func testAccelerateOrder(t *testing.T, segwit bool, walletType string) { t.Fatalf("%s: unexpected error: %v", test.name, err) } if *changeTxHash != node.sentRawTx.TxHash() { - t.Fatalf("%s: change tx hash %x != expected: %x", test.name, changeTxHash, node.sentRawTx.TxHash()) + t.Fatalf("%s: change tx hash %s != expected: %s", test.name, changeTxHash, node.sentRawTx.TxHash()) } if changeVout != 0 { t.Fatalf("%s: change vout %v != expected: 0", test.name, changeVout)