Skip to content

Commit

Permalink
Include outgoing payment description in audit memo
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Feb 9, 2024
1 parent 256bde5 commit b362314
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
19 changes: 15 additions & 4 deletions accounting/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,22 @@ func paymentReference(sequenceNumber uint64, preimage lntypes.Preimage) string {

// paymentNote creates a note for payments from our node.
// nolint: interfacer
func paymentNote(dest *route.Vertex) string {
if dest == nil {
func paymentNote(dest *route.Vertex, memo *string) string {
var notes []string

if memo != nil && *memo != "" {
notes = append(notes, fmt.Sprintf("memo: %v", *memo))
}

if dest != nil {
notes = append(notes, fmt.Sprintf("destination: %v", dest))
}

if len(notes) == 0 {
return ""
}
return dest.String()

return strings.Join(notes, "/")
}

// paymentEntry creates an entry for an off chain payment, including fee entries
Expand All @@ -432,7 +443,7 @@ func paymentEntry(payment paymentInfo, paidToSelf bool,

// Create a note for our payment. Since we have already checked that our
// payment is settled, we will not have a nil preimage.
note := paymentNote(payment.destination)
note := paymentNote(payment.destination, payment.description)
ref := paymentReference(payment.SequenceNumber, *payment.Preimage)

// Payment values are expressed as positive values over rpc, but they
Expand Down
41 changes: 35 additions & 6 deletions accounting/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ func filterInvoices(startTime, endTime time.Time,
return filtered
}

// paymentInfo wraps a lndclient payment struct with a destination, if it is
// available from the information we have available, and its settle time.
// Since we now allow multi-path payments, a single payment may have multiple
// htlcs resolved over a period of time. We use the most recent settle time for
// payment because payments are not considered settled until all the htlcs are
// resolved.
// paymentInfo wraps a lndclient payment struct with a destination, and
// description if available from the information we have available, and its
// settle time. Since we now allow multi-path payments, a single payment may
// have multiple htlcs resolved over a period of time. We use the most recent
// settle time for payment because payments are not considered settled until
// all the htlcs are resolved.
type paymentInfo struct {
lndclient.Payment
destination *route.Vertex
description *string
settleTime time.Time
}

Expand Down Expand Up @@ -150,9 +151,20 @@ func preProcessPayments(payments []lndclient.Payment,
}
}

// Try to get our payment description from our payment request
// This value may not be present for all payments, so we do not
// error if it is not.
description, err := paymentRequestDescription(
payment.PaymentRequest, decode,
)
if err != nil && err != errNoPaymentRequest {
return nil, err
}

pmt := paymentInfo{
Payment: payment,
destination: destination,
description: description,
}

// If the payment did not succeed, we can add it to our list
Expand Down Expand Up @@ -229,6 +241,23 @@ func paymentRequestDestination(paymentRequest string,
return &payReq.Destination, nil
}

// paymentRequestDescription attempts to decode a payment address, and returns
// the description.
func paymentRequestDescription(paymentRequest string,
decode decodePaymentRequest) (*string, error) {

if paymentRequest == "" {
return nil, errNoPaymentRequest
}

payReq, err := decode(paymentRequest)
if err != nil {
return nil, fmt.Errorf("decode payment request failed: %w", err)
}

return &payReq.Description, nil
}

// filterPayments filters out unsuccessful payments and those which did not
// occur within the range we specify.
func filterPayments(startTime, endTime time.Time,
Expand Down

0 comments on commit b362314

Please sign in to comment.