Merge pull request #3190 from halseth/listpayments-status-filter
ListPayments: filter out non-succeeded payments, include payment status
This commit is contained in:
6 files changed
+631
-493
No files matched your search
+541
-485
File diff suppressed because it is too large.
Load diff
@@ -558,10 +558,18 @@ func request_Lightning_DecodePayReq_0(ctx context.Context, marshaler runtime.Mar
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
filter_Lightning_ListPayments_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||||
|
)
|
||||||
|
|
||||||
func request_Lightning_ListPayments_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
func request_Lightning_ListPayments_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
var protoReq ListPaymentsRequest
|
var protoReq ListPaymentsRequest
|
||||||
var metadata runtime.ServerMetadata
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Lightning_ListPayments_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
msg, err := client.ListPayments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
msg, err := client.ListPayments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
|
|
||||||
|
|||||||
@@ -2158,9 +2158,21 @@ message Payment {
|
|||||||
|
|
||||||
/// The optional payment request being fulfilled.
|
/// The optional payment request being fulfilled.
|
||||||
string payment_request = 9 [json_name = "payment_request"];
|
string payment_request = 9 [json_name = "payment_request"];
|
||||||
|
|
||||||
|
enum PaymentStatus {
|
||||||
|
UNKNOWN = 0;
|
||||||
|
IN_FLIGHT = 1;
|
||||||
|
SUCCEEDED = 2;
|
||||||
|
FAILED = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The status of the payment.
|
||||||
|
PaymentStatus status = 10 [json_name = "status"];
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListPaymentsRequest {
|
message ListPaymentsRequest {
|
||||||
|
/// Set to also return payments that are not (yet) succeeded.
|
||||||
|
bool non_succeeded = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListPaymentsResponse {
|
message ListPaymentsResponse {
|
||||||
|
|||||||
@@ -938,6 +938,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "non_succeeded",
|
||||||
|
"description": "/ Set to also return payments that are not (yet) succeeded.",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"type": "boolean",
|
||||||
|
"format": "boolean"
|
||||||
|
}
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Lightning"
|
"Lightning"
|
||||||
]
|
]
|
||||||
@@ -1297,6 +1307,16 @@
|
|||||||
],
|
],
|
||||||
"default": "OPEN"
|
"default": "OPEN"
|
||||||
},
|
},
|
||||||
|
"PaymentPaymentStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"UNKNOWN",
|
||||||
|
"IN_FLIGHT",
|
||||||
|
"SUCCEEDED",
|
||||||
|
"FAILED"
|
||||||
|
],
|
||||||
|
"default": "UNKNOWN"
|
||||||
|
},
|
||||||
"PeerSyncType": {
|
"PeerSyncType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -2835,6 +2855,10 @@
|
|||||||
"payment_request": {
|
"payment_request": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "/ The optional payment request being fulfilled."
|
"description": "/ The optional payment request being fulfilled."
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"$ref": "#/definitions/PaymentPaymentStatus",
|
||||||
|
"description": "The status of the payment."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13281,7 +13281,9 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// The payments should now show up in Alice's ListInvoices, with a zero
|
// The payments should now show up in Alice's ListInvoices, with a zero
|
||||||
// preimage, indicating they are not yet settled.
|
// preimage, indicating they are not yet settled.
|
||||||
err = lntest.WaitNoError(func() error {
|
err = lntest.WaitNoError(func() error {
|
||||||
req := &lnrpc.ListPaymentsRequest{}
|
req := &lnrpc.ListPaymentsRequest{
|
||||||
|
NonSucceeded: true,
|
||||||
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||||
paymentsResp, err := net.Alice.ListPayments(ctxt, req)
|
paymentsResp, err := net.Alice.ListPayments(ctxt, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -13458,7 +13460,9 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Check that Alice's invoices to be shown as settled and failed
|
// Check that Alice's invoices to be shown as settled and failed
|
||||||
// accordingly, and preimages matching up.
|
// accordingly, and preimages matching up.
|
||||||
req := &lnrpc.ListPaymentsRequest{}
|
req := &lnrpc.ListPaymentsRequest{
|
||||||
|
NonSucceeded: true,
|
||||||
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||||
paymentsResp, err := net.Alice.ListPayments(ctxt, req)
|
paymentsResp, err := net.Alice.ListPayments(ctxt, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+40
-6
@@ -4131,7 +4131,7 @@ func marshallTopologyChange(topChange *routing.TopologyChange) *lnrpc.GraphTopol
|
|||||||
|
|
||||||
// ListPayments returns a list of all outgoing payments.
|
// ListPayments returns a list of all outgoing payments.
|
||||||
func (r *rpcServer) ListPayments(ctx context.Context,
|
func (r *rpcServer) ListPayments(ctx context.Context,
|
||||||
_ *lnrpc.ListPaymentsRequest) (*lnrpc.ListPaymentsResponse, error) {
|
req *lnrpc.ListPaymentsRequest) (*lnrpc.ListPaymentsResponse, error) {
|
||||||
|
|
||||||
rpcsLog.Debugf("[ListPayments]")
|
rpcsLog.Debugf("[ListPayments]")
|
||||||
|
|
||||||
@@ -4140,10 +4140,15 @@ func (r *rpcServer) ListPayments(ctx context.Context,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
paymentsResp := &lnrpc.ListPaymentsResponse{
|
paymentsResp := &lnrpc.ListPaymentsResponse{}
|
||||||
Payments: make([]*lnrpc.Payment, len(payments)),
|
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.NonSucceeded {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
for i, payment := range payments {
|
|
||||||
// If a payment attempt has been made we can fetch the route.
|
// If a payment attempt has been made we can fetch the route.
|
||||||
// Otherwise we'll just populate the RPC response with an empty
|
// Otherwise we'll just populate the RPC response with an empty
|
||||||
// one.
|
// one.
|
||||||
@@ -4165,8 +4170,13 @@ func (r *rpcServer) ListPayments(ctx context.Context,
|
|||||||
msatValue := int64(payment.Info.Value)
|
msatValue := int64(payment.Info.Value)
|
||||||
satValue := int64(payment.Info.Value.ToSatoshis())
|
satValue := int64(payment.Info.Value.ToSatoshis())
|
||||||
|
|
||||||
|
status, err := convertPaymentStatus(payment.Status)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
paymentHash := payment.Info.PaymentHash
|
paymentHash := payment.Info.PaymentHash
|
||||||
paymentsResp.Payments[i] = &lnrpc.Payment{
|
paymentsResp.Payments = append(paymentsResp.Payments, &lnrpc.Payment{
|
||||||
PaymentHash: hex.EncodeToString(paymentHash[:]),
|
PaymentHash: hex.EncodeToString(paymentHash[:]),
|
||||||
Value: satValue,
|
Value: satValue,
|
||||||
ValueMsat: msatValue,
|
ValueMsat: msatValue,
|
||||||
@@ -4176,12 +4186,36 @@ func (r *rpcServer) ListPayments(ctx context.Context,
|
|||||||
Fee: int64(route.TotalFees().ToSatoshis()),
|
Fee: int64(route.TotalFees().ToSatoshis()),
|
||||||
PaymentPreimage: hex.EncodeToString(preimage[:]),
|
PaymentPreimage: hex.EncodeToString(preimage[:]),
|
||||||
PaymentRequest: string(payment.Info.PaymentRequest),
|
PaymentRequest: string(payment.Info.PaymentRequest),
|
||||||
}
|
Status: status,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return paymentsResp, nil
|
return paymentsResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertPaymentStatus converts a channeldb.PaymentStatus to the type expected
|
||||||
|
// by the RPC.
|
||||||
|
func convertPaymentStatus(dbStatus channeldb.PaymentStatus) (
|
||||||
|
lnrpc.Payment_PaymentStatus, error) {
|
||||||
|
|
||||||
|
switch dbStatus {
|
||||||
|
case channeldb.StatusUnknown:
|
||||||
|
return lnrpc.Payment_UNKNOWN, nil
|
||||||
|
|
||||||
|
case channeldb.StatusInFlight:
|
||||||
|
return lnrpc.Payment_IN_FLIGHT, nil
|
||||||
|
|
||||||
|
case channeldb.StatusSucceeded:
|
||||||
|
return lnrpc.Payment_SUCCEEDED, nil
|
||||||
|
|
||||||
|
case channeldb.StatusFailed:
|
||||||
|
return lnrpc.Payment_FAILED, nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("unhandled payment status %v", dbStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteAllPayments deletes all outgoing payments from DB.
|
// DeleteAllPayments deletes all outgoing payments from DB.
|
||||||
func (r *rpcServer) DeleteAllPayments(ctx context.Context,
|
func (r *rpcServer) DeleteAllPayments(ctx context.Context,
|
||||||
_ *lnrpc.DeleteAllPaymentsRequest) (*lnrpc.DeleteAllPaymentsResponse, error) {
|
_ *lnrpc.DeleteAllPaymentsRequest) (*lnrpc.DeleteAllPaymentsResponse, error) {
|
||||||
|
|||||||
Reference in new issue
Block a user