@@ -46,6 +46,16 @@ type BackupSingle struct {
4646 LocalChanCfg ChannelConfig
4747 RemoteChanCfg ChannelConfig
4848 ShaChainRootDesc KeyDescriptor
49+ CloseTxInputs * CloseTxInputs
50+ }
51+
52+ // CloseTxInputs is a struct that contains data needed to produce a force close
53+ // transaction from a channel backup as a last resort recovery method.
54+ type CloseTxInputs struct {
55+ CommitTx string
56+ CommitSig string
57+ CommitHeight uint64
58+ TapscriptRoot string
4959}
5060
5161// OpenChannel is the information we want to dump from an open channel in lnd's
@@ -406,7 +416,40 @@ func BackupDump(multi *chanbackup.Multi,
406416 params , single .ShaChainRootDesc ,
407417 ),
408418 }
419+
420+ single .CloseTxInputs .WhenSome (
421+ func (inputs chanbackup.CloseTxInputs ) {
422+ // Serialize unsigned transaction.
423+ var buf bytes.Buffer
424+ err := inputs .CommitTx .Serialize (& buf )
425+ if err != nil {
426+ buf .WriteString ("error serializing " +
427+ "commit tx: " + err .Error ())
428+ }
429+ tx := buf .Bytes ()
430+
431+ // Serialize TapscriptRoot if present.
432+ var tapscriptRoot string
433+ inputs .TapscriptRoot .WhenSome (
434+ func (tr chainhash.Hash ) {
435+ tapscriptRoot = tr .String ()
436+ },
437+ )
438+
439+ // Put all CloseTxInputs to dump in human
440+ // readable form.
441+ dumpSingles [idx ].CloseTxInputs = & CloseTxInputs {
442+ CommitTx : hex .EncodeToString (tx ),
443+ CommitSig : hex .EncodeToString (
444+ inputs .CommitSig ,
445+ ),
446+ CommitHeight : inputs .CommitHeight ,
447+ TapscriptRoot : tapscriptRoot ,
448+ }
449+ },
450+ )
409451 }
452+
410453 return dumpSingles
411454}
412455
0 commit comments