From 433dabcc02c46d2ff038946fe2525a41b9e29b43 Mon Sep 17 00:00:00 2001 From: sampocs Date: Sat, 10 Dec 2022 11:45:03 -0600 Subject: [PATCH] Add Query for Pending ICQs (#495) --- proto/stride/interchainquery/v1/query.proto | 21 + x/interchainquery/README.md | 36 +- x/interchainquery/client/cli/query.go | 69 +++ x/interchainquery/keeper/grpc_query.go | 25 + x/interchainquery/module.go | 14 +- x/interchainquery/types/query.pb.go | 543 ++++++++++++++++++++ x/interchainquery/types/query.pb.gw.go | 153 ++++++ 7 files changed, 841 insertions(+), 20 deletions(-) create mode 100644 proto/stride/interchainquery/v1/query.proto create mode 100644 x/interchainquery/client/cli/query.go create mode 100644 x/interchainquery/keeper/grpc_query.go create mode 100644 x/interchainquery/types/query.pb.go create mode 100644 x/interchainquery/types/query.pb.gw.go diff --git a/proto/stride/interchainquery/v1/query.proto b/proto/stride/interchainquery/v1/query.proto new file mode 100644 index 0000000000..c1907e8faa --- /dev/null +++ b/proto/stride/interchainquery/v1/query.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package stride.interchainquery.v1; + +import "stride/interchainquery/v1/genesis.proto"; +import "google/api/annotations.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/Stride-Labs/stride/v4/x/interchainquery/types"; + +service QueryService { + rpc PendingQueries(QueryPendingQueriesRequest) + returns (QueryPendingQueriesResponse) { + option (google.api.http).get = + "/Stride-Labs/stride/interchainquery/pending_queries"; + } +} + +message QueryPendingQueriesRequest {} +message QueryPendingQueriesResponse { + repeated Query pending_queries = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/x/interchainquery/README.md b/x/interchainquery/README.md index 284af092d6..126b90726c 100644 --- a/x/interchainquery/README.md +++ b/x/interchainquery/README.md @@ -23,6 +23,7 @@ Stride uses interchain queries and interchain accounts to perform multichain liq 3. **[Events](#events)** 4. **[Keeper](#keeper)** 5. **[Msgs](#msgs)** +6. **[Queries](#queries)** ## State @@ -33,15 +34,13 @@ The `interchainquery` module keeps `Query` objects and modifies the information `Query` has information types that pertain to the query itself. `Query` keeps the following: 1. `id` keeps the query identification string. -2. `connection_id` keeps the id of the channel or connection between the controller and host chain. +2. `connection_id` keeps the id of the connection between the controller and host chain. 3. `chain_id` keeps the id of the queried chain. -4. `query_type` keeps the type of interchain query +4. `query_type` keeps the type of interchain query (e.g. bank store query) 5. `request` keeps an bytecode encoded version of the interchain query -6. `period` TODO -7. `last_height` keeps the blockheight of the last block before the query was made -8. `callback_id` keeps the function that will be called by the interchain query -9. `ttl` TODO -10. `height` keeps the height at which the ICQ query should execute on the host zone. This is often `0`, meaning the query should execute at the latest height on the host zone. +6. `callback_id` keeps the function that will be called by the interchain query +7. `ttl` time at which the query expires (in unix nano) +8. `request_sent` keeps a boolean indicating whether the query event has been emitted (and can be identified by a relayer) `DataPoint` has information types that pertain to the data that is queried. `DataPoint` keeps the following: @@ -52,7 +51,7 @@ The `interchainquery` module keeps `Query` objects and modifies the information ## Events -The `interchainquery` module emits an event at the end of every 3 `stride_epoch`s (e.g. 15 minutes on local testnet). +The `interchainquery` module emits an event at the end of every `stride_epoch`s (e.g. 15 minutes on local testnet). The purpose of this event is to send interchainqueries that query data about staking rewards, which Stride uses to reinvest (aka autocompound) staking rewards. @@ -65,7 +64,6 @@ The purpose of this event is to send interchainqueries that query data about sta sdk.NewAttribute(types.AttributeKeyChainId, queryInfo.ChainId), sdk.NewAttribute(types.AttributeKeyConnectionId, queryInfo.ConnectionId), sdk.NewAttribute(types.AttributeKeyType, queryInfo.QueryType), - // TODO: add height to request type sdk.NewAttribute(types.AttributeKeyHeight, "0"), sdk.NewAttribute(types.AttributeKeyRequest, hex.EncodeToString(queryInfo.Request)), ) @@ -91,12 +89,22 @@ AllQueries(ctx sdk.Context) []types.Query ## Msgs -`interchainquery` has a `Msg` service that passes messages between chains. - ```protobuf -service Msg { - // SubmitQueryResponse defines a method for submiting query responses. - rpc SubmitQueryResponse(MsgSubmitQueryResponse) returns (MsgSubmitQueryResponseResponse) +// SubmitQueryResponse is used to return the query response back to Stride +message MsgSubmitQueryResponse { + string chain_id = 1; + string query_id = 2; + bytes result = 3; + tendermint.crypto.ProofOps proof_ops = 4; + int64 height = 5; + string from_address = 6; } ``` +## Queries +```protobuf +// Query PendingQueries lists all queries that have been requested (i.e. emitted) +// but have not had a response submitted yet +message QueryPendingQueriesRequest {} +``` + diff --git a/x/interchainquery/client/cli/query.go b/x/interchainquery/client/cli/query.go new file mode 100644 index 0000000000..94598c4211 --- /dev/null +++ b/x/interchainquery/client/cli/query.go @@ -0,0 +1,69 @@ +package cli + +import ( + "context" + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/Stride-Labs/stride/v4/x/interchainquery/types" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + // Group lockup queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetCmdListPendingQueries(), + ) + + return cmd +} + +// GetCmdQueries provides a list of all pending queries +// (queries that have not have been requested but have not received a response) +func GetCmdListPendingQueries() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-pending-queries", + Short: "Query all pending queries", + Example: strings.TrimSpace( + fmt.Sprintf(`$ %s query interchainquery list-pending-queries`, + version.AppName, + ), + ), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryServiceClient(clientCtx) + + req := &types.QueryPendingQueriesRequest{} + + res, err := queryClient.PendingQueries(context.Background(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchainquery/keeper/grpc_query.go b/x/interchainquery/keeper/grpc_query.go new file mode 100644 index 0000000000..ef11a58e2d --- /dev/null +++ b/x/interchainquery/keeper/grpc_query.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v4/x/interchainquery/types" +) + +var _ types.QueryServiceServer = Keeper{} + +// Queries all queries that have been requested but have not received a response +func (k Keeper) PendingQueries(c context.Context, req *types.QueryPendingQueriesRequest) (*types.QueryPendingQueriesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + pendingQueries := []types.Query{} + for _, query := range k.AllQueries(ctx) { + if query.RequestSent { + pendingQueries = append(pendingQueries, query) + } + } + + return &types.QueryPendingQueriesResponse{PendingQueries: pendingQueries}, nil +} diff --git a/x/interchainquery/module.go b/x/interchainquery/module.go index aa68abdbf2..ba857d7834 100644 --- a/x/interchainquery/module.go +++ b/x/interchainquery/module.go @@ -1,6 +1,7 @@ package interchainquery import ( + "context" "encoding/json" "math/rand" @@ -20,6 +21,7 @@ import ( "github.com/Stride-Labs/stride/v4/x/interchainquery/keeper" + "github.com/Stride-Labs/stride/v4/x/interchainquery/client/cli" "github.com/Stride-Labs/stride/v4/x/interchainquery/types" ) @@ -78,10 +80,10 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - // err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - // if err != nil { - // panic(err) - // } + err := types.RegisterQueryServiceHandlerClient(context.Background(), mux, types.NewQueryServiceClient(clientCtx)) + if err != nil { + panic(err) + } } // GetTxCmd returns the capability module's root tx command. @@ -91,7 +93,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns the capability module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // ---------------------------------------------------------------------------- @@ -134,7 +136,7 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - // types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterQueryServiceServer(cfg.QueryServer(), am.keeper) } // RegisterInvariants registers the capability module's invariants. diff --git a/x/interchainquery/types/query.pb.go b/x/interchainquery/types/query.pb.go new file mode 100644 index 0000000000..2a6a29a9b1 --- /dev/null +++ b/x/interchainquery/types/query.pb.go @@ -0,0 +1,543 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/interchainquery/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/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" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryPendingQueriesRequest struct { +} + +func (m *QueryPendingQueriesRequest) Reset() { *m = QueryPendingQueriesRequest{} } +func (m *QueryPendingQueriesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPendingQueriesRequest) ProtoMessage() {} +func (*QueryPendingQueriesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b720c147b9144d5b, []int{0} +} +func (m *QueryPendingQueriesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPendingQueriesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPendingQueriesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPendingQueriesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPendingQueriesRequest.Merge(m, src) +} +func (m *QueryPendingQueriesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPendingQueriesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPendingQueriesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPendingQueriesRequest proto.InternalMessageInfo + +type QueryPendingQueriesResponse struct { + PendingQueries []Query `protobuf:"bytes,1,rep,name=pending_queries,json=pendingQueries,proto3" json:"pending_queries"` +} + +func (m *QueryPendingQueriesResponse) Reset() { *m = QueryPendingQueriesResponse{} } +func (m *QueryPendingQueriesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPendingQueriesResponse) ProtoMessage() {} +func (*QueryPendingQueriesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b720c147b9144d5b, []int{1} +} +func (m *QueryPendingQueriesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPendingQueriesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPendingQueriesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryPendingQueriesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPendingQueriesResponse.Merge(m, src) +} +func (m *QueryPendingQueriesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPendingQueriesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPendingQueriesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPendingQueriesResponse proto.InternalMessageInfo + +func (m *QueryPendingQueriesResponse) GetPendingQueries() []Query { + if m != nil { + return m.PendingQueries + } + return nil +} + +func init() { + proto.RegisterType((*QueryPendingQueriesRequest)(nil), "stride.interchainquery.v1.QueryPendingQueriesRequest") + proto.RegisterType((*QueryPendingQueriesResponse)(nil), "stride.interchainquery.v1.QueryPendingQueriesResponse") +} + +func init() { + proto.RegisterFile("stride/interchainquery/v1/query.proto", fileDescriptor_b720c147b9144d5b) +} + +var fileDescriptor_b720c147b9144d5b = []byte{ + // 313 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x2e, 0x29, 0xca, + 0x4c, 0x49, 0xd5, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0x2b, 0x2c, 0x4d, + 0x2d, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x07, 0x33, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x24, + 0x21, 0xca, 0xf4, 0xd0, 0x94, 0xe9, 0x95, 0x19, 0x4a, 0xa9, 0xe3, 0x36, 0x21, 0x3d, 0x35, 0x2f, + 0xb5, 0x38, 0xb3, 0x18, 0x62, 0x86, 0x94, 0x4c, 0x7a, 0x7e, 0x7e, 0x7a, 0x4e, 0xaa, 0x7e, 0x62, + 0x41, 0xa6, 0x7e, 0x62, 0x5e, 0x5e, 0x7e, 0x49, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x4c, 0x56, 0x24, + 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, 0x20, 0xa2, 0x4a, 0x32, 0x5c, 0x52, 0x81, 0x20, + 0xd3, 0x02, 0x52, 0xf3, 0x52, 0x32, 0xf3, 0xd2, 0x41, 0xec, 0xcc, 0xd4, 0xe2, 0xa0, 0xd4, 0xc2, + 0xd2, 0xd4, 0xe2, 0x12, 0xa5, 0x3c, 0x2e, 0x69, 0xac, 0xb2, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, + 0x42, 0xfe, 0x5c, 0xfc, 0x05, 0x10, 0x99, 0xf8, 0x42, 0x88, 0x94, 0x04, 0xa3, 0x02, 0xb3, 0x06, + 0xb7, 0x91, 0x82, 0x1e, 0x4e, 0xef, 0xe8, 0x81, 0x0d, 0x74, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, + 0x88, 0xaf, 0x00, 0xc5, 0x60, 0xa3, 0xb3, 0x8c, 0x5c, 0x3c, 0x60, 0xf9, 0xe0, 0xd4, 0xa2, 0xb2, + 0xcc, 0xe4, 0x54, 0xa1, 0x3d, 0x8c, 0x5c, 0x7c, 0xa8, 0x96, 0x0b, 0x99, 0x12, 0x32, 0x1b, 0xab, + 0x57, 0xa4, 0xcc, 0x48, 0xd5, 0x06, 0xf1, 0xa3, 0x92, 0x75, 0xd3, 0xe5, 0x27, 0x93, 0x99, 0x4c, + 0x85, 0x8c, 0xf5, 0x83, 0xc1, 0xfa, 0x75, 0x7d, 0x12, 0x93, 0x8a, 0xf5, 0x71, 0x44, 0x09, 0x5a, + 0x68, 0x38, 0x05, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, + 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x45, 0x7a, + 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0x36, 0x83, 0xcb, 0x4c, 0xf4, 0x2b, 0x30, + 0x4c, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x47, 0x9c, 0x31, 0x20, 0x00, 0x00, 0xff, + 0xff, 0xcf, 0x30, 0xb6, 0x38, 0x59, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryServiceClient is the client API for QueryService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryServiceClient interface { + PendingQueries(ctx context.Context, in *QueryPendingQueriesRequest, opts ...grpc.CallOption) (*QueryPendingQueriesResponse, error) +} + +type queryServiceClient struct { + cc grpc1.ClientConn +} + +func NewQueryServiceClient(cc grpc1.ClientConn) QueryServiceClient { + return &queryServiceClient{cc} +} + +func (c *queryServiceClient) PendingQueries(ctx context.Context, in *QueryPendingQueriesRequest, opts ...grpc.CallOption) (*QueryPendingQueriesResponse, error) { + out := new(QueryPendingQueriesResponse) + err := c.cc.Invoke(ctx, "/stride.interchainquery.v1.QueryService/PendingQueries", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServiceServer is the server API for QueryService service. +type QueryServiceServer interface { + PendingQueries(context.Context, *QueryPendingQueriesRequest) (*QueryPendingQueriesResponse, error) +} + +// UnimplementedQueryServiceServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServiceServer struct { +} + +func (*UnimplementedQueryServiceServer) PendingQueries(ctx context.Context, req *QueryPendingQueriesRequest) (*QueryPendingQueriesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PendingQueries not implemented") +} + +func RegisterQueryServiceServer(s grpc1.Server, srv QueryServiceServer) { + s.RegisterService(&_QueryService_serviceDesc, srv) +} + +func _QueryService_PendingQueries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPendingQueriesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServiceServer).PendingQueries(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.interchainquery.v1.QueryService/PendingQueries", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServiceServer).PendingQueries(ctx, req.(*QueryPendingQueriesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _QueryService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.interchainquery.v1.QueryService", + HandlerType: (*QueryServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "PendingQueries", + Handler: _QueryService_PendingQueries_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/interchainquery/v1/query.proto", +} + +func (m *QueryPendingQueriesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPendingQueriesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPendingQueriesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryPendingQueriesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryPendingQueriesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPendingQueriesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PendingQueries) > 0 { + for iNdEx := len(m.PendingQueries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PendingQueries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryPendingQueriesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryPendingQueriesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PendingQueries) > 0 { + for _, e := range m.PendingQueries { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryPendingQueriesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPendingQueriesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPendingQueriesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPendingQueriesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryPendingQueriesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPendingQueriesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PendingQueries", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PendingQueries = append(m.PendingQueries, Query{}) + if err := m.PendingQueries[len(m.PendingQueries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/interchainquery/types/query.pb.gw.go b/x/interchainquery/types/query.pb.gw.go new file mode 100644 index 0000000000..aaf3eb83c5 --- /dev/null +++ b/x/interchainquery/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stride/interchainquery/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_QueryService_PendingQueries_0(ctx context.Context, marshaler runtime.Marshaler, client QueryServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPendingQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := client.PendingQueries(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_QueryService_PendingQueries_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPendingQueriesRequest + var metadata runtime.ServerMetadata + + msg, err := server.PendingQueries(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryServiceHandlerServer registers the http handlers for service QueryService to "mux". +// UnaryRPC :call QueryServiceServer 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 to stop working. Consider using RegisterQueryServiceHandlerFromEndpoint instead. +func RegisterQueryServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServiceServer) error { + + mux.Handle("GET", pattern_QueryService_PendingQueries_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 { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_QueryService_PendingQueries_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) + return + } + + forward_QueryService_PendingQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryServiceHandlerFromEndpoint is same as RegisterQueryServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("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) + } + }() + }() + + return RegisterQueryServiceHandler(ctx, mux, conn) +} + +// RegisterQueryServiceHandler registers the http handlers for service QueryService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryServiceHandlerClient(ctx, mux, NewQueryServiceClient(conn)) +} + +// RegisterQueryServiceHandlerClient registers the http handlers for service QueryService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryServiceClient" to call the correct interceptors. +func RegisterQueryServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryServiceClient) error { + + mux.Handle("GET", pattern_QueryService_PendingQueries_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 := request_QueryService_PendingQueries_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_QueryService_PendingQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_QueryService_PendingQueries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"Stride-Labs", "stride", "interchainquery", "pending_queries"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_QueryService_PendingQueries_0 = runtime.ForwardResponseMessage +)