From d9d4200b92d953e7c619738c8495598679a6c887 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:44:39 +0200 Subject: [PATCH] feat: add query proto wrap --- x/amm/types/query.pb.gw.go | 19 +++++++- x/oracle/client/grpc/grpc_query.go | 67 +++++++++++++++++++++++++++++ x/oracle/client/query_proto_wrap.go | 19 ++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 x/oracle/client/grpc/grpc_query.go create mode 100644 x/oracle/client/query_proto_wrap.go diff --git a/x/amm/types/query.pb.gw.go b/x/amm/types/query.pb.gw.go index 2babba22a..3b891ece9 100644 --- a/x/amm/types/query.pb.gw.go +++ b/x/amm/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -232,12 +234,14 @@ func local_request_Query_DenomLiquidityAll_0(ctx context.Context, marshaler runt // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -245,6 +249,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -258,6 +263,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -265,6 +272,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Pool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -278,6 +286,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_PoolAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -285,6 +295,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_PoolAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -298,6 +309,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidity_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -305,6 +318,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidity_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -318,6 +332,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidityAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -325,6 +341,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidityAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/oracle/client/grpc/grpc_query.go b/x/oracle/client/grpc/grpc_query.go new file mode 100644 index 000000000..703faef6d --- /dev/null +++ b/x/oracle/client/grpc/grpc_query.go @@ -0,0 +1,67 @@ +package grpc + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/elys-network/elys/x/oracle/client" + "github.com/elys-network/elys/x/oracle/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type Querier struct { + Q client.Querier +} + +var _ types.QueryServer = Querier{} + +func (q Querier) PriceAll(grpcCtx context.Context, req *types.QueryAllPriceRequest) (*types.QueryAllPriceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.PriceAll(ctx, *req) +} + +// implment those functions +func (q Querier) Params(context.Context, *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + panic("implement me") +} + +// BandPriceResult defines a rpc handler method for MsgRequestBandPrice. +func (q Querier) BandPriceResult(context.Context, *types.QueryBandPriceRequest) (*types.QueryBandPriceResponse, error) { + panic("implement me") +} + +// LastBandRequestId query the last BandPrice result id +func (q Querier) LastBandRequestId(context.Context, *types.QueryLastBandRequestIdRequest) (*types.QueryLastBandRequestIdResponse, error) { + panic("implement me") +} + +// Queries a AssetInfo by denom. +func (q Querier) AssetInfo(context.Context, *types.QueryGetAssetInfoRequest) (*types.QueryGetAssetInfoResponse, error) { + panic("implement me") +} + +// Queries a list of AssetInfo items. +func (q Querier) AssetInfoAll(context.Context, *types.QueryAllAssetInfoRequest) (*types.QueryAllAssetInfoResponse, error) { + panic("implement me") +} + +// Queries a Price by asset. +func (q Querier) Price(context.Context, *types.QueryGetPriceRequest) (*types.QueryGetPriceResponse, error) { + panic("implement me") +} + +// Queries a PriceFeeder by feeder. +func (q Querier) PriceFeeder(context.Context, *types.QueryGetPriceFeederRequest) (*types.QueryGetPriceFeederResponse, error) { + panic("implement me") +} + +// Queries a list of PriceFeeder items. +func (q Querier) PriceFeederAll(context.Context, *types.QueryAllPriceFeederRequest) (*types.QueryAllPriceFeederResponse, error) { + panic("implement me") +} diff --git a/x/oracle/client/query_proto_wrap.go b/x/oracle/client/query_proto_wrap.go new file mode 100644 index 000000000..0ae137295 --- /dev/null +++ b/x/oracle/client/query_proto_wrap.go @@ -0,0 +1,19 @@ +package client + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/oracle/keeper" + "github.com/elys-network/elys/x/oracle/types" +) + +type Querier struct { + K keeper.Keeper +} + +func NewQuerier(k keeper.Keeper) Querier { + return Querier{K: k} +} + +func (q Querier) PriceAll(ctx sdk.Context, req types.QueryAllPriceRequest) (*types.QueryAllPriceResponse, error) { + return q.K.PriceAll(ctx, &req) +}