lnd: add DeletePayment to the RPC
The RPC DeletePayment allows deleteing single payment from its ID. When calling with `FailedHtlcsOnly` set in the request only failed HTLCs of this payment will be deleted.
This commit is contained in:
8 files changed
+878
-496
No files matched your search
+628
-492
File diff suppressed because it is too large.
Load diff
@@ -1357,6 +1357,42 @@ func local_request_Lightning_ListPayments_0(ctx context.Context, marshaler runti
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Lightning_DeletePayment_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Lightning_DeletePayment_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeletePaymentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_DeletePayment_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.DeletePayment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Lightning_DeletePayment_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DeletePaymentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_DeletePayment_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.DeletePayment(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Lightning_DeleteAllPayments_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
@@ -2910,6 +2946,29 @@ func RegisterLightningHandlerServer(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeletePayment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/lnrpc.Lightning/DeletePayment", runtime.WithHTTPPathPattern("/v1/payment"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Lightning_DeletePayment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_DeletePayment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeleteAllPayments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@@ -4165,6 +4224,26 @@ func RegisterLightningHandlerClient(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeletePayment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/lnrpc.Lightning/DeletePayment", runtime.WithHTTPPathPattern("/v1/payment"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Lightning_DeletePayment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_DeletePayment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("DELETE", pattern_Lightning_DeleteAllPayments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@@ -4683,6 +4762,8 @@ var (
|
||||
|
||||
pattern_Lightning_ListPayments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "payments"}, ""))
|
||||
|
||||
pattern_Lightning_DeletePayment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "payment"}, ""))
|
||||
|
||||
pattern_Lightning_DeleteAllPayments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "payments"}, ""))
|
||||
|
||||
pattern_Lightning_DescribeGraph_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "graph"}, ""))
|
||||
@@ -4803,6 +4884,8 @@ var (
|
||||
|
||||
forward_Lightning_ListPayments_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_DeletePayment_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_DeleteAllPayments_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_DescribeGraph_0 = runtime.ForwardResponseMessage
|
||||
|
||||
@@ -1000,6 +1000,31 @@ func RegisterLightningJSONCallbacks(registry map[string]func(ctx context.Context
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["lnrpc.Lightning.DeletePayment"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &DeletePaymentRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewLightningClient(conn)
|
||||
resp, err := client.DeletePayment(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["lnrpc.Lightning.DeleteAllPayments"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
|
||||
+21
-1
@@ -340,7 +340,14 @@ service Lightning {
|
||||
rpc ListPayments (ListPaymentsRequest) returns (ListPaymentsResponse);
|
||||
|
||||
/*
|
||||
DeleteAllPayments deletes all outgoing payments from DB.
|
||||
DeletePayment deletes an outgoing payment from DB. Note that it will not
|
||||
attempt to delete an In-Flight payment, since that would be unsafe.
|
||||
*/
|
||||
rpc DeletePayment (DeletePaymentRequest) returns (DeletePaymentResponse);
|
||||
|
||||
/*
|
||||
DeleteAllPayments deletes all outgoing payments from DB. Note that it will
|
||||
not attempt to delete In-Flight payments, since that would be unsafe.
|
||||
*/
|
||||
rpc DeleteAllPayments (DeleteAllPaymentsRequest)
|
||||
returns (DeleteAllPaymentsResponse);
|
||||
@@ -3448,6 +3455,16 @@ message ListPaymentsResponse {
|
||||
uint64 last_index_offset = 3;
|
||||
}
|
||||
|
||||
message DeletePaymentRequest {
|
||||
// Payment hash to delete.
|
||||
bytes payment_hash = 1;
|
||||
|
||||
/*
|
||||
Only delete failed HTLCs from the payment, not the payment itself.
|
||||
*/
|
||||
bool failed_htlcs_only = 2;
|
||||
}
|
||||
|
||||
message DeleteAllPaymentsRequest {
|
||||
// Only delete failed payments.
|
||||
bool failed_payments_only = 1;
|
||||
@@ -3458,6 +3475,9 @@ message DeleteAllPaymentsRequest {
|
||||
bool failed_htlcs_only = 2;
|
||||
}
|
||||
|
||||
message DeletePaymentResponse {
|
||||
}
|
||||
|
||||
message DeleteAllPaymentsResponse {
|
||||
}
|
||||
|
||||
|
||||
@@ -1688,6 +1688,46 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/payment": {
|
||||
"delete": {
|
||||
"summary": "DeletePayment deletes an outgoing payment from DB. Note that it will not\nattempt to delete an In-Flight payment, since that would be unsafe.",
|
||||
"operationId": "Lightning_DeletePayment",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/lnrpcDeletePaymentResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "payment_hash",
|
||||
"description": "Payment hash to delete.",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
},
|
||||
{
|
||||
"name": "failed_htlcs_only",
|
||||
"description": "Only delete failed HTLCs from the payment, not the payment itself.",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"Lightning"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/payments": {
|
||||
"get": {
|
||||
"summary": "lncli: `listpayments`\nListPayments returns a list of all outgoing payments.",
|
||||
@@ -1743,7 +1783,7 @@
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"summary": "DeleteAllPayments deletes all outgoing payments from DB.",
|
||||
"summary": "DeleteAllPayments deletes all outgoing payments from DB. Note that it will\nnot attempt to delete In-Flight payments, since that would be unsafe.",
|
||||
"operationId": "Lightning_DeleteAllPayments",
|
||||
"responses": {
|
||||
"200": {
|
||||
@@ -3688,6 +3728,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcDeletePaymentResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"lnrpcDisconnectPeerResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
|
||||
@@ -95,6 +95,8 @@ http:
|
||||
get: "/v1/invoices/subscribe"
|
||||
- selector: lnrpc.Lightning.DecodePayReq
|
||||
get: "/v1/payreq/{pay_req}"
|
||||
- selector: lnrpc.Lightning.DeletePayment
|
||||
delete: "/v1/payment"
|
||||
- selector: lnrpc.Lightning.ListPayments
|
||||
get: "/v1/payments"
|
||||
- selector: lnrpc.Lightning.DeleteAllPayments
|
||||
|
||||
@@ -249,7 +249,12 @@ type LightningClient interface {
|
||||
//ListPayments returns a list of all outgoing payments.
|
||||
ListPayments(ctx context.Context, in *ListPaymentsRequest, opts ...grpc.CallOption) (*ListPaymentsResponse, error)
|
||||
//
|
||||
//DeleteAllPayments deletes all outgoing payments from DB.
|
||||
//DeletePayment deletes an outgoing payment from DB. Note that it will not
|
||||
//attempt to delete an In-Flight payment, since that would be unsafe.
|
||||
DeletePayment(ctx context.Context, in *DeletePaymentRequest, opts ...grpc.CallOption) (*DeletePaymentResponse, error)
|
||||
//
|
||||
//DeleteAllPayments deletes all outgoing payments from DB. Note that it will
|
||||
//not attempt to delete In-Flight payments, since that would be unsafe.
|
||||
DeleteAllPayments(ctx context.Context, in *DeleteAllPaymentsRequest, opts ...grpc.CallOption) (*DeleteAllPaymentsResponse, error)
|
||||
// lncli: `describegraph`
|
||||
//DescribeGraph returns a description of the latest graph state from the
|
||||
@@ -937,6 +942,15 @@ func (c *lightningClient) ListPayments(ctx context.Context, in *ListPaymentsRequ
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *lightningClient) DeletePayment(ctx context.Context, in *DeletePaymentRequest, opts ...grpc.CallOption) (*DeletePaymentResponse, error) {
|
||||
out := new(DeletePaymentResponse)
|
||||
err := c.cc.Invoke(ctx, "/lnrpc.Lightning/DeletePayment", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *lightningClient) DeleteAllPayments(ctx context.Context, in *DeleteAllPaymentsRequest, opts ...grpc.CallOption) (*DeleteAllPaymentsResponse, error) {
|
||||
out := new(DeleteAllPaymentsResponse)
|
||||
err := c.cc.Invoke(ctx, "/lnrpc.Lightning/DeleteAllPayments", in, out, opts...)
|
||||
@@ -1416,7 +1430,12 @@ type LightningServer interface {
|
||||
//ListPayments returns a list of all outgoing payments.
|
||||
ListPayments(context.Context, *ListPaymentsRequest) (*ListPaymentsResponse, error)
|
||||
//
|
||||
//DeleteAllPayments deletes all outgoing payments from DB.
|
||||
//DeletePayment deletes an outgoing payment from DB. Note that it will not
|
||||
//attempt to delete an In-Flight payment, since that would be unsafe.
|
||||
DeletePayment(context.Context, *DeletePaymentRequest) (*DeletePaymentResponse, error)
|
||||
//
|
||||
//DeleteAllPayments deletes all outgoing payments from DB. Note that it will
|
||||
//not attempt to delete In-Flight payments, since that would be unsafe.
|
||||
DeleteAllPayments(context.Context, *DeleteAllPaymentsRequest) (*DeleteAllPaymentsResponse, error)
|
||||
// lncli: `describegraph`
|
||||
//DescribeGraph returns a description of the latest graph state from the
|
||||
@@ -1667,6 +1686,9 @@ func (UnimplementedLightningServer) DecodePayReq(context.Context, *PayReqString)
|
||||
func (UnimplementedLightningServer) ListPayments(context.Context, *ListPaymentsRequest) (*ListPaymentsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListPayments not implemented")
|
||||
}
|
||||
func (UnimplementedLightningServer) DeletePayment(context.Context, *DeletePaymentRequest) (*DeletePaymentResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeletePayment not implemented")
|
||||
}
|
||||
func (UnimplementedLightningServer) DeleteAllPayments(context.Context, *DeleteAllPaymentsRequest) (*DeleteAllPaymentsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteAllPayments not implemented")
|
||||
}
|
||||
@@ -2472,6 +2494,24 @@ func _Lightning_ListPayments_Handler(srv interface{}, ctx context.Context, dec f
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Lightning_DeletePayment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeletePaymentRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LightningServer).DeletePayment(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/lnrpc.Lightning/DeletePayment",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LightningServer).DeletePayment(ctx, req.(*DeletePaymentRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Lightning_DeleteAllPayments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteAllPaymentsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -2997,6 +3037,10 @@ var Lightning_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "ListPayments",
|
||||
Handler: _Lightning_ListPayments_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeletePayment",
|
||||
Handler: _Lightning_DeletePayment_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteAllPayments",
|
||||
Handler: _Lightning_DeleteAllPayments_Handler,
|
||||
|
||||
@@ -442,6 +442,10 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
|
||||
Entity: "offchain",
|
||||
Action: "read",
|
||||
}},
|
||||
"/lnrpc.Lightning/DeletePayment": {{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
}},
|
||||
"/lnrpc.Lightning/DeleteAllPayments": {{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
@@ -5934,6 +5938,31 @@ func (r *rpcServer) ListPayments(ctx context.Context,
|
||||
return paymentsResp, nil
|
||||
}
|
||||
|
||||
// DeletePayment deletes a payment from the DB given its payment hash. If
|
||||
// failedHtlcsOnly is set, only failed HTLC attempts of the payment will be
|
||||
// deleted.
|
||||
func (r *rpcServer) DeletePayment(ctx context.Context,
|
||||
req *lnrpc.DeletePaymentRequest) (
|
||||
*lnrpc.DeletePaymentResponse, error) {
|
||||
|
||||
hash, err := lntypes.MakeHash(req.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rpcsLog.Infof("[DeletePayment] payment_identifier=%v, "+
|
||||
"failed_htlcs_only=%v", hash, req.FailedHtlcsOnly)
|
||||
|
||||
err = r.server.chanStateDB.DeletePayment(
|
||||
hash, req.FailedHtlcsOnly,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &lnrpc.DeletePaymentResponse{}, nil
|
||||
}
|
||||
|
||||
// DeleteAllPayments deletes all outgoing payments from DB.
|
||||
func (r *rpcServer) DeleteAllPayments(ctx context.Context,
|
||||
req *lnrpc.DeleteAllPaymentsRequest) (
|
||||
|
||||
Reference in new issue
Block a user