• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.6
/input/input.go
1
package input
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
        "github.com/btcsuite/btcd/txscript"
8
        "github.com/btcsuite/btcd/wire"
9
        "github.com/lightningnetwork/lnd/lntypes"
10
)
11

12
// EmptyOutPoint is a zeroed outpoint.
13
var EmptyOutPoint wire.OutPoint
14

15
// Input represents an abstract UTXO which is to be spent using a sweeping
16
// transaction. The method provided give the caller all information needed to
17
// construct a valid input within a sweeping transaction to sweep this
18
// lingering UTXO.
19
type Input interface {
20
        // Outpoint returns the reference to the output being spent, used to
21
        // construct the corresponding transaction input.
22
        OutPoint() wire.OutPoint
23

24
        // RequiredTxOut returns a non-nil TxOut if input commits to a certain
25
        // transaction output. This is used in the SINGLE|ANYONECANPAY case to
26
        // make sure any presigned input is still valid by including the
27
        // output.
28
        RequiredTxOut() *wire.TxOut
29

30
        // RequiredLockTime returns whether this input commits to a tx locktime
31
        // that must be used in the transaction including it.
32
        RequiredLockTime() (uint32, bool)
33

34
        // WitnessType returns an enum specifying the type of witness that must
35
        // be generated in order to spend this output.
36
        WitnessType() WitnessType
37

38
        // SignDesc returns a reference to a spendable output's sign
39
        // descriptor, which is used during signing to compute a valid witness
40
        // that spends this output.
41
        SignDesc() *SignDescriptor
42

43
        // CraftInputScript returns a valid set of input scripts allowing this
44
        // output to be spent. The returns input scripts should target the
45
        // input at location txIndex within the passed transaction. The input
46
        // scripts generated by this method support spending p2wkh, p2wsh, and
47
        // also nested p2sh outputs.
48
        CraftInputScript(signer Signer, txn *wire.MsgTx,
49
                hashCache *txscript.TxSigHashes,
50
                prevOutputFetcher txscript.PrevOutputFetcher,
51
                txinIdx int) (*Script, error)
52

53
        // BlocksToMaturity returns the relative timelock, as a number of
54
        // blocks, that must be built on top of the confirmation height before
55
        // the output can be spent. For non-CSV locked inputs this is always
56
        // zero.
57
        BlocksToMaturity() uint32
58

59
        // HeightHint returns the minimum height at which a confirmed spending
60
        // tx can occur.
61
        HeightHint() uint32
62

63
        // UnconfParent returns information about a possibly unconfirmed parent
64
        // tx.
65
        UnconfParent() *TxInfo
66
}
67

68
// TxInfo describes properties of a parent tx that are relevant for CPFP.
69
type TxInfo struct {
70
        // Fee is the fee of the tx.
71
        Fee btcutil.Amount
72

73
        // Weight is the weight of the tx.
74
        Weight lntypes.WeightUnit
75
}
76

77
// String returns a human readable version of the tx info.
78
func (t *TxInfo) String() string {
79
        return fmt.Sprintf("fee=%v, weight=%v", t.Fee, t.Weight)
80
}
81

82
// SignDetails is a struct containing information needed to resign certain
83
// inputs. It is used to re-sign 2nd level HTLC transactions that uses the
UNCOV
84
// SINGLE|ANYONECANPAY sighash type, as we have a signature provided by our
×
UNCOV
85
// peer, but we can aggregate multiple of these 2nd level transactions into a
×
UNCOV
86
// new transaction, that needs to be signed by us.
×
87
type SignDetails struct {
88
        // SignDesc is the sign descriptor needed for us to sign the input.
89
        SignDesc SignDescriptor
90

91
        // PeerSig is the peer's signature for this input.
92
        PeerSig Signature
93

94
        // SigHashType is the sighash signed by the peer.
95
        SigHashType txscript.SigHashType
96
}
97

98
type inputKit struct {
99
        outpoint        wire.OutPoint
100
        witnessType     WitnessType
101
        signDesc        SignDescriptor
102
        heightHint      uint32
103
        blockToMaturity uint32
104
        cltvExpiry      uint32
105

106
        // unconfParent contains information about a potential unconfirmed
107
        // parent transaction.
108
        unconfParent *TxInfo
109
}
110

111
// OutPoint returns the breached output's identifier that is to be included as
112
// a transaction input.
113
func (i *inputKit) OutPoint() wire.OutPoint {
114
        return i.outpoint
115
}
116

