mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
htlcswitch+invoices: log payment metadata
This commit is contained in:
@@ -93,6 +93,10 @@ type Payload struct {
|
||||
// customRecords are user-defined records in the custom type range that
|
||||
// were included in the payload.
|
||||
customRecords record.CustomSet
|
||||
|
||||
// metadata is additional data that is sent along with the payment to
|
||||
// the payee.
|
||||
metadata []byte
|
||||
}
|
||||
|
||||
// NewLegacyPayload builds a Payload from the amount, cltv, and next hop
|
||||
@@ -115,11 +119,12 @@ func NewLegacyPayload(f *sphinx.HopData) *Payload {
|
||||
// should correspond to the bytes encapsulated in a TLV onion payload.
|
||||
func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
var (
|
||||
cid uint64
|
||||
amt uint64
|
||||
cltv uint32
|
||||
mpp = &record.MPP{}
|
||||
amp = &record.AMP{}
|
||||
cid uint64
|
||||
amt uint64
|
||||
cltv uint32
|
||||
mpp = &record.MPP{}
|
||||
amp = &record.AMP{}
|
||||
metadata []byte
|
||||
)
|
||||
|
||||
tlvStream, err := tlv.NewStream(
|
||||
@@ -128,6 +133,7 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
record.NewNextHopIDRecord(&cid),
|
||||
mpp.Record(),
|
||||
amp.Record(),
|
||||
record.NewMetadataRecord(&metadata),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -168,6 +174,12 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
amp = nil
|
||||
}
|
||||
|
||||
// If no metadata field was parsed, set the metadata field on the
|
||||
// resulting payload to nil.
|
||||
if _, ok := parsedTypes[record.MetadataOnionType]; !ok {
|
||||
metadata = nil
|
||||
}
|
||||
|
||||
// Filter out the custom records.
|
||||
customRecords := NewCustomRecords(parsedTypes)
|
||||
|
||||
@@ -180,6 +192,7 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
},
|
||||
MPP: mpp,
|
||||
AMP: amp,
|
||||
metadata: metadata,
|
||||
customRecords: customRecords,
|
||||
}, nil
|
||||
}
|
||||
@@ -284,6 +297,12 @@ func (h *Payload) CustomRecords() record.CustomSet {
|
||||
return h.customRecords
|
||||
}
|
||||
|
||||
// Metadata returns the additional data that is sent along with the
|
||||
// payment to the payee.
|
||||
func (h *Payload) Metadata() []byte {
|
||||
return h.metadata
|
||||
}
|
||||
|
||||
// getMinRequiredViolation checks for unrecognized required (even) fields in the
|
||||
// standard range and returns the lowest required type. Always returning the
|
||||
// lowest required type allows a failure message to be deterministic.
|
||||
|
Reference in New Issue
Block a user