Skip to content

Commit 06ed714

Browse files
committed
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.
1 parent 7cfceb7 commit 06ed714

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sweepbatcher/sweep_batch.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,10 @@ func (b *batch) monitorConfirmations(ctx context.Context) error {
18721872
func getFeePortionForSweep(spendTx *wire.MsgTx, numSweeps int,
18731873
totalSweptAmt btcutil.Amount) (btcutil.Amount, btcutil.Amount) {
18741874

1875-
totalFee := int64(totalSweptAmt) - spendTx.TxOut[0].Value
1875+
totalFee := int64(totalSweptAmt)
1876+
if len(spendTx.TxOut) > 0 {
1877+
totalFee -= spendTx.TxOut[0].Value
1878+
}
18761879
feePortionPerSweep := totalFee / int64(numSweeps)
18771880
roundingDiff := totalFee - (int64(numSweeps) * feePortionPerSweep)
18781881

@@ -1900,7 +1903,11 @@ func (b *batch) handleSpend(ctx context.Context, spendTx *wire.MsgTx) error {
19001903
notifyList = make([]sweep, 0, len(b.sweeps))
19011904
)
19021905
b.batchTxid = &txHash
1903-
b.batchPkScript = spendTx.TxOut[0].PkScript
1906+
if len(spendTx.TxOut) > 0 {
1907+
b.batchPkScript = spendTx.TxOut[0].PkScript
1908+
} else {
1909+
b.log.Warnf("transaction %v has no outputs", txHash)
1910+
}
19041911

19051912
// As a previous version of the batch transaction may get confirmed,
19061913
// which does not contain the latest sweeps, we need to detect the

0 commit comments

Comments
 (0)