@@ -109,15 +109,16 @@ func filterInvoices(startTime, endTime time.Time,
109109 return filtered
110110}
111111
112- // paymentInfo wraps a lndclient payment struct with a destination, if it is
113- // available from the information we have available, and its settle time.
114- // Since we now allow multi-path payments, a single payment may have multiple
115- // htlcs resolved over a period of time. We use the most recent settle time for
116- // payment because payments are not considered settled until all the htlcs are
117- // resolved.
112+ // paymentInfo wraps a lndclient payment struct with a destination, and
113+ // description if available from the information we have available, and its
114+ // settle time. Since we now allow multi-path payments, a single payment may
115+ // have multiple htlcs resolved over a period of time. We use the most recent
116+ // settle time for payment because payments are not considered settled until
117+ // all the htlcs are resolved.
118118type paymentInfo struct {
119119 lndclient.Payment
120120 destination * route.Vertex
121+ description * string
121122 settleTime time.Time
122123}
123124
@@ -135,24 +136,31 @@ func preProcessPayments(payments []lndclient.Payment,
135136 paymentList := make ([]paymentInfo , len (payments ))
136137
137138 for i , payment := range payments {
138- // Try to get our payment destination from our set of htlcs.
139- // If we cannot get it from our htlcs (which is the case for
140- // legacy payments that did not store htlcs), we try to get it
141- // from our payment request. This value may not be present for
142- // all payments, so we do not error if it is not.
139+ // Attempt to obtain the payment destination and description
140+ // from our payment request. If this is not possible (which
141+ // can be the case for legacy payments that did not store
142+ // payment requests, or payments that pay directly to a
143+ // payment hash), then try to get it from our HTLCs. Note
144+ // that HTLCs may also not be available for legacy payments
145+ // that did not store HTLCs. In the event that we get a
146+ // destination from both sources, we prefer the destination
147+ // from the HTLCs.
148+ payReqDestination , description , err := paymentRequestDetails (
149+ payment .PaymentRequest , decode ,
150+ )
151+ if err != nil && err != errNoPaymentRequest {
152+ return nil , err
153+ }
154+
143155 destination , err := paymentHtlcDestination (payment )
144156 if err != nil {
145- destination , err = paymentRequestDestination (
146- payment .PaymentRequest , decode ,
147- )
148- if err != nil && err != errNoPaymentRequest {
149- return nil , err
150- }
157+ destination = payReqDestination
151158 }
152159
153160 pmt := paymentInfo {
154161 Payment : payment ,
155162 destination : destination ,
163+ description : description ,
156164 }
157165
158166 // If the payment did not succeed, we can add it to our list
@@ -212,21 +220,23 @@ func paymentHtlcDestination(payment lndclient.Payment) (*route.Vertex, error) {
212220 return & lastHopPubkey , nil
213221}
214222
215- // paymentRequestDestination attempts to decode a payment address, and returns
216- // the destination.
217- func paymentRequestDestination (paymentRequest string ,
218- decode decodePaymentRequest ) (* route.Vertex , error ) {
223+ // paymentRequestDetails attempts to decode a payment address, and returns
224+ // the destination and the description .
225+ func paymentRequestDetails (paymentRequest string ,
226+ decode decodePaymentRequest ) (* route.Vertex , * string , error ) {
219227
220228 if paymentRequest == "" {
221- return nil , errNoPaymentRequest
229+ return nil , nil , errNoPaymentRequest
222230 }
223231
224232 payReq , err := decode (paymentRequest )
225233 if err != nil {
226- return nil , fmt .Errorf ("decode payment request failed: %w" , err )
234+ return nil , nil , fmt .Errorf (
235+ "decode payment request failed: %w" , err ,
236+ )
227237 }
228238
229- return & payReq .Destination , nil
239+ return & payReq .Destination , & payReq . Description , nil
230240}
231241
232242// filterPayments filters out unsuccessful payments and those which did not
0 commit comments