@@ -29,6 +29,17 @@ type taprootBriefcase struct {
2929 // are to be spent via a keyspend path. This includes anchors, and any
3030 // revocation paths.
3131 TapTweaks tlv.RecordT [tlv.TlvType1 , tapTweaks ]
32+
33+ // SettledCommitBlob is an optional record that contains an opaque blob
34+ // that may be used to properly sweep commitment outputs on a force
35+ // close transaction.
36+ SettledCommitBlob tlv.OptionalRecordT [tlv.TlvType2 , tlv.Blob ]
37+
38+ // BreachCommitBlob is an optional record that contains an opaque blob
39+ // used to sweep a remote party's breached output.
40+ BreachedCommitBlob tlv.OptionalRecordT [tlv.TlvType3 , tlv.Blob ]
41+
42+ // TODO(roasbeef): htlc blobs
3243}
3344
3445// TODO(roasbeef): morph into new tlv record
@@ -47,6 +58,18 @@ func (t *taprootBriefcase) EncodeRecords() []tlv.Record {
4758 records := []tlv.Record {
4859 t .CtrlBlocks .Record (), t .TapTweaks .Record (),
4960 }
61+
62+ t .SettledCommitBlob .WhenSome (
63+ func (r tlv.RecordT [tlv.TlvType2 , tlv.Blob ]) {
64+ records = append (records , r .Record ())
65+ },
66+ )
67+ t .BreachedCommitBlob .WhenSome (
68+ func (r tlv.RecordT [tlv.TlvType3 , tlv.Blob ]) {
69+ records = append (records , r .Record ())
70+ },
71+ )
72+
5073 return records
5174}
5275
@@ -69,16 +92,29 @@ func (t *taprootBriefcase) Encode(w io.Writer) error {
6992
7093// Decode decodes the given reader into the target struct.
7194func (t * taprootBriefcase ) Decode (r io.Reader ) error {
72- stream , err := tlv .NewStream (t .DecodeRecords ()... )
95+ settledCommitBlob := t .SettledCommitBlob .Zero ()
96+ breachedCommitBlob := t .BreachedCommitBlob .Zero ()
97+ records := append (
98+ t .DecodeRecords (), settledCommitBlob .Record (),
99+ breachedCommitBlob .Record (),
100+ )
101+ stream , err := tlv .NewStream (records ... )
73102 if err != nil {
74103 return err
75104 }
76105
77- _ , err = stream .DecodeWithParsedTypes (r )
106+ typeMap , err : = stream .DecodeWithParsedTypes (r )
78107 if err != nil {
79108 return err
80109 }
81110
111+ if val , ok := typeMap [t .SettledCommitBlob .TlvType ()]; ok && val == nil {
112+ t .SettledCommitBlob = tlv .SomeRecordT (settledCommitBlob )
113+ }
114+ if v , ok := typeMap [t .BreachedCommitBlob .TlvType ()]; ok && v == nil {
115+ t .BreachedCommitBlob = tlv .SomeRecordT (breachedCommitBlob )
116+ }
117+
82118 return nil
83119}
84120
0 commit comments