From 036db6646f4e43d16bc5773023576b96e952249f Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 23 Sep 2019 09:54:33 +0200 Subject: [PATCH 1/4] looprpc: regenerate with correct version --- looprpc/client.pb.go | 28 --- looprpc/client.pb.gw.go | 358 ++++++++---------------------------- looprpc/client.swagger.json | 65 +------ looprpc/server.pb.go | 19 -- 4 files changed, 80 insertions(+), 390 deletions(-) diff --git a/looprpc/client.pb.go b/looprpc/client.pb.go index 3774eb0..ef6b335 100644 --- a/looprpc/client.pb.go +++ b/looprpc/client.pb.go @@ -9,8 +9,6 @@ import ( proto "github.com/golang/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -1065,32 +1063,6 @@ type SwapClientServer interface { GetLoopInQuote(context.Context, *QuoteRequest) (*QuoteResponse, error) } -// UnimplementedSwapClientServer can be embedded to have forward compatible implementations. -type UnimplementedSwapClientServer struct { -} - -func (*UnimplementedSwapClientServer) LoopOut(ctx context.Context, req *LoopOutRequest) (*SwapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopOut not implemented") -} -func (*UnimplementedSwapClientServer) LoopIn(ctx context.Context, req *LoopInRequest) (*SwapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopIn not implemented") -} -func (*UnimplementedSwapClientServer) Monitor(req *MonitorRequest, srv SwapClient_MonitorServer) error { - return status.Errorf(codes.Unimplemented, "method Monitor not implemented") -} -func (*UnimplementedSwapClientServer) LoopOutTerms(ctx context.Context, req *TermsRequest) (*TermsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopOutTerms not implemented") -} -func (*UnimplementedSwapClientServer) LoopOutQuote(ctx context.Context, req *QuoteRequest) (*QuoteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopOutQuote not implemented") -} -func (*UnimplementedSwapClientServer) GetLoopInTerms(ctx context.Context, req *TermsRequest) (*TermsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetLoopInTerms not implemented") -} -func (*UnimplementedSwapClientServer) GetLoopInQuote(ctx context.Context, req *QuoteRequest) (*QuoteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetLoopInQuote not implemented") -} - func RegisterSwapClientServer(s *grpc.Server, srv SwapClientServer) { s.RegisterService(&_SwapClient_serviceDesc, srv) } diff --git a/looprpc/client.pb.gw.go b/looprpc/client.pb.gw.go index 0251c65..5ce9f24 100644 --- a/looprpc/client.pb.gw.go +++ b/looprpc/client.pb.gw.go @@ -9,13 +9,13 @@ It translates gRPC into RESTful JSON APIs. package looprpc import ( - "context" "io" "net/http" "github.com/golang/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" + "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" @@ -32,11 +32,7 @@ func request_SwapClient_LoopOut_0(ctx context.Context, marshaler runtime.Marshal var protoReq LoopOutRequest var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -45,32 +41,11 @@ func request_SwapClient_LoopOut_0(ctx context.Context, marshaler runtime.Marshal } -func local_request_SwapClient_LoopOut_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq LoopOutRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LoopOut(ctx, &protoReq) - return msg, metadata, err - -} - func request_SwapClient_LoopIn_0(ctx context.Context, marshaler runtime.Marshaler, client SwapClientClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq LoopInRequest var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -79,23 +54,6 @@ func request_SwapClient_LoopIn_0(ctx context.Context, marshaler runtime.Marshale } -func local_request_SwapClient_LoopIn_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq LoopInRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LoopIn(ctx, &protoReq) - return msg, metadata, err - -} - func request_SwapClient_LoopOutTerms_0(ctx context.Context, marshaler runtime.Marshaler, client SwapClientClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq TermsRequest var metadata runtime.ServerMetadata @@ -105,15 +63,6 @@ func request_SwapClient_LoopOutTerms_0(ctx context.Context, marshaler runtime.Ma } -func local_request_SwapClient_LoopOutTerms_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TermsRequest - var metadata runtime.ServerMetadata - - msg, err := server.LoopOutTerms(ctx, &protoReq) - return msg, metadata, err - -} - var ( filter_SwapClient_LoopOutQuote_0 = &utilities.DoubleArray{Encoding: map[string]int{"amt": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) @@ -140,45 +89,11 @@ func request_SwapClient_LoopOutQuote_0(ctx context.Context, marshaler runtime.Ma return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amt", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_SwapClient_LoopOutQuote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LoopOutQuote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_SwapClient_LoopOutQuote_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QuoteRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["amt"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "amt") - } - - protoReq.Amt, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amt", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_SwapClient_LoopOutQuote_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.LoopOutQuote(ctx, &protoReq) + msg, err := client.LoopOutQuote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } @@ -192,15 +107,6 @@ func request_SwapClient_GetLoopInTerms_0(ctx context.Context, marshaler runtime. } -func local_request_SwapClient_GetLoopInTerms_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TermsRequest - var metadata runtime.ServerMetadata - - msg, err := server.GetLoopInTerms(ctx, &protoReq) - return msg, metadata, err - -} - var ( filter_SwapClient_GetLoopInQuote_0 = &utilities.DoubleArray{Encoding: map[string]int{"amt": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) @@ -227,177 +133,15 @@ func request_SwapClient_GetLoopInQuote_0(ctx context.Context, marshaler runtime. return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amt", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_SwapClient_GetLoopInQuote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetLoopInQuote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_SwapClient_GetLoopInQuote_0(ctx context.Context, marshaler runtime.Marshaler, server SwapClientServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QuoteRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["amt"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "amt") - } - - protoReq.Amt, err = runtime.Int64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amt", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_SwapClient_GetLoopInQuote_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.GetLoopInQuote(ctx, &protoReq) + msg, err := client.GetLoopInQuote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -// RegisterSwapClientHandlerServer registers the http handlers for service SwapClient to "mux". -// UnaryRPC :call SwapClientServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterSwapClientHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SwapClientServer, opts []grpc.DialOption) error { - - mux.Handle("POST", pattern_SwapClient_LoopOut_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_LoopOut_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_LoopOut_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_SwapClient_LoopIn_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_LoopIn_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_LoopIn_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_SwapClient_LoopOutTerms_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_LoopOutTerms_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_LoopOutTerms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_SwapClient_LoopOutQuote_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_LoopOutQuote_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_LoopOutQuote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_SwapClient_GetLoopInTerms_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_GetLoopInTerms_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_GetLoopInTerms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_SwapClient_GetLoopInQuote_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) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SwapClient_GetLoopInQuote_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SwapClient_GetLoopInQuote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - // RegisterSwapClientHandlerFromEndpoint is same as RegisterSwapClientHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterSwapClientHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { @@ -408,14 +152,14 @@ func RegisterSwapClientHandlerFromEndpoint(ctx context.Context, mux *runtime.Ser defer func() { if err != nil { if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) } return } go func() { <-ctx.Done() if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) } }() }() @@ -426,19 +170,20 @@ func RegisterSwapClientHandlerFromEndpoint(ctx context.Context, mux *runtime.Ser // RegisterSwapClientHandler registers the http handlers for service SwapClient to "mux". // The handlers forward requests to the grpc endpoint over "conn". func RegisterSwapClientHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterSwapClientHandlerClient(ctx, mux, NewSwapClientClient(conn)) -} - -// RegisterSwapClientHandlerClient registers the http handlers for service SwapClient -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SwapClientClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SwapClientClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "SwapClientClient" to call the correct interceptors. -func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SwapClientClient) error { + client := NewSwapClientClient(conn) mux.Handle("POST", pattern_SwapClient_LoopOut_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -457,8 +202,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_SwapClient_LoopIn_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -477,8 +231,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("GET", pattern_SwapClient_LoopOutTerms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -497,8 +260,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("GET", pattern_SwapClient_LoopOutQuote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -517,8 +289,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("GET", pattern_SwapClient_GetLoopInTerms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -537,8 +318,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("GET", pattern_SwapClient_GetLoopInQuote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + 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 { @@ -560,17 +350,17 @@ func RegisterSwapClientHandlerClient(ctx context.Context, mux *runtime.ServeMux, } var ( - pattern_SwapClient_LoopOut_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "loop", "out"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_LoopOut_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "loop", "out"}, "")) - pattern_SwapClient_LoopIn_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "loop", "in"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_LoopIn_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "loop", "in"}, "")) - pattern_SwapClient_LoopOutTerms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "loop", "out", "terms"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_LoopOutTerms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "loop", "out", "terms"}, "")) - pattern_SwapClient_LoopOutQuote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "loop", "out", "quote", "amt"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_LoopOutQuote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "loop", "out", "quote", "amt"}, "")) - pattern_SwapClient_GetLoopInTerms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "loop", "in", "terms"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_GetLoopInTerms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "loop", "in", "terms"}, "")) - pattern_SwapClient_GetLoopInQuote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "loop", "in", "quote", "amt"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_SwapClient_GetLoopInQuote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v1", "loop", "in", "quote", "amt"}, "")) ) var ( diff --git a/looprpc/client.swagger.json b/looprpc/client.swagger.json index 0031979..887d327 100644 --- a/looprpc/client.swagger.json +++ b/looprpc/client.swagger.json @@ -21,7 +21,7 @@ "operationId": "LoopIn", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcSwapResponse" } @@ -48,7 +48,7 @@ "operationId": "GetLoopInQuote", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcQuoteResponse" } @@ -57,7 +57,6 @@ "parameters": [ { "name": "amt", - "description": "*\nThe amount to swap in satoshis.", "in": "path", "required": true, "type": "string", @@ -83,7 +82,7 @@ "operationId": "GetLoopInTerms", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcTermsResponse" } @@ -100,7 +99,7 @@ "operationId": "LoopOut", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcSwapResponse" } @@ -127,7 +126,7 @@ "operationId": "LoopOutQuote", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcQuoteResponse" } @@ -136,7 +135,6 @@ "parameters": [ { "name": "amt", - "description": "*\nThe amount to swap in satoshis.", "in": "path", "required": true, "type": "string", @@ -162,7 +160,7 @@ "operationId": "LoopOutTerms", "responses": { "200": { - "description": "A successful response.", + "description": "", "schema": { "$ref": "#/definitions/looprpcTermsResponse" } @@ -398,57 +396,6 @@ "title": "*\nOn-chain cltv expiry delta" } } - }, - "protobufAny": { - "type": "object", - "properties": { - "type_url": { - "type": "string" - }, - "value": { - "type": "string", - "format": "byte" - } - } - }, - "runtimeStreamError": { - "type": "object", - "properties": { - "grpc_code": { - "type": "integer", - "format": "int32" - }, - "http_code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" - }, - "http_status": { - "type": "string" - }, - "details": { - "type": "array", - "items": { - "$ref": "#/definitions/protobufAny" - } - } - } - } - }, - "x-stream-definitions": { - "looprpcSwapStatus": { - "type": "object", - "properties": { - "result": { - "$ref": "#/definitions/looprpcSwapStatus" - }, - "error": { - "$ref": "#/definitions/runtimeStreamError" - } - }, - "title": "Stream result of looprpcSwapStatus" } } } diff --git a/looprpc/server.pb.go b/looprpc/server.pb.go index adfff68..e9914df 100644 --- a/looprpc/server.pb.go +++ b/looprpc/server.pb.go @@ -9,8 +9,6 @@ import ( proto "github.com/golang/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -597,23 +595,6 @@ type SwapServerServer interface { LoopInQuote(context.Context, *ServerLoopInQuoteRequest) (*ServerLoopInQuoteResponse, error) } -// UnimplementedSwapServerServer can be embedded to have forward compatible implementations. -type UnimplementedSwapServerServer struct { -} - -func (*UnimplementedSwapServerServer) NewLoopOutSwap(ctx context.Context, req *ServerLoopOutRequest) (*ServerLoopOutResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method NewLoopOutSwap not implemented") -} -func (*UnimplementedSwapServerServer) LoopOutQuote(ctx context.Context, req *ServerLoopOutQuoteRequest) (*ServerLoopOutQuote, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopOutQuote not implemented") -} -func (*UnimplementedSwapServerServer) NewLoopInSwap(ctx context.Context, req *ServerLoopInRequest) (*ServerLoopInResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method NewLoopInSwap not implemented") -} -func (*UnimplementedSwapServerServer) LoopInQuote(ctx context.Context, req *ServerLoopInQuoteRequest) (*ServerLoopInQuoteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method LoopInQuote not implemented") -} - func RegisterSwapServerServer(s *grpc.Server, srv SwapServerServer) { s.RegisterService(&_SwapServer_serviceDesc, srv) } From be9a2b9a47fdb6e82ea88ac7eb938e7b30fc5226 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 23 Sep 2019 09:58:52 +0200 Subject: [PATCH 2/4] looprpc: add external HTLC flag to quote request --- looprpc/client.pb.go | 149 +++++++++++++++++++----------------- looprpc/client.proto | 6 ++ looprpc/client.swagger.json | 16 ++++ 3 files changed, 102 insertions(+), 69 deletions(-) diff --git a/looprpc/client.pb.go b/looprpc/client.pb.go index ef6b335..bc4578e 100644 --- a/looprpc/client.pb.go +++ b/looprpc/client.pb.go @@ -700,7 +700,11 @@ type QuoteRequest struct { //on-chain HTLC broadcast by the swap server in the case of a Loop Out, or for //the confirmation of the on-chain HTLC broadcast by the swap client in the //case of a Loop In. - ConfTarget int32 `protobuf:"varint,2,opt,name=conf_target,json=confTarget,proto3" json:"conf_target,omitempty"` + ConfTarget int32 `protobuf:"varint,2,opt,name=conf_target,json=confTarget,proto3" json:"conf_target,omitempty"` + //* + //If external_htlc is true, we expect the htlc to be published by an external + //actor. + ExternalHtlc bool `protobuf:"varint,3,opt,name=external_htlc,json=externalHtlc,proto3" json:"external_htlc,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -745,6 +749,13 @@ func (m *QuoteRequest) GetConfTarget() int32 { return 0 } +func (m *QuoteRequest) GetExternalHtlc() bool { + if m != nil { + return m.ExternalHtlc + } + return false +} + type QuoteResponse struct { //* //The fee that the swap server is charging for the swap. @@ -823,74 +834,74 @@ func init() { func init() { proto.RegisterFile("client.proto", fileDescriptor_014de31d7ac8c57c) } var fileDescriptor_014de31d7ac8c57c = []byte{ - // 1057 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x5d, 0x73, 0xda, 0x46, - 0x14, 0x0d, 0x02, 0x1b, 0xb8, 0x80, 0x80, 0x75, 0xe2, 0x10, 0xda, 0x4c, 0xa8, 0xda, 0xa4, 0x8c, - 0x1f, 0x4c, 0xeb, 0x3c, 0xb5, 0x6f, 0x04, 0x93, 0x98, 0x19, 0xdb, 0xb8, 0x02, 0x67, 0xa6, 0x7d, - 0xd9, 0x6e, 0x60, 0xb1, 0x35, 0x23, 0xed, 0x2a, 0xd2, 0xe2, 0x8f, 0xe9, 0xf4, 0xa5, 0xff, 0xa0, - 0xd3, 0xbf, 0xd2, 0x7f, 0xd2, 0xf7, 0x3e, 0x75, 0xfa, 0x3b, 0x3a, 0x7b, 0x57, 0xc8, 0x02, 0xd7, - 0x2f, 0x79, 0xc3, 0x67, 0xcf, 0x9e, 0xbd, 0x7b, 0xef, 0x39, 0x2b, 0x43, 0x75, 0xe6, 0x7b, 0x5c, - 0xa8, 0xfd, 0x30, 0x92, 0x4a, 0x92, 0xa2, 0x2f, 0x65, 0x18, 0x85, 0xb3, 0xf6, 0xe7, 0x17, 0x52, - 0x5e, 0xf8, 0xbc, 0xc7, 0x42, 0xaf, 0xc7, 0x84, 0x90, 0x8a, 0x29, 0x4f, 0x8a, 0xd8, 0xd0, 0x9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0f, 0xdb, 0xf8, - 0x8f, 0xca, 0xeb, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x88, 0xc1, 0x07, 0xdf, 0x08, 0x00, - 0x00, + // 1065 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x5f, 0x73, 0xda, 0xc6, + 0x17, 0x0d, 0x02, 0x1b, 0xb8, 0x08, 0x01, 0xeb, 0xc4, 0xc6, 0xfc, 0x7e, 0x99, 0x50, 0xb5, 0x49, + 0x19, 0x3f, 0x98, 0xd6, 0x79, 0x6a, 0xdf, 0x08, 0x26, 0x31, 0x33, 0xb6, 0x71, 0x05, 0xce, 0x4c, + 0xfb, 0xa2, 0x6e, 0x60, 0xb1, 0x35, 0x23, 0xed, 0x2a, 0xd2, 0xe2, 0x3f, 0xd3, 0xe9, 0x4b, 0xbf, + 0x41, 0xa7, 0x5f, 0xa5, 0xdf, 0xa4, 0xef, 0x7d, 0xea, 0xf4, 0x73, 0x74, 0xf6, 0xae, 0x90, 0x05, + 0xc4, 0x2f, 0x79, 0xc3, 0x67, 0xcf, 0x9e, 0xbd, 0x7b, 0xef, 0x39, 0x2b, 0x83, 0x39, 0xf5, 0x3d, + 0xc6, 0xe5, 0x61, 0x18, 0x09, 0x29, 0x48, 0xd1, 0x17, 0x22, 0x8c, 0xc2, 0x69, 0xeb, 0xff, 0x57, + 0x42, 0x5c, 0xf9, 0xac, 0x4b, 0x43, 0xaf, 0x4b, 0x39, 0x17, 0x92, 0x4a, 0x4f, 0xf0, 0x58, 0xd3, + 0xec, 0xbf, 0x0d, 0xb0, 0x4e, 0x85, 0x08, 0x47, 0x0b, 0xe9, 0xb0, 0x8f, 0x0b, 0x16, 0x4b, 0x52, + 0x87, 0x3c, 0x0d, 0x64, 0x33, 0xd7, 0xce, 0x75, 0xf2, 0x8e, 0xfa, 0x49, 0x08, 0x14, 0x66, 0x2c, +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2e, 0x9b, 0x67, 0xef, 0xfd, 0xf6, 0xd7, 0x3f, + 0x7f, 0x18, 0x0d, 0xdb, 0xec, 0xde, 0x7c, 0xdb, 0x55, 0x8c, 0xae, 0x58, 0xc8, 0xef, 0x73, 0x07, + 0x64, 0x04, 0xdb, 0xfa, 0x79, 0x25, 0xbb, 0x2b, 0x92, 0xe9, 0x7b, 0xfb, 0x98, 0xe2, 0x2e, 0x2a, + 0xd6, 0xed, 0x4a, 0xaa, 0xe8, 0x71, 0x25, 0xf8, 0x1d, 0x14, 0x93, 0x67, 0x2b, 0x53, 0xe4, 0xea, + 0x43, 0xd6, 0xda, 0xd9, 0x78, 0x61, 0x16, 0xf1, 0x37, 0x39, 0xf2, 0x23, 0x98, 0xc9, 0x6d, 0x30, + 0x74, 0xe4, 0xe1, 0xe4, 0x6c, 0x2a, 0x5b, 0xbb, 0xeb, 0x70, 0x52, 0x51, 0x0b, 0x2b, 0x7a, 0x4a, + 0x48, 0xf6, 0x8e, 0x5d, 0x89, 0x52, 0x6e, 0x2a, 0x8d, 0xa6, 0xca, 0x48, 0x67, 0xcd, 0x9c, 0x91, + 0x5e, 0xf1, 0x9e, 0xdd, 0x46, 0xe9, 0x16, 0x69, 0xae, 0x48, 0x7f, 0x54, 0x9c, 0xee, 0x2f, 0x34, + 0x90, 0xbf, 0x92, 0x9f, 0xc0, 0x7a, 0xc7, 0xa4, 0xee, 0xdc, 0x67, 0x55, 0xbf, 0x8f, 0x47, 0xec, + 0x90, 0x46, 0xa6, 0x9f, 0x49, 0xf1, 0x3f, 0x67, 0xb4, 0x3f, 0xab, 0xfc, 0x17, 0xa8, 0xbd, 0x4f, + 0xf6, 0xb2, 0xda, 0x99, 0xea, 0x3f, 0x6c, 0xe3, 0x7f, 0x33, 0xaf, 0xff, 0x0b, 0x00, 0x00, 0xff, + 0xff, 0x71, 0xf8, 0xf7, 0x7c, 0x04, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/looprpc/client.proto b/looprpc/client.proto index 792ec1c..0d54f15 100644 --- a/looprpc/client.proto +++ b/looprpc/client.proto @@ -355,6 +355,12 @@ message QuoteRequest { case of a Loop In. */ int32 conf_target = 2; + + /** + If external_htlc is true, we expect the htlc to be published by an external + actor. + */ + bool external_htlc = 3; } message QuoteResponse { diff --git a/looprpc/client.swagger.json b/looprpc/client.swagger.json index 887d327..43d001b 100644 --- a/looprpc/client.swagger.json +++ b/looprpc/client.swagger.json @@ -69,6 +69,14 @@ "required": false, "type": "integer", "format": "int32" + }, + { + "name": "external_htlc", + "description": "*\nIf external_htlc is true, we expect the htlc to be published by an external\nactor.", + "in": "query", + "required": false, + "type": "boolean", + "format": "boolean" } ], "tags": [ @@ -147,6 +155,14 @@ "required": false, "type": "integer", "format": "int32" + }, + { + "name": "external_htlc", + "description": "*\nIf external_htlc is true, we expect the htlc to be published by an external\nactor.", + "in": "query", + "required": false, + "type": "boolean", + "format": "boolean" } ], "tags": [ From 489ab5620ec0c3fc525e69466b9c99486fd46118 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 23 Sep 2019 10:08:34 +0200 Subject: [PATCH 3/4] loopd: receive external HTLC flag in loop in quote request --- client.go | 9 +++++++++ cmd/loopd/swapclient_server.go | 1 + interface.go | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/client.go b/client.go index 8e48bae..2422656 100644 --- a/client.go +++ b/client.go @@ -470,6 +470,15 @@ func (s *Client) LoopInQuote(ctx context.Context, request.Amount*btcutil.Amount(terms.SwapFeeRate)/ btcutil.Amount(swap.FeeRateTotalParts) + // We don't calculate the on-chain fee if the HTLC is going to be + // published externally. + if request.ExternalHtlc { + return &LoopInQuote{ + SwapFee: swapFee, + MinerFee: 0, + }, nil + } + // Get estimate for miner fee. minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH( ctx, request.Amount, request.HtlcConfTarget, diff --git a/cmd/loopd/swapclient_server.go b/cmd/loopd/swapclient_server.go index 89cf775..7579cb2 100644 --- a/cmd/loopd/swapclient_server.go +++ b/cmd/loopd/swapclient_server.go @@ -306,6 +306,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context, quote, err := s.impl.LoopInQuote(ctx, &loop.LoopInQuoteRequest{ Amount: btcutil.Amount(req.Amt), HtlcConfTarget: defaultConfTarget, + ExternalHtlc: req.ExternalHtlc, }) if err != nil { return nil, err diff --git a/interface.go b/interface.go index 04756f5..fadc2b8 100644 --- a/interface.go +++ b/interface.go @@ -224,6 +224,10 @@ type LoopInQuoteRequest struct { // HtlcConfTarget specifies the targeted confirmation target for the // client sweep tx. HtlcConfTarget int32 + + // ExternalHtlc specifies whether the htlc is published by an external + // source. + ExternalHtlc bool } // LoopInQuote contains estimates for the fees making up the total swap cost From c00f831675141b97f73976b3861784f4b13e5b92 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 23 Sep 2019 10:20:33 +0200 Subject: [PATCH 4/4] cmd/loop: handle external loop in flag --- cmd/loop/loopin.go | 10 ++++++---- cmd/loop/loopout.go | 2 +- cmd/loop/main.go | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmd/loop/loopin.go b/cmd/loop/loopin.go index cc56cf6..36b6be2 100644 --- a/cmd/loop/loopin.go +++ b/cmd/loop/loopin.go @@ -56,10 +56,12 @@ func loopIn(ctx *cli.Context) error { } defer cleanup() + external := ctx.Bool("external") quote, err := client.GetLoopInQuote( context.Background(), &looprpc.QuoteRequest{ - Amt: int64(amt), + Amt: int64(amt), + ExternalHtlc: external, }, ) if err != nil { @@ -67,8 +69,8 @@ func loopIn(ctx *cli.Context) error { } limits := getInLimits(amt, quote) - - if err := displayLimits(loop.TypeIn, amt, limits); err != nil { + err = displayLimits(loop.TypeIn, amt, limits, external) + if err != nil { return err } @@ -76,7 +78,7 @@ func loopIn(ctx *cli.Context) error { Amt: int64(amt), MaxMinerFee: int64(limits.maxMinerFee), MaxSwapFee: int64(limits.maxSwapFee), - ExternalHtlc: ctx.Bool("external"), + ExternalHtlc: external, }) if err != nil { return err diff --git a/cmd/loop/loopout.go b/cmd/loop/loopout.go index 97878ad..2fc2ef7 100644 --- a/cmd/loop/loopout.go +++ b/cmd/loop/loopout.go @@ -94,7 +94,7 @@ func loopOut(ctx *cli.Context) error { limits := getLimits(amt, quote) - if err := displayLimits(loop.TypeOut, amt, limits); err != nil { + if err := displayLimits(loop.TypeOut, amt, limits, false); err != nil { return err } diff --git a/cmd/loop/main.go b/cmd/loop/main.go index b518775..35fae92 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -116,7 +116,9 @@ func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits { } } -func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits) error { +func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits, + externalHtlc bool) error { + totalSuccessMax := l.maxMinerFee + l.maxSwapFee if l.maxSwapRoutingFee != nil { totalSuccessMax += *l.maxSwapRoutingFee @@ -124,6 +126,13 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits) error { if l.maxPrepayRoutingFee != nil { totalSuccessMax += *l.maxPrepayRoutingFee } + + if swapType == loop.TypeIn && externalHtlc { + fmt.Printf("On-chain fee for external loop in is not " + + "included.\nSufficient fees will need to be paid " + + "when constructing the transaction in the external " + + "wallet.\n\n") + } fmt.Printf("Max swap fees for %d Loop %v: %d\n", btcutil.Amount(amt), swapType, totalSuccessMax, @@ -139,7 +148,10 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits) error { return nil case "x": fmt.Println() - fmt.Printf("Max on-chain fee: %d\n", l.maxMinerFee) + if swapType != loop.TypeIn || !externalHtlc { + fmt.Printf("Max on-chain fee: %d\n", + l.maxMinerFee) + } if l.maxSwapRoutingFee != nil { fmt.Printf("Max off-chain swap routing fee: %d\n",