117
// RequiredTxOut returns a nil for the base input type.
118
func (i *inputKit) RequiredTxOut() *wire.TxOut {
119
        return nil
120
}
121

122
// RequiredLockTime returns whether this input commits to a tx locktime that
123
// must be used in the transaction including it. This will be false for the
2,914✔
124
// base input type since we can re-sign for any lock time.
2,914✔
125
func (i *inputKit) RequiredLockTime() (uint32, bool) {
2,914✔
126
        return i.cltvExpiry, i.cltvExpiry > 0
127
}
128

134✔
129
// WitnessType returns the type of witness that must be generated to spend the
134✔
130
// breached output.
134✔
131
func (i *inputKit) WitnessType() WitnessType {
132
        return i.witnessType
133
}
134

135
// SignDesc returns the breached output's SignDescriptor, which is used during
25✔
136
// signing to compute the witness.
25✔
137
func (i *inputKit) SignDesc() *SignDescriptor {
25✔
138
        return &i.signDesc
139
}
140

141
// HeightHint returns the minimum height at which a confirmed spending
1,521✔
142
// tx can occur.
1,521✔
143
func (i *inputKit) HeightHint() uint32 {
1,521✔
144
        return i.heightHint
145
}
146

147
// BlocksToMaturity returns the relative timelock, as a number of blocks, that
2,878✔
148
// must be built on top of the confirmation height before the output can be
2,878✔
149
// spent. For non-CSV locked inputs this is always zero.
2,878✔
150
func (i *inputKit) BlocksToMaturity() uint32 {
151
        return i.blockToMaturity
152
}
UNCOV
153

×
UNCOV
154
// Cpfp returns information about a possibly unconfirmed parent tx.
×
UNCOV
155
func (i *inputKit) UnconfParent() *TxInfo {
×
156
        return i.unconfParent
157
}
158

159
// BaseInput contains all the information needed to sweep a basic
160
// output (CSV/CLTV/no time lock).
1,416✔
161
type BaseInput struct {
1,416✔
162
        inputKit
1,416✔
163
}
164

165
// MakeBaseInput assembles a new BaseInput that can be used to construct a
62✔
166
// sweep transaction.
62✔
167
func MakeBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
62✔
168
        signDescriptor *SignDescriptor, heightHint uint32,
169
        unconfParent *TxInfo) BaseInput {
170

171
        return BaseInput{
7✔
172
                inputKit{
7✔
173
                        outpoint:     *outpoint,
7✔
174
                        witnessType:  witnessType,
175
                        signDesc:     *signDescriptor,
176
                        heightHint:   heightHint,
177
                        unconfParent: unconfParent,
178
                },
179
        }
180
}
181

182
// NewBaseInput allocates and assembles a new *BaseInput that can be used to
183
// construct a sweep transaction.
1,120✔
184
func NewBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
1,120✔
185
        signDescriptor *SignDescriptor, heightHint uint32) *BaseInput {
1,120✔
186

187
        input := MakeBaseInput(
188
                outpoint, witnessType, signDescriptor, heightHint, nil,
189
        )
190

191
        return &input
192
}
193

3✔
194
// NewCsvInput assembles a new csv-locked input that can be used to
6✔
195
// construct a sweep transaction.
3✔
196
func NewCsvInput(outpoint *wire.OutPoint, witnessType WitnessType,
3✔
197
        signDescriptor *SignDescriptor, heightHint uint32,
198
        blockToMaturity uint32) *BaseInput {
199

200
        return &BaseInput{
201
                inputKit{
202
                        outpoint:        *outpoint,
203
                        witnessType:     witnessType,
204
                        signDesc:        *signDescriptor,
205
                        heightHint:      heightHint,
206
                        blockToMaturity: blockToMaturity,
207
                },
208
        }
209
}
1,120✔
210

