@@ -222,11 +222,13 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
222222 }
223223 api := & btc.ExplorerAPI {BaseURL : apiURL }
224224
225- sweepTx := wire .NewMsgTx (2 )
226- totalOutputValue := int64 (0 )
227- signDescs := make ([]* input.SignDescriptor , 0 )
228- var estimator input.TxWeightEstimator
229-
225+ var (
226+ sweepTx = wire .NewMsgTx (2 )
227+ totalOutputValue = int64 (0 )
228+ signDescs = make ([]* input.SignDescriptor , 0 )
229+ prevOutFetcher = txscript .NewMultiPrevOutFetcher (nil )
230+ estimator input.TxWeightEstimator
231+ )
230232 for _ , target := range targets {
231233 // We can't rely on the CSV delay of the channel DB to be
232234 // correct. But it doesn't cost us a lot to just brute force it.
@@ -246,11 +248,17 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
246248 }
247249
248250 // Create the transaction input.
251+ prevOutPoint := wire.OutPoint {
252+ Hash : target .txid ,
253+ Index : target .index ,
254+ }
255+ prevTxOut := & wire.TxOut {
256+ PkScript : scriptHash ,
257+ Value : target .value ,
258+ }
259+ prevOutFetcher .AddPrevOut (prevOutPoint , prevTxOut )
249260 sweepTx .TxIn = append (sweepTx .TxIn , & wire.TxIn {
250- PreviousOutPoint : wire.OutPoint {
251- Hash : target .txid ,
252- Index : target .index ,
253- },
261+ PreviousOutPoint : prevOutPoint ,
254262 Sequence : input .LockTimeToSequence (
255263 false , uint32 (csvTimeout ),
256264 ),
@@ -264,11 +272,8 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
264272 target .delayBasePointDesc .PubKey ,
265273 ),
266274 WitnessScript : script ,
267- Output : & wire.TxOut {
268- PkScript : scriptHash ,
269- Value : target .value ,
270- },
271- HashType : txscript .SigHashAll ,
275+ Output : prevTxOut ,
276+ HashType : txscript .SigHashAll ,
272277 }
273278 totalOutputValue += target .value
274279 signDescs = append (signDescs , signDesc )
@@ -298,7 +303,7 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
298303 }}
299304
300305 // Sign the transaction now.
301- sigHashes := input . NewTxSigHashesV0Only (sweepTx )
306+ sigHashes := txscript . NewTxSigHashes (sweepTx , prevOutFetcher )
302307 for idx , desc := range signDescs {
303308 desc .SigHashes = sigHashes
304309 desc .InputIndex = idx
0 commit comments