Skip to content

Commit 662566c

Browse files
committed
lnwire: add attribution data helpers
We add some simple helpers for the purpose of parsing the attribution data from and to the wire format.
1 parent 56f4fdf commit 662566c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lnwire/attr_data.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package lnwire
2+
3+
import "github.com/lightningnetwork/lnd/tlv"
4+
5+
// AttrDataTlvType is the TlvType that hosts the attribution data in the
6+
// update_fail_htlc wire message.
7+
var AttrDataTlvType tlv.TlvType101
8+
9+
// AttrDataTlvTypeVal is the value of the type of the TLV record for the
10+
// attribution data.
11+
var AttrDataTlvTypeVal = AttrDataTlvType.TypeVal()
12+
13+
// AttrDataToExtraData converts the provided attribution data to the extra
14+
// opaque data to be included in the wire message.
15+
func AttrDataToExtraData(attrData []byte) (ExtraOpaqueData, error) {
16+
attrRecs := make(tlv.TypeMap)
17+
18+
attrType := AttrDataTlvType.TypeVal()
19+
20+
attrRecs[attrType] = attrData
21+
22+
return NewExtraOpaqueData(attrRecs)
23+
}
24+
25+
// ExtraDataToAttrData takes the extra opaque data of the wire message and tries
26+
// to extract the attribution data.
27+
func ExtraDataToAttrData(extraData ExtraOpaqueData) ([]byte, error) {
28+
extraRecords, err := extraData.ExtractRecords()
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
attrType := AttrDataTlvTypeVal
34+
var attrData []byte
35+
if value, ok := extraRecords[attrType]; ok {
36+
attrData = value
37+
}
38+
39+
return attrData, nil
40+
}

0 commit comments

Comments
 (0)