1,120✔
211
// NewCsvInputWithCltv assembles a new csv and cltv locked input that can be
1,120✔
212
// used to construct a sweep transaction.
1,123✔
213
func NewCsvInputWithCltv(outpoint *wire.OutPoint, witnessType WitnessType,
3✔
214
        signDescriptor *SignDescriptor, heightHint uint32,
3✔
215
        csvDelay uint32, cltvExpiry uint32) *BaseInput {
216

1,120✔
217
        return &BaseInput{
1,120✔
218
                inputKit{
1,120✔
219
                        outpoint:        *outpoint,
1,120✔
220
                        witnessType:     witnessType,
1,120✔
221
                        signDesc:        *signDescriptor,
1,120✔
222
                        heightHint:      heightHint,
1,120✔
223
                        blockToMaturity: csvDelay,
1,120✔
224
                        cltvExpiry:      cltvExpiry,
1,120✔
225
                        unconfParent:    nil,
1,120✔
226
                },
227
        }
228
}
229

230
// CraftInputScript returns a valid set of input scripts allowing this output
231
// to be spent. The returned input scripts should target the input at location
232
// txIndex within the passed transaction. The input scripts generated by this
566✔
233
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
566✔
234
func (bi *BaseInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
566✔
235
        hashCache *txscript.TxSigHashes,
566✔
236
        prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
566✔
237
        error) {
566✔
238

566✔
239
        signDesc := bi.SignDesc()
566✔
240
        signDesc.PrevOutputFetcher = prevOutputFetcher
241
        witnessFunc := bi.witnessType.WitnessGenerator(signer, signDesc)
242

243
        return witnessFunc(txn, hashCache, txinIdx)
244
}
245

509✔
246
// HtlcSucceedInput constitutes a sweep input that needs a pre-image. The input
509✔
247
// is expected to reside on the commitment tx of the remote party and should
509✔
248
// not be a second level tx output.
509✔
249
type HtlcSucceedInput struct {
509✔
250
        inputKit
509✔
251

509✔
252
        preimage []byte
509✔
253
}
509✔
254

509✔
255
// MakeHtlcSucceedInput assembles a new redeem input that can be used to
256
// construct a sweep transaction.
257
func MakeHtlcSucceedInput(outpoint *wire.OutPoint,
258
        signDescriptor *SignDescriptor, preimage []byte, heightHint,
259
        blocksToMaturity uint32) HtlcSucceedInput {
260

4✔
261
        return HtlcSucceedInput{
4✔
262
                inputKit: inputKit{
4✔
263
                        outpoint:        *outpoint,
4✔
264
                        witnessType:     HtlcAcceptedRemoteSuccess,
4✔
265
                        signDesc:        *signDescriptor,
4✔
266
                        heightHint:      heightHint,
4✔
267
                        blockToMaturity: blocksToMaturity,
4✔
268
                },
4✔
269
                preimage: preimage,
4✔
270
        }
4✔
271
}
272

273
// MakeTaprootHtlcSucceedInput creates a new HtlcSucceedInput that can be used
274
// to spend an HTLC output for a taproot channel on the remote party's
275
// commitment transaction.
276
func MakeTaprootHtlcSucceedInput(op *wire.OutPoint, signDesc *SignDescriptor,
277
        preimage []byte, heightHint, blocksToMaturity uint32) HtlcSucceedInput {
278

279
        return HtlcSucceedInput{
1,416✔
280
                inputKit: inputKit{
1,416✔
281
                        outpoint:        *op,
1,416✔
282
                        witnessType:     TaprootHtlcAcceptedRemoteSuccess,
1,416✔
283
                        signDesc:        *signDesc,
1,416✔
284
                        heightHint:      heightHint,
1,416✔
285
                        blockToMaturity: blocksToMaturity,
1,416✔
286
                },
1,416✔
287
                preimage: preimage,
288
        }
289
}
290

291
// CraftInputScript returns a valid set of input scripts allowing this output
292
// to be spent. The returns input scripts should target the input at location
293
// txIndex within the passed transaction. The input scripts generated by this
294
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
295
func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
296
        hashCache *txscript.TxSigHashes,
297
        prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
