looprpc: add reservations to loop out

pull/687/head
sputn1ck 6 months ago
parent 5cfae70942
commit 0340191251
No known key found for this signature in database
GPG Key ID: 671103D881A5F0E4

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 {
@ -235,6 +240,14 @@ message LoopOutRequest {
The address type of the account specified in the account field.
*/
AddressType account_addr_type = 16;
/*
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 = 17;
}
/*
@ -1277,7 +1290,7 @@ message ClientReservation {
/*
The transaction id of the reservation.
*/
bytes tx_id = 4;
string tx_id = 4;
/*
The vout of the reservation.
*/
@ -1286,4 +1299,24 @@ 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 {
bytes instant_out_hash = 1;
string sweep_tx_id = 2;
string state = 3;
}

@ -604,7 +604,6 @@
},
"tx_id": {
"type": "string",
"format": "byte",
"description": "The transaction id of the reservation."
},
"vout": {
@ -760,6 +759,21 @@
}
}
},
"looprpcInstantOutResponse": {
"type": "object",
"properties": {
"instant_out_hash": {
"type": "string",
"format": "byte"
},
"sweep_tx_id": {
"type": "string"
},
"state": {
"type": "string"
}
}
},
"looprpcLiquidityParameters": {
"type": "object",
"properties": {
@ -1110,6 +1124,14 @@
"account_addr_type": {
"$ref": "#/definitions/looprpcAddressType",
"description": "The address type of the account specified in the account field."
},
"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…
Cancel
Save