lnrpc: report total fees paid

Fixes a bug where only the fees of the last route where reported.
This commit is contained in:
Joost Jager 2020-04-09 16:30:21 +02:00
parent 06f73c0a66
commit e61ff2202d
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -1095,20 +1095,17 @@ func marshallChannelUpdate(update *lnwire.ChannelUpdate) *lnrpc.ChannelUpdate {
func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) ( func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
*lnrpc.Payment, error) { *lnrpc.Payment, error) {
// Fetch the payment's route and preimage. If no HTLC was // Fetch the payment's preimage and the total paid in fees.
// successful, an empty route and preimage will be used.
var ( var (
route route.Route fee lnwire.MilliSatoshi
preimage lntypes.Preimage preimage lntypes.Preimage
) )
for _, htlc := range payment.HTLCs { for _, htlc := range payment.HTLCs {
// Display the last route attempted.
route = htlc.Route
// If any of the htlcs have settled, extract a valid // If any of the htlcs have settled, extract a valid
// preimage. // preimage.
if htlc.Settle != nil { if htlc.Settle != nil {
preimage = htlc.Settle.Preimage preimage = htlc.Settle.Preimage
fee += htlc.Route.TotalFees()
} }
} }
@ -1147,9 +1144,9 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
ValueSat: satValue, ValueSat: satValue,
CreationDate: payment.Info.CreationTime.Unix(), CreationDate: payment.Info.CreationTime.Unix(),
CreationTimeNs: creationTimeNS, CreationTimeNs: creationTimeNS,
Fee: int64(route.TotalFees().ToSatoshis()), Fee: int64(fee.ToSatoshis()),
FeeSat: int64(route.TotalFees().ToSatoshis()), FeeSat: int64(fee.ToSatoshis()),
FeeMsat: int64(route.TotalFees()), FeeMsat: int64(fee),
PaymentPreimage: hex.EncodeToString(preimage[:]), PaymentPreimage: hex.EncodeToString(preimage[:]),
PaymentRequest: string(payment.Info.PaymentRequest), PaymentRequest: string(payment.Info.PaymentRequest),
Status: status, Status: status,