mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
looprpc: add reservations to loop out
This commit is contained in:
parent
932a55aaf6
commit
6c07f88458
5 changed files with 877 additions and 553 deletions
1294
looprpc/client.pb.go
1294
looprpc/client.pb.go
File diff suppressed because it is too large
Load diff
|
|
@ -115,6 +115,11 @@ service SwapClient {
|
|||
*/
|
||||
rpc ListReservations (ListReservationsRequest)
|
||||
returns (ListReservationsResponse);
|
||||
|
||||
/* loop: `instantout`
|
||||
InstantOut initiates an instant out swap with the given parameters.
|
||||
*/
|
||||
rpc InstantOut (InstantOutRequest) returns (InstantOutResponse);
|
||||
}
|
||||
|
||||
message LoopOutRequest {
|
||||
|
|
@ -242,6 +247,14 @@ message LoopOutRequest {
|
|||
associated sweep batched.
|
||||
*/
|
||||
bool is_external_addr = 17;
|
||||
|
||||
/*
|
||||
The reservations to use for the swap. If this field is set, loop will try
|
||||
to use the instant out flow using the given reservations. If the
|
||||
reservations are not sufficient, the swap will fail. The swap amount must
|
||||
be equal to the sum of the amounts of the reservations.
|
||||
*/
|
||||
repeated bytes reservation_ids = 18;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1284,7 +1297,7 @@ message ClientReservation {
|
|||
/*
|
||||
The transaction id of the reservation.
|
||||
*/
|
||||
bytes tx_id = 4;
|
||||
string tx_id = 4;
|
||||
/*
|
||||
The vout of the reservation.
|
||||
*/
|
||||
|
|
@ -1293,4 +1306,33 @@ message ClientReservation {
|
|||
The expiry of the reservation.
|
||||
*/
|
||||
uint32 expiry = 6;
|
||||
}
|
||||
|
||||
message InstantOutRequest {
|
||||
/*
|
||||
The reservations to use for the swap.
|
||||
*/
|
||||
repeated bytes reservation_ids = 1;
|
||||
|
||||
/*
|
||||
A restriction on the channel set that may be used to loop out. The actual
|
||||
channel(s) that will be used are selected based on the lowest routing fee
|
||||
for the swap payment to the server.
|
||||
*/
|
||||
repeated uint64 outgoing_chan_set = 11;
|
||||
}
|
||||
|
||||
message InstantOutResponse {
|
||||
/*
|
||||
The hash of the swap preimage.
|
||||
*/
|
||||
bytes instant_out_hash = 1;
|
||||
/*
|
||||
The transaction id of the sweep transaction.
|
||||
*/
|
||||
string sweep_tx_id = 2;
|
||||
/*
|
||||
The state of the swap.
|
||||
*/
|
||||
string state = 3;
|
||||
}
|
||||
|
|
@ -604,7 +604,6 @@
|
|||
},
|
||||
"tx_id": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "The transaction id of the reservation."
|
||||
},
|
||||
"vout": {
|
||||
|
|
@ -760,6 +759,24 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"looprpcInstantOutResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"instant_out_hash": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "The hash of the swap preimage."
|
||||
},
|
||||
"sweep_tx_id": {
|
||||
"type": "string",
|
||||
"description": "The transaction id of the sweep transaction."
|
||||
},
|
||||
"state": {
|
||||
"type": "string",
|
||||
"description": "The state of the swap."
|
||||
}
|
||||
}
|
||||
},
|
||||
"looprpcLiquidityParameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -1114,6 +1131,14 @@
|
|||
"is_external_addr": {
|
||||
"type": "boolean",
|
||||
"description": "A flag indicating whether the defined destination address does not belong to\nthe wallet. This is used to flag whether this loop out swap could have its\nassociated sweep batched."
|
||||
},
|
||||
"reservation_ids": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
},
|
||||
"description": "The reservations to use for the swap. If this field is set, loop will try\nto use the instant out flow using the given reservations. If the\nreservations are not sufficient, the swap will fail. The swap amount must\nbe equal to the sum of the amounts of the reservations."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ type SwapClientClient interface {
|
|||
// loop: `listreservations`
|
||||
//ListReservations returns a list of all reservations the server opened to us.
|
||||
ListReservations(ctx context.Context, in *ListReservationsRequest, opts ...grpc.CallOption) (*ListReservationsResponse, error)
|
||||
// loop: `instantout`
|
||||
//InstantOut initiates an instant out swap with the given parameters.
|
||||
InstantOut(ctx context.Context, in *InstantOutRequest, opts ...grpc.CallOption) (*InstantOutResponse, error)
|
||||
}
|
||||
|
||||
type swapClientClient struct {
|
||||
|
|
@ -272,6 +275,15 @@ func (c *swapClientClient) ListReservations(ctx context.Context, in *ListReserva
|
|||
return out, nil
|
||||
}
|
||||
|
||||
func (c *swapClientClient) InstantOut(ctx context.Context, in *InstantOutRequest, opts ...grpc.CallOption) (*InstantOutResponse, error) {
|
||||
out := new(InstantOutResponse)
|
||||
err := c.cc.Invoke(ctx, "/looprpc.SwapClient/InstantOut", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SwapClientServer is the server API for SwapClient service.
|
||||
// All implementations must embed UnimplementedSwapClientServer
|
||||
// for forward compatibility
|
||||
|
|
@ -344,6 +356,9 @@ type SwapClientServer interface {
|
|||
// loop: `listreservations`
|
||||
//ListReservations returns a list of all reservations the server opened to us.
|
||||
ListReservations(context.Context, *ListReservationsRequest) (*ListReservationsResponse, error)
|
||||
// loop: `instantout`
|
||||
//InstantOut initiates an instant out swap with the given parameters.
|
||||
InstantOut(context.Context, *InstantOutRequest) (*InstantOutResponse, error)
|
||||
mustEmbedUnimplementedSwapClientServer()
|
||||
}
|
||||
|
||||
|
|
@ -402,6 +417,9 @@ func (UnimplementedSwapClientServer) SuggestSwaps(context.Context, *SuggestSwaps
|
|||
func (UnimplementedSwapClientServer) ListReservations(context.Context, *ListReservationsRequest) (*ListReservationsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListReservations not implemented")
|
||||
}
|
||||
func (UnimplementedSwapClientServer) InstantOut(context.Context, *InstantOutRequest) (*InstantOutResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method InstantOut not implemented")
|
||||
}
|
||||
func (UnimplementedSwapClientServer) mustEmbedUnimplementedSwapClientServer() {}
|
||||
|
||||
// UnsafeSwapClientServer may be embedded to opt out of forward compatibility for this service.
|
||||
|
|
@ -724,6 +742,24 @@ func _SwapClient_ListReservations_Handler(srv interface{}, ctx context.Context,
|
|||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SwapClient_InstantOut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(InstantOutRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SwapClientServer).InstantOut(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/looprpc.SwapClient/InstantOut",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SwapClientServer).InstantOut(ctx, req.(*InstantOutRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// SwapClient_ServiceDesc is the grpc.ServiceDesc for SwapClient service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
|
|
@ -795,6 +831,10 @@ var SwapClient_ServiceDesc = grpc.ServiceDesc{
|
|||
MethodName: "ListReservations",
|
||||
Handler: _SwapClient_ListReservations_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "InstantOut",
|
||||
Handler: _SwapClient_InstantOut_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -462,4 +462,29 @@ func RegisterSwapClientJSONCallbacks(registry map[string]func(ctx context.Contex
|
|||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["looprpc.SwapClient.InstantOut"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &InstantOutRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewSwapClientClient(conn)
|
||||
resp, err := client.InstantOut(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue