lnrpc: add SendToRoute command

This commit is contained in:
t4sk 2018-01-25 12:08:46 +07:00 committed by Olaoluwa Osuntokun
parent dc04df0f2e
commit dac62e812c
5 changed files with 760 additions and 459 deletions

View File

@ -72,6 +72,11 @@ description):
* Send a payment over Lightning to a target peer. * Send a payment over Lightning to a target peer.
* SendPaymentSync * SendPaymentSync
* SendPaymentSync is the synchronous non-streaming version of SendPayment. * SendPaymentSync is the synchronous non-streaming version of SendPayment.
* SendToRoute
* Send a payment over Lightning to a target peer through a route explicitly
defined by the user.
* SendToRouteSync
* SendToRouteSync is the synchronous non-streaming version of SendToRoute.
* AddInvoice * AddInvoice
* Adds an invoice to the daemon. Invoices are automatically settled once * Adds an invoice to the daemon. Invoices are automatically settled once
seen as an incoming HTLC. seen as an incoming HTLC.

File diff suppressed because it is too large Load Diff

View File

@ -297,6 +297,19 @@ func request_Lightning_SendPaymentSync_0(ctx context.Context, marshaler runtime.
} }
func request_Lightning_SendToRouteSync_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq SendToRouteRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.SendToRouteSync(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func request_Lightning_AddInvoice_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_Lightning_AddInvoice_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq Invoice var protoReq Invoice
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@ -1182,6 +1195,35 @@ func RegisterLightningHandler(ctx context.Context, mux *runtime.ServeMux, conn *
}) })
mux.Handle("POST", pattern_Lightning_SendToRouteSync_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Lightning_SendToRouteSync_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_SendToRouteSync_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Lightning_AddInvoice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("POST", pattern_Lightning_AddInvoice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
@ -1649,6 +1691,8 @@ var (
pattern_Lightning_SendPaymentSync_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "channels", "transactions"}, "")) pattern_Lightning_SendPaymentSync_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "channels", "transactions"}, ""))
pattern_Lightning_SendToRouteSync_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "channels", "transactions", "sendtoroute"}, ""))
pattern_Lightning_AddInvoice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "invoices"}, "")) pattern_Lightning_AddInvoice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "invoices"}, ""))
pattern_Lightning_ListInvoices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "invoices"}, "")) pattern_Lightning_ListInvoices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "invoices"}, ""))
@ -1709,6 +1753,8 @@ var (
forward_Lightning_SendPaymentSync_0 = runtime.ForwardResponseMessage forward_Lightning_SendPaymentSync_0 = runtime.ForwardResponseMessage
forward_Lightning_SendToRouteSync_0 = runtime.ForwardResponseMessage
forward_Lightning_AddInvoice_0 = runtime.ForwardResponseMessage forward_Lightning_AddInvoice_0 = runtime.ForwardResponseMessage
forward_Lightning_ListInvoices_0 = runtime.ForwardResponseMessage forward_Lightning_ListInvoices_0 = runtime.ForwardResponseMessage

View File

@ -399,6 +399,28 @@ service Lightning {
}; };
} }
/** lncli: `sendtoroute`
SendToRoute dispatches a bi-directional streaming RPC for sending payments
through the Lightning Network via predefined routes passed in. A single RPC
invocation creates a persistent bi-directional stream allowing clients to
rapidly send payments through the Lightning Network with a single
persistent connection.
*/
rpc SendToRoute(stream SendToRouteRequest) returns (stream SendResponse);
/**
SendToRouteSync is the synchronous non-streaming version of SendToRoute.
This RPC is intended to be consumed by clients of the REST proxy.
Additionally, this RPC expects the payment hash to be encoded
as hex strings.
*/
rpc SendToRouteSync (SendToRouteRequest) returns (SendResponse) {
option (google.api.http) = {
post: "/v1/channels/transactions/sendtoroute"
body: "*"
};
}
/** lncli: `addinvoice` /** lncli: `addinvoice`
AddInvoice attempts to add a new invoice to the invoice database. Any AddInvoice attempts to add a new invoice to the invoice database. Any
duplicated invoices are rejected, therefore all invoices *must* have a duplicated invoices are rejected, therefore all invoices *must* have a
@ -659,6 +681,17 @@ message SendResponse {
Route payment_route = 3 [json_name = "payment_route"]; Route payment_route = 3 [json_name = "payment_route"];
} }
message SendToRouteRequest {
/// The hash to use within the payment's HTLC
bytes payment_hash = 1;
/// The hex-encoded hash to use within the payment's HTLC
string payment_hash_string = 2;
/// The routes that should be tried in sending the payment.
repeated Route routes = 3 [json_name = "routes"];
}
message ChannelPoint { message ChannelPoint {
oneof funding_txid { oneof funding_txid {
/// Txid of the funding transaction /// Txid of the funding transaction

View File

@ -192,6 +192,33 @@
] ]
} }
}, },
"/v1/channels/transactions/sendtoroute": {
"post": {
"summary": "*\nSendToRouteSync is the synchronous non-streaming version of SendToRoute.\nThis RPC is intended to be consumed by clients of the REST proxy.\nAdditionally, this RPC expects the payment hash to be encoded\nas hex strings.",
"operationId": "SendToRouteSync",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/lnrpcSendResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/lnrpcSendToRouteRequest"
}
}
],
"tags": [
"Lightning"
]
}
},
"/v1/channels/{channel_point.funding_txid_str}/{channel_point.output_index}": { "/v1/channels/{channel_point.funding_txid_str}/{channel_point.output_index}": {
"delete": { "delete": {
"summary": "* lncli: `closechannel`\nCloseChannel attempts to close an active channel identified by its channel\noutpoint (ChannelPoint). The actions of this method can additionally be\naugmented to attempt a force close after a timeout period in the case of an\ninactive peer. If a non-force close (cooperative closure) is requested,\nthen the user can specify either a target number of blocks until the\nclosure transaction is confirmed, or a manual fee rate. If neither are\nspecified, then a default lax, block confirmation target is used.", "summary": "* lncli: `closechannel`\nCloseChannel attempts to close an active channel identified by its channel\noutpoint (ChannelPoint). The actions of this method can additionally be\naugmented to attempt a force close after a timeout period in the case of an\ninactive peer. If a non-force close (cooperative closure) is requested,\nthen the user can specify either a target number of blocks until the\nclosure transaction is confirmed, or a manual fee rate. If neither are\nspecified, then a default lax, block confirmation target is used.",
@ -2364,6 +2391,27 @@
} }
} }
}, },
"lnrpcSendToRouteRequest": {
"type": "object",
"properties": {
"payment_hash": {
"type": "string",
"format": "byte",
"title": "/ The hash to use within the payment's HTLC"
},
"payment_hash_string": {
"type": "string",
"title": "/ The hex-encoded hash to use within the payment's HTLC"
},
"routes": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcRoute"
},
"description": "/ The routes that should be tried in sending the payment."
}
}
},
"lnrpcSignMessageResponse": { "lnrpcSignMessageResponse": {
"type": "object", "type": "object",
"properties": { "properties": {