Skip to content

Commit 2f7fc42

Browse files
guggerostarius
authored andcommitted
dump: include close tx, commit sig, commit height
That will add the new data to the output of chantools dumpbackup.
1 parent 51e1bd6 commit 2f7fc42

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

dump/dump.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ type BackupSingle struct {
4545
LocalChanCfg ChannelConfig
4646
RemoteChanCfg ChannelConfig
4747
ShaChainRootDesc KeyDescriptor
48+
CloseTxInputs *CloseTxInputs
49+
}
50+
51+
// CloseTxInputs is a struct that contains data needed to produce a force close
52+
// transaction from a channel backup as a last resort recovery method.
53+
type CloseTxInputs struct {
54+
CommitTx string
55+
CommitSig string
56+
CommitHeight uint64
57+
TapscriptRoot string
4858
}
4959

5060
// 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

Comments
 (0)