@@ -603,7 +603,9 @@ func (t *TxPublisher) broadcast(requestID uint64) (*BumpResult, error) {
603603 // Before we go to broadcast, we'll notify the aux sweeper, if it's
604604 // present of this new broadcast attempt.
605605 err := fn .MapOptionZ (t .cfg .AuxSweeper , func (aux AuxSweeper ) error {
606- return aux .NotifyBroadcast (record .req , tx , record .fee )
606+ return aux .NotifyBroadcast (
607+ record .req , tx , record .fee , record .outpointToTxIndex ,
608+ )
607609 })
608610 if err != nil {
609611 return nil , fmt .Errorf ("unable to notify aux sweeper: %w" , err )
@@ -725,6 +727,9 @@ type monitorRecord struct {
725727
726728 // fee is the fee paid by the tx.
727729 fee btcutil.Amount
730+
731+ // outpointToTxIndex is a map of outpoint to tx index.
732+ outpointToTxIndex map [wire.OutPoint ]int
728733}
729734
730735// Start starts the publisher by subscribing to block epoch updates and kicking
@@ -1042,10 +1047,11 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
10421047 // The tx has been created without any errors, we now register a new
10431048 // record by overwriting the same requestID.
10441049 t .records .Store (requestID , & monitorRecord {
1045- tx : sweepCtx .tx ,
1046- req : r .req ,
1047- feeFunction : r .feeFunction ,
1048- fee : sweepCtx .fee ,
1050+ tx : sweepCtx .tx ,
1051+ req : r .req ,
1052+ feeFunction : r .feeFunction ,
1053+ fee : sweepCtx .fee ,
1054+ outpointToTxIndex : sweepCtx .outpointToTxIndex ,
10491055 })
10501056
10511057 // Attempt to broadcast this new tx.
@@ -1199,6 +1205,10 @@ type sweepTxCtx struct {
11991205 fee btcutil.Amount
12001206
12011207 extraTxOut fn.Option [SweepOutput ]
1208+
1209+ // outpointToTxIndex maps the outpoint of the inputs to their index in
1210+ // the sweep transaction.
1211+ outpointToTxIndex map [wire.OutPoint ]int
12021212}
12031213
12041214// createSweepTx creates a sweeping tx based on the given inputs, change
@@ -1229,6 +1239,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
12291239 // We start by adding all inputs that commit to an output. We do this
12301240 // since the input and output index must stay the same for the
12311241 // signatures to be valid.
1242+ outpointToTxIndex := make (map [wire.OutPoint ]int )
12321243 for _ , o := range inputs {
12331244 if o .RequiredTxOut () == nil {
12341245 continue
@@ -1240,6 +1251,8 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
12401251 Sequence : o .BlocksToMaturity (),
12411252 })
12421253 sweepTx .AddTxOut (o .RequiredTxOut ())
1254+
1255+ outpointToTxIndex [o .OutPoint ()] = len (sweepTx .TxOut ) - 1
12431256 }
12441257
12451258 // Sum up the value contained in the remaining inputs, and add them to
@@ -1331,9 +1344,10 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
13311344 )(changeOutputsOpt )
13321345
13331346 return & sweepTxCtx {
1334- tx : sweepTx ,
1335- fee : txFee ,
1336- extraTxOut : fn .FlattenOption (extraTxOut ),
1347+ tx : sweepTx ,
1348+ fee : txFee ,
1349+ extraTxOut : fn .FlattenOption (extraTxOut ),
1350+ outpointToTxIndex : outpointToTxIndex ,
13371351 }, nil
13381352}
13391353
0 commit comments