298
        error) {
299

300
        desc := h.signDesc
301
        desc.SigHashes = hashCache
1✔
302
        desc.InputIndex = txinIdx
1✔
303
        desc.PrevOutputFetcher = prevOutputFetcher
1✔
304

1✔
305
        isTaproot := txscript.IsPayToTaproot(desc.Output.PkScript)
1✔
306

1✔
307
        var (
1✔
308
                witness wire.TxWitness
1✔
309
                err     error
1✔
310
        )
1✔
311
        if isTaproot {
1✔
312
                if desc.ControlBlock == nil {
1✔
313
                        return nil, fmt.Errorf("ctrl block must be set")
1✔
314
                }
315

316
                desc.SignMethod = TaprootScriptSpendSignMethod
317

318
                witness, err = SenderHTLCScriptTaprootRedeem(
319
                        signer, &desc, txn, h.preimage, nil, nil,
UNCOV
320
                )
×
UNCOV
321
        } else {
×
UNCOV
322
                witness, err = SenderHtlcSpendRedeem(
×
UNCOV
323
                        signer, &desc, txn, h.preimage,
×
UNCOV
324
                )
×
UNCOV
325
        }
×
UNCOV
326
        if err != nil {
×
327
                return nil, err
×
328
        }
×
UNCOV
329

×
UNCOV
330
        return &Script{
×
UNCOV
331
                Witness: witness,
×
UNCOV
332
        }, nil
×
333
}
334

335
// HtlcSecondLevelAnchorInput is an input type used to spend HTLC outputs
336
// using a re-signed second level transaction, either via the timeout or success
337
// paths.
338
type HtlcSecondLevelAnchorInput struct {
339
        inputKit
340

UNCOV
341
        // SignedTx is the original second level transaction signed by the
×
UNCOV
342
        // channel peer.
×
UNCOV
343
        SignedTx *wire.MsgTx
×
UNCOV
344

×
UNCOV
345
        // createWitness creates a witness allowing the passed transaction to
×
UNCOV
346
        // spend the input.
×
UNCOV
347
        createWitness func(signer Signer, txn *wire.MsgTx,
×
UNCOV
348
                hashCache *txscript.TxSigHashes,
×
UNCOV
349
                prevOutputFetcher txscript.PrevOutputFetcher,
×
UNCOV
350
                txinIdx int) (wire.TxWitness, error)
×
UNCOV
351
}
×
UNCOV
352

×
UNCOV
353
// RequiredTxOut returns the tx out needed to be present on the sweep tx for
×
UNCOV
354
// the spend of the input to be valid.
×
UNCOV
355
func (i *HtlcSecondLevelAnchorInput) RequiredTxOut() *wire.TxOut {
×
UNCOV
356
        return i.SignedTx.TxOut[0]
×
UNCOV
357
}
×
358

UNCOV
359
// RequiredLockTime returns the locktime needed for the sweep tx for the spend
×
UNCOV
360
// of the input to be valid. For a second level HTLC timeout this will be the
×
UNCOV
361
// CLTV expiry, for HTLC success it will be zero.
×
UNCOV
362
func (i *HtlcSecondLevelAnchorInput) RequiredLockTime() (uint32, bool) {
×
UNCOV
363
        return i.SignedTx.LockTime, true
×
UNCOV
364
}
×
UNCOV
365

×
UNCOV
366
// CraftInputScript returns a valid set of input scripts allowing this output
×
UNCOV
367
// to be spent. The returns input scripts should target the input at location
×
UNCOV
368
// txIndex within the passed transaction. The input scripts generated by this
×
UNCOV
369
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
×
UNCOV
370
func (i *HtlcSecondLevelAnchorInput) CraftInputScript(signer Signer,
×
UNCOV
371
        txn *wire.MsgTx, hashCache *txscript.TxSigHashes,
×
372
        prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
UNCOV
373
        error) {
×
UNCOV
374

×
UNCOV
375
        witness, err := i.createWitness(
×
376
                signer, txn, hashCache, prevOutputFetcher, txinIdx,
377
        )
378
        if err != nil {
379
                return nil, err
380
        }
381

382
        return &Script{
383
                Witness: witness,
384
        }, nil
385
}
386

