lnrpc: use queried payments to list payments in the rpc

Changes the grpc proto file, generates the protobuf, and
enables a queried way to retrieve payments in the rpc, where
backward compatibility is enforced by returning all payments
in the database by default. Adds a payment index field to
the returned payments of the rpc call.
This commit is contained in:
bitromortac
2020-01-17 07:35:03 +01:00
parent d5dd48fa71
commit 39c58d9d14
4 changed files with 930 additions and 766 deletions

View File

@ -5153,26 +5153,37 @@ func marshallTopologyChange(topChange *routing.TopologyChange) *lnrpc.GraphTopol
}
}
// ListPayments returns a list of all outgoing payments.
// ListPayments returns a list of outgoing payments determined by a paginated
// database query.
func (r *rpcServer) ListPayments(ctx context.Context,
req *lnrpc.ListPaymentsRequest) (*lnrpc.ListPaymentsResponse, error) {
rpcsLog.Debugf("[ListPayments]")
payments, err := r.server.chanDB.FetchPayments()
query := channeldb.PaymentsQuery{
IndexOffset: req.IndexOffset,
MaxPayments: req.MaxPayments,
Reversed: req.Reversed,
IncludeIncomplete: req.IncludeIncomplete,
}
// If the maximum number of payments wasn't specified, then we'll
// default to return the maximal number of payments representable.
if req.MaxPayments == 0 {
query.MaxPayments = math.MaxUint64
}
paymentsQuerySlice, err := r.server.chanDB.QueryPayments(query)
if err != nil {
return nil, err
}
paymentsResp := &lnrpc.ListPaymentsResponse{}
for _, payment := range payments {
// To keep compatibility with the old API, we only return
// non-suceeded payments if requested.
if payment.Status != channeldb.StatusSucceeded &&
!req.IncludeIncomplete {
continue
}
paymentsResp := &lnrpc.ListPaymentsResponse{
LastIndexOffset: paymentsQuerySlice.LastIndexOffset,
FirstIndexOffset: paymentsQuerySlice.FirstIndexOffset,
}
for _, payment := range paymentsQuerySlice.Payments {
// Fetch the payment's route and preimage. If no HTLC was
// successful, an empty route and preimage will be used.
var (
@ -5231,6 +5242,7 @@ func (r *rpcServer) ListPayments(ctx context.Context,
PaymentRequest: string(payment.Info.PaymentRequest),
Status: status,
Htlcs: htlcs,
PaymentIndex: payment.SequenceNum,
})
}