routing+channeldb: send payment metadata from invoice

This commit is contained in:
Joost Jager committed 2022-04-13 22:55:40 +02:00
1 parent 135e27ddd3
commit 9195f29e61
17 files changed
+1580 -1401

No files matched your search

+16
View File
@@ -127,6 +127,10 @@ type Hop struct {
// understand the new TLV payload, so we must instead use the legacy
// payload.
LegacyPayload bool
// Metadata is additional data that is sent along with the payment to
// the payee.
Metadata []byte
}
// Copy returns a deep copy of the Hop.
@@ -205,6 +209,13 @@ func (h *Hop) PackHopPayload(w io.Writer, nextChanID uint64) error {
}
}
// If metadata is specified, generate a tlv record for it.
if h.Metadata != nil {
records = append(records,
record.NewMetadataRecord(&h.Metadata),
)
}
// Append any custom types destined for this hop.
tlvRecords := tlv.MapToRecords(h.CustomRecords)
records = append(records, tlvRecords...)
@@ -259,6 +270,11 @@ func (h *Hop) PayloadSize(nextChanID uint64) uint64 {
addRecord(record.AMPOnionType, h.AMP.PayloadSize())
}
// Add metadata if present.
if h.Metadata != nil {
addRecord(record.MetadataOnionType, uint64(len(h.Metadata)))
}
// Add custom records.
for k, v := range h.CustomRecords {
addRecord(tlv.Type(k), uint64(len(v)))
+1
View File
@@ -186,6 +186,7 @@ func TestPayloadSize(t *testing.T) {
100000: {1, 2, 3},
1000000: {4, 5},
},
Metadata: []byte{10, 11},
},
}