387
// MakeHtlcSecondLevelTimeoutAnchorInput creates an input allowing the sweeper
388
// to spend the HTLC output on our commit using the second level timeout
389
// transaction.
390
func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
391
        signDetails *SignDetails, heightHint uint32) HtlcSecondLevelAnchorInput {
392

393
        // Spend an HTLC output on our local commitment tx using the
394
        // 2nd timeout transaction.
395
        createWitness := func(signer Signer, txn *wire.MsgTx,
396
                hashCache *txscript.TxSigHashes,
397
                prevOutputFetcher txscript.PrevOutputFetcher,
UNCOV
398
                txinIdx int) (wire.TxWitness, error) {
×
UNCOV
399

×
UNCOV
400
                desc := signDetails.SignDesc
×
401
                desc.SigHashes = txscript.NewTxSigHashes(txn, prevOutputFetcher)
402
                desc.InputIndex = txinIdx
403
                desc.PrevOutputFetcher = prevOutputFetcher
404

UNCOV
405
                return SenderHtlcSpendTimeout(
×
UNCOV
406
                        signDetails.PeerSig, signDetails.SigHashType, signer,
×
UNCOV
407
                        &desc, txn,
×
408
                )
409
        }
410

411
        return HtlcSecondLevelAnchorInput{
412
                inputKit: inputKit{
413
                        outpoint:    signedTx.TxIn[0].PreviousOutPoint,
414
                        witnessType: HtlcOfferedTimeoutSecondLevelInputConfirmed,
415
                        signDesc:    signDetails.SignDesc,
UNCOV
416
                        heightHint:  heightHint,
×
UNCOV
417

×
UNCOV
418
                        // CSV delay is always 1 for these inputs.
×
UNCOV
419
                        blockToMaturity: 1,
×
UNCOV
420
                },
×
UNCOV
421
                SignedTx:      signedTx,
×
UNCOV
422
                createWitness: createWitness,
×
UNCOV
423
        }
×
424
}
UNCOV
425

×
UNCOV
426
// MakeHtlcSecondLevelTimeoutTaprootInput creates an input that allows the
×
UNCOV
427
// sweeper to spend an HTLC output to the second level on our commitment
×
428
// transaction. The sweeper is also able to generate witnesses on demand to
429
// sweep the second level HTLC aggregated with other transactions.
430
func MakeHtlcSecondLevelTimeoutTaprootInput(signedTx *wire.MsgTx,
431
        signDetails *SignDetails,
432
        heightHint uint32) HtlcSecondLevelAnchorInput {
433

434
        createWitness := func(signer Signer, txn *wire.MsgTx,
435
                hashCache *txscript.TxSigHashes,
2✔
436
                prevOutputFetcher txscript.PrevOutputFetcher,
2✔
437
                txinIdx int) (wire.TxWitness, error) {
2✔
438

2✔
439
                desc := signDetails.SignDesc
2✔
440
                if desc.ControlBlock == nil {
2✔
441
                        return nil, fmt.Errorf("ctrl block must be set")
2✔
442
                }
2✔
UNCOV
443

×
UNCOV
444
                desc.SigHashes = txscript.NewTxSigHashes(txn, prevOutputFetcher)
×
UNCOV
445
                desc.InputIndex = txinIdx
×
UNCOV
446
                desc.PrevOutputFetcher = prevOutputFetcher
×
UNCOV
447

×
UNCOV
448
                desc.SignMethod = TaprootScriptSpendSignMethod
×
UNCOV
449

×
UNCOV
450
                return SenderHTLCScriptTaprootTimeout(
×
UNCOV
451
                        signDetails.PeerSig, signDetails.SigHashType, signer,
×
UNCOV
452
                        &desc, txn, nil, nil,
×
UNCOV
453
                )
×
454
        }
455

2✔
456
        return HtlcSecondLevelAnchorInput{
2✔
457
                inputKit: inputKit{
2✔
458
                        outpoint:    signedTx.TxIn[0].PreviousOutPoint,
2✔
459
                        witnessType: TaprootHtlcLocalOfferedTimeout,
2✔
460
                        signDesc:    signDetails.SignDesc,
2✔
461
                        heightHint:  heightHint,
2✔
462

2✔
463
                        // CSV delay is always 1 for these inputs.
2✔
464
                        blockToMaturity: 1,
2✔
465
                },
2✔
466
                SignedTx:      signedTx,
2✔
467
                createWitness: createWitness,
468
        }
469
}
470

