@@ -69,6 +69,9 @@ type Input interface {
6969 // ResolutionBlob returns a special opaque blob to be used to
7070 // sweep/resolve this input.
7171 ResolutionBlob () fn.Option [tlv.Blob ]
72+
73+ // Preimage returns the preimage for the input if it is an HTLC input.
74+ Preimage () fn.Option [lntypes.Preimage ]
7275}
7376
7477// TxInfo describes properties of a parent tx that are relevant for CPFP.
@@ -285,6 +288,11 @@ func (bi *BaseInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
285288 return witnessFunc (txn , hashCache , txinIdx )
286289}
287290
291+ // Preimage returns the preimage for the input if it is an HTLC input.
292+ func (bi * BaseInput ) Preimage () fn.Option [lntypes.Preimage ] {
293+ return fn .None [lntypes.Preimage ]()
294+ }
295+
288296// HtlcSucceedInput constitutes a sweep input that needs a pre-image. The input
289297// is expected to reside on the commitment tx of the remote party and should
290298// not be a second level tx output.
@@ -357,7 +365,6 @@ func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
357365 }
358366
359367 desc .SignMethod = TaprootScriptSpendSignMethod
360-
361368 witness , err = SenderHTLCScriptTaprootRedeem (
362369 signer , & desc , txn , h .preimage , nil , nil ,
363370 )
@@ -375,6 +382,15 @@ func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
375382 }, nil
376383}
377384
385+ // Preimage returns the preimage for the input if it is an HTLC input.
386+ func (h * HtlcSucceedInput ) Preimage () fn.Option [lntypes.Preimage ] {
387+ if len (h .preimage ) == 0 {
388+ return fn .None [lntypes.Preimage ]()
389+ }
390+
391+ return fn .Some (lntypes .Preimage (h .preimage ))
392+ }
393+
378394// HtlcSecondLevelAnchorInput is an input type used to spend HTLC outputs
379395// using a re-signed second level transaction, either via the timeout or success
380396// paths.
@@ -391,6 +407,8 @@ type HtlcSecondLevelAnchorInput struct {
391407 hashCache * txscript.TxSigHashes ,
392408 prevOutputFetcher txscript.PrevOutputFetcher ,
393409 txinIdx int ) (wire.TxWitness , error )
410+
411+ preimage []byte
394412}
395413
396414// RequiredTxOut returns the tx out needed to be present on the sweep tx for
@@ -427,6 +445,15 @@ func (i *HtlcSecondLevelAnchorInput) CraftInputScript(signer Signer,
427445 }, nil
428446}
429447
448+ // Preimage returns the preimage for the input if it is an HTLC input.
449+ func (i * HtlcSecondLevelAnchorInput ) Preimage () fn.Option [lntypes.Preimage ] {
450+ if len (i .preimage ) == 0 {
451+ return fn .None [lntypes.Preimage ]()
452+ }
453+
454+ return fn .Some (lntypes .Preimage (i .preimage ))
455+ }
456+
430457// MakeHtlcSecondLevelTimeoutAnchorInput creates an input allowing the sweeper
431458// to spend the HTLC output on our commit using the second level timeout
432459// transaction.
@@ -545,6 +572,7 @@ func MakeHtlcSecondLevelSuccessAnchorInput(signedTx *wire.MsgTx,
545572 SignedTx : signedTx ,
546573 inputKit : input .inputKit ,
547574 createWitness : createWitness ,
575+ preimage : preimage [:],
548576 }
549577}
550578
@@ -588,6 +616,7 @@ func MakeHtlcSecondLevelSuccessTaprootInput(signedTx *wire.MsgTx,
588616 inputKit : input .inputKit ,
589617 SignedTx : signedTx ,
590618 createWitness : createWitness ,
619+ preimage : preimage [:],
591620 }
592621}
593622
0 commit comments