routing+channeldb: send payment metadata from invoice
This commit is contained in:
17 files changed
+1580
-1401
No files matched your search
@@ -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)))
|
||||
|
||||
@@ -186,6 +186,7 @@ func TestPayloadSize(t *testing.T) {
|
||||
100000: {1, 2, 3},
|
||||
1000000: {4, 5},
|
||||
},
|
||||
Metadata: []byte{10, 11},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user