looprpc: add client calls

This commit is contained in:
sputn1ck 2025-02-03 16:13:02 +01:00 committed by Slyghtning
parent 5ca0ccd486
commit 04a874e0e1
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
6 changed files with 675 additions and 235 deletions

File diff suppressed because it is too large Load diff

View file

@ -137,12 +137,25 @@ service SwapClient {
*/
rpc SuggestSwaps (SuggestSwapsRequest) returns (SuggestSwapsResponse);
/* loop: `listreservations`
/* loop: `reservations list`
ListReservations returns a list of all reservations the server opened to us.
*/
rpc ListReservations (ListReservationsRequest)
returns (ListReservationsResponse);
/* loop:`reservation request`
ReservationRequest requests a reservation from the server.
*/
rpc ReservationRequest (ReservationRequestRequest)
returns (ReservationRequestResponse);
/* loop:`reservation quote`
ReservationQuote returns a quote for a reservation with the provided
parameters.
*/
rpc ReservationQuote (ReservationQuoteRequest)
returns (ReservationQuoteResponse);
/* loop: `instantout`
InstantOut initiates an instant out swap with the given parameters.
*/
@ -1667,6 +1680,46 @@ message ClientReservation {
uint32 expiry = 6;
}
message ReservationRequestRequest {
/*
The amount to reserve in satoshis.
*/
uint64 amt = 1;
/*
The relative expiry of the reservation in blocks.
*/
uint32 expiry = 2;
/*
The maximum amt in satoshis we allow for the prepayment.
*/
uint64 max_prepay_amt = 3;
}
message ReservationRequestResponse {
ClientReservation reservation = 1;
}
message ReservationQuoteRequest {
/*
The amount to reserve in satoshis.
*/
uint64 amt = 1;
/*
The relative expiry of the reservation in blocks.
*/
uint32 expiry = 2;
}
message ReservationQuoteResponse {
/*
The prepay fee that will be charged for the reservation.
*/
uint64 prepay_amt = 1;
}
message InstantOutRequest {
/*
The reservations to use for the swap.

View file

@ -130,7 +130,7 @@
},
"/v1/instantout/reservations": {
"get": {
"summary": "loop: `listreservations`\nListReservations returns a list of all reservations the server opened to us.",
"summary": "loop: `reservations list`\nListReservations returns a list of all reservations the server opened to us.",
"operationId": "SwapClient_ListReservations",
"responses": {
"200": {
@ -2621,6 +2621,24 @@
"type": "object",
"description": "PublishSucceeded is returned by SweepHtlc if publishing was requested in\nSweepHtlcRequest and it succeeded."
},
"looprpcReservationQuoteResponse": {
"type": "object",
"properties": {
"prepay_amt": {
"type": "string",
"format": "uint64",
"description": "The prepay fee that will be charged for the reservation."
}
}
},
"looprpcReservationRequestResponse": {
"type": "object",
"properties": {
"reservation": {
"$ref": "#/definitions/looprpcClientReservation"
}
}
},
"looprpcRouteHint": {
"type": "object",
"properties": {

View file

@ -99,9 +99,16 @@ type SwapClientClient interface {
// Note that only loop out suggestions are currently supported.
// [EXPERIMENTAL]: endpoint is subject to change.
SuggestSwaps(ctx context.Context, in *SuggestSwapsRequest, opts ...grpc.CallOption) (*SuggestSwapsResponse, error)
// loop: `listreservations`
// loop: `reservations list`
// ListReservations returns a list of all reservations the server opened to us.
ListReservations(ctx context.Context, in *ListReservationsRequest, opts ...grpc.CallOption) (*ListReservationsResponse, error)
// loop:`reservation request`
// ReservationRequest requests a reservation from the server.
ReservationRequest(ctx context.Context, in *ReservationRequestRequest, opts ...grpc.CallOption) (*ReservationRequestResponse, error)
// loop:`reservation quote`
// ReservationQuote returns a quote for a reservation with the provided
// parameters.
ReservationQuote(ctx context.Context, in *ReservationQuoteRequest, opts ...grpc.CallOption) (*ReservationQuoteResponse, error)
// loop: `instantout`
// InstantOut initiates an instant out swap with the given parameters.
InstantOut(ctx context.Context, in *InstantOutRequest, opts ...grpc.CallOption) (*InstantOutResponse, error)
@ -366,6 +373,24 @@ func (c *swapClientClient) ListReservations(ctx context.Context, in *ListReserva
return out, nil
}
func (c *swapClientClient) ReservationRequest(ctx context.Context, in *ReservationRequestRequest, opts ...grpc.CallOption) (*ReservationRequestResponse, error) {
out := new(ReservationRequestResponse)
err := c.cc.Invoke(ctx, "/looprpc.SwapClient/ReservationRequest", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *swapClientClient) ReservationQuote(ctx context.Context, in *ReservationQuoteRequest, opts ...grpc.CallOption) (*ReservationQuoteResponse, error) {
out := new(ReservationQuoteResponse)
err := c.cc.Invoke(ctx, "/looprpc.SwapClient/ReservationQuote", in, out, opts...)
if err != nil {
return nil, err
}
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...)
@ -559,9 +584,16 @@ type SwapClientServer interface {
// Note that only loop out suggestions are currently supported.
// [EXPERIMENTAL]: endpoint is subject to change.
SuggestSwaps(context.Context, *SuggestSwapsRequest) (*SuggestSwapsResponse, error)
// loop: `listreservations`
// loop: `reservations list`
// ListReservations returns a list of all reservations the server opened to us.
ListReservations(context.Context, *ListReservationsRequest) (*ListReservationsResponse, error)
// loop:`reservation request`
// ReservationRequest requests a reservation from the server.
ReservationRequest(context.Context, *ReservationRequestRequest) (*ReservationRequestResponse, error)
// loop:`reservation quote`
// ReservationQuote returns a quote for a reservation with the provided
// parameters.
ReservationQuote(context.Context, *ReservationQuoteRequest) (*ReservationQuoteResponse, error)
// loop: `instantout`
// InstantOut initiates an instant out swap with the given parameters.
InstantOut(context.Context, *InstantOutRequest) (*InstantOutResponse, error)
@ -674,6 +706,12 @@ 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) ReservationRequest(context.Context, *ReservationRequestRequest) (*ReservationRequestResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReservationRequest not implemented")
}
func (UnimplementedSwapClientServer) ReservationQuote(context.Context, *ReservationQuoteRequest) (*ReservationQuoteResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReservationQuote not implemented")
}
func (UnimplementedSwapClientServer) InstantOut(context.Context, *InstantOutRequest) (*InstantOutResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method InstantOut not implemented")
}
@ -1104,6 +1142,42 @@ func _SwapClient_ListReservations_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _SwapClient_ReservationRequest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReservationRequestRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SwapClientServer).ReservationRequest(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/looprpc.SwapClient/ReservationRequest",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SwapClientServer).ReservationRequest(ctx, req.(*ReservationRequestRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SwapClient_ReservationQuote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReservationQuoteRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SwapClientServer).ReservationQuote(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/looprpc.SwapClient/ReservationQuote",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SwapClientServer).ReservationQuote(ctx, req.(*ReservationQuoteRequest))
}
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 {
@ -1407,6 +1481,14 @@ var SwapClient_ServiceDesc = grpc.ServiceDesc{
MethodName: "ListReservations",
Handler: _SwapClient_ListReservations_Handler,
},
{
MethodName: "ReservationRequest",
Handler: _SwapClient_ReservationRequest_Handler,
},
{
MethodName: "ReservationQuote",
Handler: _SwapClient_ReservationQuote_Handler,
},
{
MethodName: "InstantOut",
Handler: _SwapClient_InstantOut_Handler,

View file

@ -181,6 +181,14 @@ var RequiredPermissions = map[string][]bakery.Op{
Entity: "loop",
Action: "out",
}},
"/looprpc.SwapClient/ReservationRequest": {{
Entity: "swap",
Action: "execute",
}},
"/looprpc.SwapClient/ReservationQuote": {{
Entity: "swap",
Action: "read",
}},
"/looprpc.SwapClient/InstantOut": {{
Entity: "swap",
Action: "execute",

View file

@ -563,6 +563,56 @@ func RegisterSwapClientJSONCallbacks(registry map[string]func(ctx context.Contex
callback(string(respBytes), nil)
}
registry["looprpc.SwapClient.ReservationRequest"] = func(ctx context.Context,
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
req := &ReservationRequestRequest{}
err := marshaler.Unmarshal([]byte(reqJSON), req)
if err != nil {
callback("", err)
return
}
client := NewSwapClientClient(conn)
resp, err := client.ReservationRequest(ctx, req)
if err != nil {
callback("", err)
return
}
respBytes, err := marshaler.Marshal(resp)
if err != nil {
callback("", err)
return
}
callback(string(respBytes), nil)
}
registry["looprpc.SwapClient.ReservationQuote"] = func(ctx context.Context,
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
req := &ReservationQuoteRequest{}
err := marshaler.Unmarshal([]byte(reqJSON), req)
if err != nil {
callback("", err)
return
}
client := NewSwapClientClient(conn)
resp, err := client.ReservationQuote(ctx, req)
if err != nil {
callback("", err)
return
}
respBytes, err := marshaler.Marshal(resp)
if err != nil {
callback("", err)
return
}
callback(string(respBytes), nil)
}
registry["looprpc.SwapClient.InstantOut"] = func(ctx context.Context,
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {