@@ -156,6 +156,18 @@ func (i *inputKit) UnconfParent() *TxInfo {
156156 return i .unconfParent
157157}
158158
159+ // inputOpts holds options for the input.
160+ type inputOpts struct {
161+ }
162+
163+ // defaultInputOpts returns a new inputOpts with default values.
164+ func defaultInputOpts () * inputOpts {
165+ return & inputOpts {}
166+ }
167+
168+ // InputOpt is a functional option argument to the input constructor.
169+ type InputOpt func (* inputOpts ) //nolint:revive
170+
159171// BaseInput contains all the information needed to sweep a basic
160172// output (CSV/CLTV/no time lock).
161173type BaseInput struct {
@@ -166,7 +178,12 @@ type BaseInput struct {
166178// sweep transaction.
167179func MakeBaseInput (outpoint * wire.OutPoint , witnessType WitnessType ,
168180 signDescriptor * SignDescriptor , heightHint uint32 ,
169- unconfParent * TxInfo ) BaseInput {
181+ unconfParent * TxInfo , opts ... InputOpt ) BaseInput {
182+
183+ opt := defaultInputOpts ()
184+ for _ , optF := range opts {
185+ optF (opt )
186+ }
170187
171188 return BaseInput {
172189 inputKit {
@@ -182,10 +199,11 @@ func MakeBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
182199// NewBaseInput allocates and assembles a new *BaseInput that can be used to
183200// construct a sweep transaction.
184201func NewBaseInput (outpoint * wire.OutPoint , witnessType WitnessType ,
185- signDescriptor * SignDescriptor , heightHint uint32 ) * BaseInput {
202+ signDescriptor * SignDescriptor , heightHint uint32 ,
203+ opts ... InputOpt ) * BaseInput {
186204
187205 input := MakeBaseInput (
188- outpoint , witnessType , signDescriptor , heightHint , nil ,
206+ outpoint , witnessType , signDescriptor , heightHint , nil , opts ... ,
189207 )
190208
191209 return & input
@@ -195,36 +213,31 @@ func NewBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
195213// construct a sweep transaction.
196214func NewCsvInput (outpoint * wire.OutPoint , witnessType WitnessType ,
197215 signDescriptor * SignDescriptor , heightHint uint32 ,
198- blockToMaturity uint32 ) * BaseInput {
216+ blockToMaturity uint32 , opts ... InputOpt ) * BaseInput {
199217
200- return & BaseInput {
201- inputKit {
202- outpoint : * outpoint ,
203- witnessType : witnessType ,
204- signDesc : * signDescriptor ,
205- heightHint : heightHint ,
206- blockToMaturity : blockToMaturity ,
207- },
208- }
218+ input := MakeBaseInput (
219+ outpoint , witnessType , signDescriptor , heightHint , nil , opts ... ,
220+ )
221+
222+ input .blockToMaturity = blockToMaturity
223+
224+ return & input
209225}
210226
211227// NewCsvInputWithCltv assembles a new csv and cltv locked input that can be
212228// used to construct a sweep transaction.
213229func NewCsvInputWithCltv (outpoint * wire.OutPoint , witnessType WitnessType ,
214230 signDescriptor * SignDescriptor , heightHint uint32 ,
215- csvDelay uint32 , cltvExpiry uint32 ) * BaseInput {
231+ csvDelay uint32 , cltvExpiry uint32 , opts ... InputOpt ) * BaseInput {
216232
217- return & BaseInput {
218- inputKit {
219- outpoint : * outpoint ,
220- witnessType : witnessType ,
221- signDesc : * signDescriptor ,
222- heightHint : heightHint ,
223- blockToMaturity : csvDelay ,
224- cltvExpiry : cltvExpiry ,
225- unconfParent : nil ,
226- },
227- }
233+ input := MakeBaseInput (
234+ outpoint , witnessType , signDescriptor , heightHint , nil , opts ... ,
235+ )
236+
237+ input .blockToMaturity = csvDelay
238+ input .cltvExpiry = cltvExpiry
239+
240+ return & input
228241}
229242
230243// CraftInputScript returns a valid set of input scripts allowing this output
@@ -256,16 +269,16 @@ type HtlcSucceedInput struct {
256269// construct a sweep transaction.
257270func MakeHtlcSucceedInput (outpoint * wire.OutPoint ,
258271 signDescriptor * SignDescriptor , preimage []byte , heightHint ,
259- blocksToMaturity uint32 ) HtlcSucceedInput {
272+ blocksToMaturity uint32 , opts ... InputOpt ) HtlcSucceedInput {
273+
274+ input := MakeBaseInput (
275+ outpoint , HtlcAcceptedRemoteSuccess , signDescriptor ,
276+ heightHint , nil , opts ... ,
277+ )
278+ input .blockToMaturity = blocksToMaturity
260279
261280 return HtlcSucceedInput {
262- inputKit : inputKit {
263- outpoint : * outpoint ,
264- witnessType : HtlcAcceptedRemoteSuccess ,
265- signDesc : * signDescriptor ,
266- heightHint : heightHint ,
267- blockToMaturity : blocksToMaturity ,
268- },
281+ inputKit : input .inputKit ,
269282 preimage : preimage ,
270283 }
271284}
@@ -274,16 +287,17 @@ func MakeHtlcSucceedInput(outpoint *wire.OutPoint,
274287// to spend an HTLC output for a taproot channel on the remote party's
275288// commitment transaction.
276289func MakeTaprootHtlcSucceedInput (op * wire.OutPoint , signDesc * SignDescriptor ,
277- preimage []byte , heightHint , blocksToMaturity uint32 ) HtlcSucceedInput {
290+ preimage []byte , heightHint , blocksToMaturity uint32 ,
291+ opts ... InputOpt ) HtlcSucceedInput {
292+
293+ input := MakeBaseInput (
294+ op , TaprootHtlcAcceptedRemoteSuccess , signDesc ,
295+ heightHint , nil , opts ... ,
296+ )
297+ input .blockToMaturity = blocksToMaturity
278298
279299 return HtlcSucceedInput {
280- inputKit : inputKit {
281- outpoint : * op ,
282- witnessType : TaprootHtlcAcceptedRemoteSuccess ,
283- signDesc : * signDesc ,
284- heightHint : heightHint ,
285- blockToMaturity : blocksToMaturity ,
286- },
300+ inputKit : input .inputKit ,
287301 preimage : preimage ,
288302 }
289303}
@@ -388,7 +402,8 @@ func (i *HtlcSecondLevelAnchorInput) CraftInputScript(signer Signer,
388402// to spend the HTLC output on our commit using the second level timeout
389403// transaction.
390404func MakeHtlcSecondLevelTimeoutAnchorInput (signedTx * wire.MsgTx ,
391- signDetails * SignDetails , heightHint uint32 ) HtlcSecondLevelAnchorInput {
405+ signDetails * SignDetails , heightHint uint32 ,
406+ opts ... InputOpt ) HtlcSecondLevelAnchorInput {
392407
393408 // Spend an HTLC output on our local commitment tx using the
394409 // 2nd timeout transaction.
@@ -408,16 +423,15 @@ func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
408423 )
409424 }
410425
426+ input := MakeBaseInput (
427+ & signedTx .TxIn [0 ].PreviousOutPoint ,
428+ HtlcOfferedTimeoutSecondLevelInputConfirmed ,
429+ & signDetails .SignDesc , heightHint , nil , opts ... ,
430+ )
431+ input .blockToMaturity = 1
432+
411433 return HtlcSecondLevelAnchorInput {
412- inputKit : inputKit {
413- outpoint : signedTx .TxIn [0 ].PreviousOutPoint ,
414- witnessType : HtlcOfferedTimeoutSecondLevelInputConfirmed ,
415- signDesc : signDetails .SignDesc ,
416- heightHint : heightHint ,
417-
418- // CSV delay is always 1 for these inputs.
419- blockToMaturity : 1 ,
420- },
434+ inputKit : input .inputKit ,
421435 SignedTx : signedTx ,
422436 createWitness : createWitness ,
423437 }
@@ -429,7 +443,7 @@ func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
429443// sweep the second level HTLC aggregated with other transactions.
430444func MakeHtlcSecondLevelTimeoutTaprootInput (signedTx * wire.MsgTx ,
431445 signDetails * SignDetails ,
432- heightHint uint32 ) HtlcSecondLevelAnchorInput {
446+ heightHint uint32 , opts ... InputOpt ) HtlcSecondLevelAnchorInput {
433447
434448 createWitness := func (signer Signer , txn * wire.MsgTx ,
435449 hashCache * txscript.TxSigHashes ,
@@ -453,16 +467,15 @@ func MakeHtlcSecondLevelTimeoutTaprootInput(signedTx *wire.MsgTx,
453467 )
454468 }
455469
470+ input := MakeBaseInput (
471+ & signedTx .TxIn [0 ].PreviousOutPoint ,
472+ TaprootHtlcLocalOfferedTimeout ,
473+ & signDetails .SignDesc , heightHint , nil , opts ... ,
474+ )
475+ input .blockToMaturity = 1
476+
456477 return HtlcSecondLevelAnchorInput {
457- inputKit : inputKit {
458- outpoint : signedTx .TxIn [0 ].PreviousOutPoint ,
459- witnessType : TaprootHtlcLocalOfferedTimeout ,
460- signDesc : signDetails .SignDesc ,
461- heightHint : heightHint ,
462-
463- // CSV delay is always 1 for these inputs.
464- blockToMaturity : 1 ,
465- },
478+ inputKit : input .inputKit ,
466479 SignedTx : signedTx ,
467480 createWitness : createWitness ,
468481 }
@@ -473,7 +486,7 @@ func MakeHtlcSecondLevelTimeoutTaprootInput(signedTx *wire.MsgTx,
473486// transaction.
474487func MakeHtlcSecondLevelSuccessAnchorInput (signedTx * wire.MsgTx ,
475488 signDetails * SignDetails , preimage lntypes.Preimage ,
476- heightHint uint32 ) HtlcSecondLevelAnchorInput {
489+ heightHint uint32 , opts ... InputOpt ) HtlcSecondLevelAnchorInput {
477490
478491 // Spend an HTLC output on our local commitment tx using the 2nd
479492 // success transaction.
@@ -492,18 +505,16 @@ func MakeHtlcSecondLevelSuccessAnchorInput(signedTx *wire.MsgTx,
492505 preimage [:], signer , & desc , txn ,
493506 )
494507 }
508+ input := MakeBaseInput (
509+ & signedTx .TxIn [0 ].PreviousOutPoint ,
510+ HtlcAcceptedSuccessSecondLevelInputConfirmed ,
511+ & signDetails .SignDesc , heightHint , nil , opts ... ,
512+ )
513+ input .blockToMaturity = 1
495514
496515 return HtlcSecondLevelAnchorInput {
497- inputKit : inputKit {
498- outpoint : signedTx .TxIn [0 ].PreviousOutPoint ,
499- witnessType : HtlcAcceptedSuccessSecondLevelInputConfirmed ,
500- signDesc : signDetails .SignDesc ,
501- heightHint : heightHint ,
502-
503- // CSV delay is always 1 for these inputs.
504- blockToMaturity : 1 ,
505- },
506516 SignedTx : signedTx ,
517+ inputKit : input .inputKit ,
507518 createWitness : createWitness ,
508519 }
509520}
@@ -513,7 +524,7 @@ func MakeHtlcSecondLevelSuccessAnchorInput(signedTx *wire.MsgTx,
513524// commitment transaction.
514525func MakeHtlcSecondLevelSuccessTaprootInput (signedTx * wire.MsgTx ,
515526 signDetails * SignDetails , preimage lntypes.Preimage ,
516- heightHint uint32 ) HtlcSecondLevelAnchorInput {
527+ heightHint uint32 , opts ... InputOpt ) HtlcSecondLevelAnchorInput {
517528
518529 createWitness := func (signer Signer , txn * wire.MsgTx ,
519530 hashCache * txscript.TxSigHashes ,
@@ -537,16 +548,15 @@ func MakeHtlcSecondLevelSuccessTaprootInput(signedTx *wire.MsgTx,
537548 )
538549 }
539550
551+ input := MakeBaseInput (
552+ & signedTx .TxIn [0 ].PreviousOutPoint ,
553+ TaprootHtlcAcceptedLocalSuccess ,
554+ & signDetails .SignDesc , heightHint , nil , opts ... ,
555+ )
556+ input .blockToMaturity = 1
557+
540558 return HtlcSecondLevelAnchorInput {
541- inputKit : inputKit {
542- outpoint : signedTx .TxIn [0 ].PreviousOutPoint ,
543- witnessType : TaprootHtlcAcceptedLocalSuccess ,
544- signDesc : signDetails .SignDesc ,
545- heightHint : heightHint ,
546-
547- // CSV delay is always 1 for these inputs.
548- blockToMaturity : 1 ,
549- },
559+ inputKit : input .inputKit ,
550560 SignedTx : signedTx ,
551561 createWitness : createWitness ,
552562 }
0 commit comments