sweepbatcher: check that spending tx has an output

Previously the code handling spending tx crashed if it doesn't have an output.
This is likely to occur only in tests.
This commit is contained in:
Boris Nagaev 2025-01-09 00:26:08 -03:00
parent 7cfceb7676
commit 06ed714e9a
No known key found for this signature in database

View file

@ -1872,7 +1872,10 @@ func (b *batch) monitorConfirmations(ctx context.Context) error {
func getFeePortionForSweep(spendTx *wire.MsgTx, numSweeps int,
totalSweptAmt btcutil.Amount) (btcutil.Amount, btcutil.Amount) {
totalFee := int64(totalSweptAmt) - spendTx.TxOut[0].Value
totalFee := int64(totalSweptAmt)
if len(spendTx.TxOut) > 0 {
totalFee -= spendTx.TxOut[0].Value
}
feePortionPerSweep := totalFee / int64(numSweeps)
roundingDiff := totalFee - (int64(numSweeps) * feePortionPerSweep)
@ -1900,7 +1903,11 @@ func (b *batch) handleSpend(ctx context.Context, spendTx *wire.MsgTx) error {
notifyList = make([]sweep, 0, len(b.sweeps))
)
b.batchTxid = &txHash
b.batchPkScript = spendTx.TxOut[0].PkScript
if len(spendTx.TxOut) > 0 {
b.batchPkScript = spendTx.TxOut[0].PkScript
} else {
b.log.Warnf("transaction %v has no outputs", txHash)
}
// As a previous version of the batch transaction may get confirmed,
// which does not contain the latest sweeps, we need to detect the