471
// MakeHtlcSecondLevelSuccessAnchorInput creates an input allowing the sweeper
472
// to spend the HTLC output on our commit using the second level success
473
// transaction.
474
func MakeHtlcSecondLevelSuccessAnchorInput(signedTx *wire.MsgTx,
UNCOV
475
        signDetails *SignDetails, preimage lntypes.Preimage,
×
UNCOV
476
        heightHint uint32) HtlcSecondLevelAnchorInput {
×
UNCOV
477

×
UNCOV
478
        // Spend an HTLC output on our local commitment tx using the 2nd
×
UNCOV
479
        // success transaction.
×
UNCOV
480
        createWitness := func(signer Signer, txn *wire.MsgTx,
×
UNCOV
481
                hashCache *txscript.TxSigHashes,
×
UNCOV
482
                prevOutputFetcher txscript.PrevOutputFetcher,
×
UNCOV
483
                txinIdx int) (wire.TxWitness, error) {
×
UNCOV
484

×
UNCOV
485
                desc := signDetails.SignDesc
×
486
                desc.SigHashes = hashCache
UNCOV
487
                desc.InputIndex = txinIdx
×
UNCOV
488
                desc.PrevOutputFetcher = prevOutputFetcher
×
UNCOV
489

×
UNCOV
490
                return ReceiverHtlcSpendRedeem(
×
UNCOV
491
                        signDetails.PeerSig, signDetails.SigHashType,
×
UNCOV
492
                        preimage[:], signer, &desc, txn,
×
UNCOV
493
                )
×
UNCOV
494
        }
×
UNCOV
495

×
UNCOV
496
        return HtlcSecondLevelAnchorInput{
×
497
                inputKit: inputKit{
498
                        outpoint:    signedTx.TxIn[0].PreviousOutPoint,
UNCOV
499
                        witnessType: HtlcAcceptedSuccessSecondLevelInputConfirmed,
×
UNCOV
500
                        signDesc:    signDetails.SignDesc,
×
UNCOV
501
                        heightHint:  heightHint,
×
UNCOV
502

×
UNCOV
503
                        // CSV delay is always 1 for these inputs.
×
UNCOV
504
                        blockToMaturity: 1,
×
UNCOV
505
                },
×
UNCOV
506
                SignedTx:      signedTx,
×
UNCOV
507
                createWitness: createWitness,
×
UNCOV
508
        }
×
UNCOV
509
}
×
UNCOV
510

×
511
// MakeHtlcSecondLevelSuccessTaprootInput creates an input that allows the
512
// sweeper to spend an HTLC output to the second level on our taproot
513
// commitment transaction.
514
func MakeHtlcSecondLevelSuccessTaprootInput(signedTx *wire.MsgTx,
515
        signDetails *SignDetails, preimage lntypes.Preimage,
516
        heightHint uint32) HtlcSecondLevelAnchorInput {
517

518
        createWitness := func(signer Signer, txn *wire.MsgTx,
1✔
519
                hashCache *txscript.TxSigHashes,
1✔
520
                prevOutputFetcher txscript.PrevOutputFetcher,
1✔
521
                txinIdx int) (wire.TxWitness, error) {
1✔
522

1✔
523
                desc := signDetails.SignDesc
1✔
524
                if desc.ControlBlock == nil {
1✔
525
                        return nil, fmt.Errorf("ctrl block must be set")
1✔
526
                }
×
UNCOV
527

×
UNCOV
528
                desc.SigHashes = txscript.NewTxSigHashes(txn, prevOutputFetcher)
×
UNCOV
529
                desc.InputIndex = txinIdx
×
UNCOV
530
                desc.PrevOutputFetcher = prevOutputFetcher
×
UNCOV
531

×
UNCOV
532
                desc.SignMethod = TaprootScriptSpendSignMethod
×
UNCOV
533

×
UNCOV
534
                return ReceiverHTLCScriptTaprootRedeem(
×
UNCOV
535
                        signDetails.PeerSig, signDetails.SigHashType,
×
UNCOV
536
                        preimage[:], signer, &desc, txn, nil, nil,
×
537
                )
1✔
538
        }
1✔
539

1✔
540
        return HtlcSecondLevelAnchorInput{
1✔
541
                inputKit: inputKit{
1✔
542
                        outpoint:    signedTx.TxIn[0].PreviousOutPoint,
1✔
543
                        witnessType: TaprootHtlcAcceptedLocalSuccess,
1✔
544
                        signDesc:    signDetails.SignDesc,
1✔
545
                        heightHint:  heightHint,
1✔
546

1✔
547
                        // CSV delay is always 1 for these inputs.
1✔
548
                        blockToMaturity: 1,
1✔
549
                },
550
                SignedTx:      signedTx,
551
                createWitness: createWitness,
552
        }
553
}
554

555
// Compile-time constraints to ensure each input struct implement the Input
UNCOV
556
// interface.
×
UNCOV
557
var _ Input = (*BaseInput)(nil)
×
UNCOV
558
var _ Input = (*HtlcSucceedInput)(nil)
×
UNCOV
559
var _ Input = (*HtlcSecondLevelAnchorInput)(nil)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc