diff --git a/baseapp/abci.go b/baseapp/abci.go index 72173ada2226..21c7901be3df 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -294,6 +294,10 @@ func (app *BaseApp) halt() { // Query implements the ABCI interface. It delegates to CommitMultiStore if it // implements Queryable. func (app *BaseApp) Query(req abci.RequestQuery) abci.ResponseQuery { + if grpcHandler := app.grpcRouter.Route(req.Path); grpcHandler != nil { + return handleQueryGRPC(app, grpcHandler, req) + } + path := splitPath(req.Path) if len(path) == 0 { sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided")) @@ -317,6 +321,51 @@ func (app *BaseApp) Query(req abci.RequestQuery) abci.ResponseQuery { return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path")) } +func handleQueryGRPC(app *BaseApp, handler GRPCHandler, req abci.RequestQuery) abci.ResponseQuery { + // when a client did not provide a query height, manually inject the latest + if req.Height == 0 { + req.Height = app.LastBlockHeight() + } + + if req.Height <= 1 && req.Prove { + return sdkerrors.QueryResult( + sdkerrors.Wrap( + sdkerrors.ErrInvalidRequest, + "cannot query with proof when height <= 1; please provide a valid height", + ), + ) + } + + cacheMS, err := app.cms.CacheMultiStoreWithVersion(req.Height) + if err != nil { + return sdkerrors.QueryResult( + sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "failed to load state at height %d; %s (latest height: %d)", req.Height, err, app.LastBlockHeight(), + ), + ) + } + + // cache wrap the commit-multistore for safety + ctx := sdk.NewContext( + cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger, + ).WithMinGasPrices(app.minGasPrices) + + res, err := handler(ctx, req) + + if err != nil { + space, code, log := sdkerrors.ABCIInfo(err, false) + return abci.ResponseQuery{ + Code: code, + Codespace: space, + Log: log, + Height: req.Height, + } + } + + return res +} + func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery { if len(path) >= 2 { switch path[1] { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 22747e80fe90..3535cb327de0 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -6,6 +6,8 @@ import ( "runtime/debug" "strings" + "github.com/gogo/protobuf/grpc" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/log" @@ -48,6 +50,7 @@ type BaseApp struct { // nolint: maligned storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader() router sdk.Router // handle any kind of message queryRouter sdk.QueryRouter // router for redirecting query calls + grpcRouter *GRPCRouter // router for redirecting gRPC query calls txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx anteHandler sdk.AnteHandler // ante handler for fee and auth @@ -108,6 +111,7 @@ func NewBaseApp( storeLoader: DefaultStoreLoader, router: NewRouter(), queryRouter: NewQueryRouter(), + grpcRouter: NewGRPCRouter(), txDecoder: txDecoder, fauxMerkleMode: false, } @@ -282,6 +286,9 @@ func (app *BaseApp) Router() sdk.Router { // QueryRouter returns the QueryRouter of a BaseApp. func (app *BaseApp) QueryRouter() sdk.QueryRouter { return app.queryRouter } +// GRPCRouter returns the GRPCRouter of a BaseApp. +func (app *BaseApp) GRPCRouter() grpc.Server { return app.grpcRouter } + // Seal seals a BaseApp. It prohibits any further modifications to a BaseApp. func (app *BaseApp) Seal() { app.sealed = true } diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go new file mode 100644 index 000000000000..e9c8915a1449 --- /dev/null +++ b/baseapp/grpcrouter.go @@ -0,0 +1,108 @@ +package baseapp + +import ( + gocontext "context" + "fmt" + + gogogrpc "github.com/gogo/protobuf/grpc" + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var protoCodec = encoding.GetCodec(proto.Name) + +type GRPCRouter struct { + routes map[string]GRPCHandler +} + +var _ gogogrpc.Server + +func NewGRPCRouter() *GRPCRouter { + return &GRPCRouter{ + routes: map[string]GRPCHandler{}, + } +} + +type GRPCHandler = func(ctx sdk.Context, req abci.RequestQuery) (abci.ResponseQuery, error) + +// Route returns the Querier for a given query route path. +func (qrt *GRPCRouter) Route(path string) GRPCHandler { + handler, found := qrt.routes[path] + if !found { + return nil + } + return handler +} + +// RegisterService implements the grpc Server.RegisterService method +func (qrt *GRPCRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) { + // adds a top-level querier based on the GRPC service name + for _, method := range sd.Methods { + fqName := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName) + methodHandler := method.Handler + + qrt.routes[fqName] = func(ctx sdk.Context, req abci.RequestQuery) (abci.ResponseQuery, error) { + res, err := methodHandler(handler, sdk.WrapSDKContext(ctx), func(i interface{}) error { + return protoCodec.Unmarshal(req.Data, i) + }, nil) + if err != nil { + return abci.ResponseQuery{}, err + } + + resBytes, err := protoCodec.Marshal(res) + if err != nil { + return abci.ResponseQuery{}, err + } + + return abci.ResponseQuery{ + Height: req.Height, + Value: resBytes, + }, nil + } + } +} + +// QueryServiceTestHelper provides a helper for making grpc query service +// rpc calls in unit tests. It implements both the grpc Server and ClientConn +// interfaces needed to register a query service server and create a query +// service client. +type QueryServiceTestHelper struct { + *GRPCRouter + ctx sdk.Context +} + +// NewQueryServerTestHelper creates a new QueryServiceTestHelper that wraps +// the provided sdk.Context +func NewQueryServerTestHelper(ctx sdk.Context) *QueryServiceTestHelper { + return &QueryServiceTestHelper{GRPCRouter: NewGRPCRouter(), ctx: ctx} +} + +// Invoke implements the grpc ClientConn.Invoke method +func (q *QueryServiceTestHelper) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { + querier := q.Route(method) + if querier == nil { + return fmt.Errorf("handler not found for %s", method) + } + reqBz, err := protoCodec.Marshal(args) + if err != nil { + return err + } + res, err := querier(q.ctx, abci.RequestQuery{Data: reqBz}) + + if err != nil { + return err + } + return protoCodec.Unmarshal(res.Value, reply) +} + +// NewStream implements the grpc ClientConn.NewStream method +func (q *QueryServiceTestHelper) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, fmt.Errorf("not supported") +} + +var _ gogogrpc.Server = &QueryServiceTestHelper{} +var _ gogogrpc.ClientConn = &QueryServiceTestHelper{} diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go new file mode 100644 index 000000000000..0db3e9c51dc3 --- /dev/null +++ b/baseapp/grpcrouter_test.go @@ -0,0 +1,49 @@ +package baseapp + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type testServer struct{} + +func (e testServer) Echo(_ context.Context, req *testdata.EchoRequest) (*testdata.EchoResponse, error) { + return &testdata.EchoResponse{Message: req.Message}, nil +} + +func (e testServer) SayHello(_ context.Context, request *testdata.SayHelloRequest) (*testdata.SayHelloResponse, error) { + greeting := fmt.Sprintf("Hello %s!", request.Name) + return &testdata.SayHelloResponse{Greeting: greeting}, nil +} + +var _ testdata.TestServiceServer = testServer{} + +func TestGRPCRouter(t *testing.T) { + qr := NewGRPCRouter() + testdata.RegisterTestServiceServer(qr, testServer{}) + helper := &QueryServiceTestHelper{ + GRPCRouter: qr, + ctx: sdk.Context{}, + } + client := testdata.NewTestServiceClient(helper) + + res, err := client.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}) + require.Nil(t, err) + require.NotNil(t, res) + require.Equal(t, "hello", res.Message) + + require.Panics(t, func() { + _, _ = client.Echo(context.Background(), nil) + }) + + res2, err := client.SayHello(context.Background(), &testdata.SayHelloRequest{Name: "Foo"}) + require.Nil(t, err) + require.NotNil(t, res) + require.Equal(t, "Hello Foo!", res2.Greeting) +} diff --git a/buf.yaml b/buf.yaml index ba91745ba7d5..9dbea6b153a6 100644 --- a/buf.yaml +++ b/buf.yaml @@ -12,6 +12,7 @@ lint: - UNARY_RPC - COMMENT_FIELD - PACKAGE_DIRECTORY_MATCH + - SERVICE_SUFFIX ignore: - third_party - codec/testdata @@ -20,3 +21,4 @@ breaking: - FILE ignore: - third_party + - codec/testdata diff --git a/client/query.go b/client/query.go index 674cae599ab8..e1e91f1beda9 100644 --- a/client/query.go +++ b/client/query.go @@ -1,9 +1,15 @@ package client import ( + "context" "fmt" "strings" + gogogrpc "github.com/gogo/protobuf/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/encoding/proto" + "github.com/pkg/errors" abci "github.com/tendermint/tendermint/abci/types" @@ -233,3 +239,35 @@ func parseQueryStorePath(path string) (storeName string, err error) { return paths[1], nil } + +// QueryConn returns a new grpc ClientConn for making grpc query calls that +// get routed to the node's ABCI query handler +func (ctx Context) QueryConn() gogogrpc.ClientConn { + return cliQueryConn{ctx} +} + +type cliQueryConn struct { + ctx Context +} + +var _ gogogrpc.ClientConn = cliQueryConn{} + +var protoCodec = encoding.GetCodec(proto.Name) + +// Invoke implements the grpc ClientConn.Invoke method +func (c cliQueryConn) Invoke(_ context.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error { + reqBz, err := protoCodec.Marshal(args) + if err != nil { + return err + } + resBz, _, err := c.ctx.QueryWithData(method, reqBz) + if err != nil { + return err + } + return protoCodec.Unmarshal(resBz, reply) +} + +// NewStream implements the grpc ClientConn.NewStream method +func (c cliQueryConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, fmt.Errorf("streaming rpc not supported") +} diff --git a/codec/testdata/proto.pb.go b/codec/testdata/proto.pb.go index 8250f11e4001..458fc7987b62 100644 --- a/codec/testdata/proto.pb.go +++ b/codec/testdata/proto.pb.go @@ -4,9 +4,14 @@ package testdata import ( + context "context" fmt "fmt" types "github.com/cosmos/cosmos-sdk/codec/types" + grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + 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" @@ -267,37 +272,341 @@ func (m *HasHasHasAnimal) GetHasHasAnimal() *types.Any { return nil } +type EchoRequest struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (m *EchoRequest) Reset() { *m = EchoRequest{} } +func (m *EchoRequest) String() string { return proto.CompactTextString(m) } +func (*EchoRequest) ProtoMessage() {} +func (*EchoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ae1353846770e6e2, []int{5} +} +func (m *EchoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EchoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EchoRequest.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 *EchoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_EchoRequest.Merge(m, src) +} +func (m *EchoRequest) XXX_Size() int { + return m.Size() +} +func (m *EchoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_EchoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_EchoRequest proto.InternalMessageInfo + +func (m *EchoRequest) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +type EchoResponse struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (m *EchoResponse) Reset() { *m = EchoResponse{} } +func (m *EchoResponse) String() string { return proto.CompactTextString(m) } +func (*EchoResponse) ProtoMessage() {} +func (*EchoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ae1353846770e6e2, []int{6} +} +func (m *EchoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EchoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EchoResponse.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 *EchoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_EchoResponse.Merge(m, src) +} +func (m *EchoResponse) XXX_Size() int { + return m.Size() +} +func (m *EchoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_EchoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_EchoResponse proto.InternalMessageInfo + +func (m *EchoResponse) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +type SayHelloRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *SayHelloRequest) Reset() { *m = SayHelloRequest{} } +func (m *SayHelloRequest) String() string { return proto.CompactTextString(m) } +func (*SayHelloRequest) ProtoMessage() {} +func (*SayHelloRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ae1353846770e6e2, []int{7} +} +func (m *SayHelloRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SayHelloRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SayHelloRequest.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 *SayHelloRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SayHelloRequest.Merge(m, src) +} +func (m *SayHelloRequest) XXX_Size() int { + return m.Size() +} +func (m *SayHelloRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SayHelloRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SayHelloRequest proto.InternalMessageInfo + +func (m *SayHelloRequest) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +type SayHelloResponse struct { + Greeting string `protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"` +} + +func (m *SayHelloResponse) Reset() { *m = SayHelloResponse{} } +func (m *SayHelloResponse) String() string { return proto.CompactTextString(m) } +func (*SayHelloResponse) ProtoMessage() {} +func (*SayHelloResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ae1353846770e6e2, []int{8} +} +func (m *SayHelloResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SayHelloResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SayHelloResponse.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 *SayHelloResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SayHelloResponse.Merge(m, src) +} +func (m *SayHelloResponse) XXX_Size() int { + return m.Size() +} +func (m *SayHelloResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SayHelloResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SayHelloResponse proto.InternalMessageInfo + +func (m *SayHelloResponse) GetGreeting() string { + if m != nil { + return m.Greeting + } + return "" +} + func init() { proto.RegisterType((*Dog)(nil), "cosmos_sdk.codec.v1.Dog") proto.RegisterType((*Cat)(nil), "cosmos_sdk.codec.v1.Cat") proto.RegisterType((*HasAnimal)(nil), "cosmos_sdk.codec.v1.HasAnimal") proto.RegisterType((*HasHasAnimal)(nil), "cosmos_sdk.codec.v1.HasHasAnimal") proto.RegisterType((*HasHasHasAnimal)(nil), "cosmos_sdk.codec.v1.HasHasHasAnimal") + proto.RegisterType((*EchoRequest)(nil), "cosmos_sdk.codec.v1.EchoRequest") + proto.RegisterType((*EchoResponse)(nil), "cosmos_sdk.codec.v1.EchoResponse") + proto.RegisterType((*SayHelloRequest)(nil), "cosmos_sdk.codec.v1.SayHelloRequest") + proto.RegisterType((*SayHelloResponse)(nil), "cosmos_sdk.codec.v1.SayHelloResponse") } func init() { proto.RegisterFile("codec/testdata/proto.proto", fileDescriptor_ae1353846770e6e2) } var fileDescriptor_ae1353846770e6e2 = []byte{ - // 304 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xbf, 0x4e, 0xc3, 0x30, - 0x10, 0xc6, 0x6b, 0x4a, 0x8b, 0x7a, 0x54, 0x20, 0x99, 0x0e, 0xa1, 0x83, 0x85, 0x32, 0x21, 0x41, - 0x1d, 0x41, 0xc5, 0xc2, 0x56, 0x0a, 0xa2, 0x0b, 0x4b, 0x46, 0x96, 0xca, 0x49, 0x4c, 0x12, 0xe5, - 0x8f, 0x51, 0xed, 0x56, 0x2d, 0x4f, 0xc1, 0x63, 0x31, 0x76, 0x64, 0x44, 0xc9, 0x8b, 0xa0, 0xd8, - 0x89, 0x0a, 0x5b, 0x17, 0xfb, 0xbb, 0xd3, 0xf7, 0xfd, 0xee, 0xa4, 0x83, 0xa1, 0x2f, 0x02, 0xee, - 0x3b, 0x8a, 0x4b, 0x15, 0x30, 0xc5, 0x9c, 0xf7, 0x85, 0x50, 0x82, 0xea, 0x17, 0x9f, 0xf9, 0x42, - 0x66, 0x42, 0xce, 0x65, 0x90, 0x50, 0x6d, 0xa3, 0xab, 0x9b, 0xe1, 0x79, 0x28, 0x44, 0x98, 0x72, - 0x63, 0xf4, 0x96, 0x6f, 0x0e, 0xcb, 0x37, 0xc6, 0x6f, 0x8f, 0xa0, 0xfd, 0x28, 0x42, 0x8c, 0xe1, - 0x50, 0xc6, 0x1f, 0xdc, 0x42, 0x17, 0xe8, 0xb2, 0xe7, 0x6a, 0x5d, 0xf5, 0x72, 0x96, 0x71, 0xeb, - 0xc0, 0xf4, 0x2a, 0x6d, 0xdf, 0x41, 0x7b, 0xca, 0x14, 0xb6, 0xe0, 0x28, 0x13, 0x79, 0x9c, 0xf0, - 0x45, 0x9d, 0x68, 0x4a, 0x3c, 0x80, 0x4e, 0x1a, 0xaf, 0xb8, 0xd4, 0xa9, 0x8e, 0x6b, 0x0a, 0xfb, - 0x19, 0x7a, 0x33, 0x26, 0x27, 0x79, 0x9c, 0xb1, 0x14, 0x5f, 0x43, 0x97, 0x69, 0xa5, 0xb3, 0xc7, - 0xb7, 0x03, 0x6a, 0xd6, 0xa3, 0xcd, 0x7a, 0x74, 0x92, 0x6f, 0xdc, 0xda, 0x83, 0xfb, 0x80, 0xd6, - 0x1a, 0xd6, 0x76, 0xd1, 0xda, 0x9e, 0x42, 0x7f, 0xc6, 0xe4, 0x8e, 0x35, 0x06, 0x88, 0x98, 0x9c, - 0xef, 0xc1, 0xeb, 0x45, 0x4d, 0xc8, 0x7e, 0x81, 0x53, 0x03, 0xd9, 0x71, 0xee, 0xe1, 0xa4, 0xe2, - 0xec, 0xc9, 0xea, 0x47, 0x7f, 0xb2, 0x0f, 0x4f, 0x5f, 0x05, 0x41, 0xdb, 0x82, 0xa0, 0x9f, 0x82, - 0xa0, 0xcf, 0x92, 0xb4, 0xb6, 0x25, 0x69, 0x7d, 0x97, 0xa4, 0xf5, 0x7a, 0x15, 0xc6, 0x2a, 0x5a, - 0x7a, 0xd4, 0x17, 0x99, 0x63, 0xee, 0x52, 0x7f, 0x23, 0x19, 0x24, 0xce, 0xff, 0x2b, 0x7a, 0x5d, - 0x3d, 0x62, 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x65, 0xc6, 0xd8, 0xe9, 0xde, 0x01, 0x00, 0x00, + // 429 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x40, 0xb3, 0xa4, 0x2d, 0xcd, 0xc4, 0xa2, 0x68, 0xe9, 0x21, 0xf8, 0x60, 0x15, 0x8b, 0x8a, + 0x4a, 0xd0, 0xb5, 0x68, 0xc5, 0x85, 0x5b, 0x29, 0x15, 0x91, 0x10, 0x17, 0x17, 0x09, 0x89, 0x4b, + 0xb5, 0xb1, 0x07, 0xdb, 0x8a, 0xed, 0x2d, 0x9e, 0x4d, 0xd4, 0xf0, 0x15, 0xfc, 0x0b, 0x3f, 0xc1, + 0xb1, 0x47, 0x8e, 0x28, 0xf9, 0x11, 0xe4, 0x5d, 0x3b, 0x09, 0xa8, 0x2a, 0xbd, 0xd8, 0x33, 0xab, + 0x37, 0xcf, 0xb3, 0x3b, 0x5e, 0x70, 0x23, 0x15, 0x63, 0x14, 0x68, 0x24, 0x1d, 0x4b, 0x2d, 0x83, + 0xcb, 0x4a, 0x69, 0x25, 0xcc, 0x93, 0x3f, 0x8a, 0x14, 0x15, 0x8a, 0x2e, 0x28, 0x1e, 0x0b, 0x83, + 0x89, 0xe9, 0x4b, 0xf7, 0x71, 0xa2, 0x54, 0x92, 0xa3, 0x05, 0x47, 0x93, 0x2f, 0x81, 0x2c, 0x67, + 0x96, 0xf7, 0x0f, 0xa1, 0xfb, 0x56, 0x25, 0x9c, 0xc3, 0x06, 0x65, 0xdf, 0x70, 0xc0, 0xf6, 0xd8, + 0x41, 0x2f, 0x34, 0x71, 0xbd, 0x56, 0xca, 0x02, 0x07, 0xf7, 0xec, 0x5a, 0x1d, 0xfb, 0xaf, 0xa0, + 0x7b, 0x2a, 0x35, 0x1f, 0xc0, 0xfd, 0x42, 0x95, 0xd9, 0x18, 0xab, 0xa6, 0xa2, 0x4d, 0xf9, 0x2e, + 0x6c, 0xe6, 0xd9, 0x14, 0xc9, 0x54, 0x6d, 0x86, 0x36, 0xf1, 0xdf, 0x41, 0x6f, 0x28, 0xe9, 0xa4, + 0xcc, 0x0a, 0x99, 0xf3, 0x17, 0xb0, 0x25, 0x4d, 0x64, 0x6a, 0xfb, 0x47, 0xbb, 0xc2, 0xb6, 0x27, + 0xda, 0xf6, 0xc4, 0x49, 0x39, 0x0b, 0x1b, 0x86, 0x3b, 0xc0, 0xae, 0x8c, 0xac, 0x1b, 0xb2, 0x2b, + 0xff, 0x14, 0x9c, 0xa1, 0xa4, 0x95, 0xeb, 0x18, 0x20, 0x95, 0x74, 0x71, 0x07, 0x5f, 0x2f, 0x6d, + 0x8b, 0xfc, 0x0f, 0xb0, 0x63, 0x25, 0x2b, 0xcf, 0x6b, 0x78, 0x50, 0x7b, 0xee, 0xe8, 0x72, 0xd2, + 0xb5, 0x5a, 0xff, 0x19, 0xf4, 0xcf, 0xa2, 0x54, 0x85, 0xf8, 0x75, 0x82, 0x64, 0xcf, 0x06, 0x89, + 0x64, 0x82, 0xcb, 0xb3, 0xb1, 0xa9, 0x7f, 0x00, 0x8e, 0x05, 0xe9, 0x52, 0x95, 0x84, 0xb7, 0x90, + 0xfb, 0xb0, 0x73, 0x2e, 0x67, 0x43, 0xcc, 0xf3, 0xa5, 0xb6, 0x9d, 0x06, 0x5b, 0x9b, 0x86, 0x80, + 0x87, 0x2b, 0xac, 0x91, 0xba, 0xb0, 0x9d, 0x54, 0x88, 0x3a, 0x2b, 0x93, 0x86, 0x5d, 0xe6, 0x47, + 0x3f, 0x18, 0xf4, 0x3f, 0x22, 0xe9, 0x73, 0xac, 0xa6, 0x59, 0x84, 0xfc, 0x3d, 0x6c, 0xd4, 0x0d, + 0xf1, 0x3d, 0x71, 0xc3, 0x5f, 0x23, 0xd6, 0x36, 0xe5, 0x3e, 0xb9, 0x85, 0x68, 0x3e, 0xfc, 0x09, + 0xb6, 0xdb, 0x66, 0xf8, 0xd3, 0x1b, 0xf1, 0x7f, 0xb6, 0xe4, 0xee, 0xff, 0x87, 0xb2, 0xe2, 0x37, + 0x67, 0x3f, 0xe7, 0x1e, 0xbb, 0x9e, 0x7b, 0xec, 0xf7, 0xdc, 0x63, 0xdf, 0x17, 0x5e, 0xe7, 0x7a, + 0xe1, 0x75, 0x7e, 0x2d, 0xbc, 0xce, 0xe7, 0xe7, 0x49, 0xa6, 0xd3, 0xc9, 0x48, 0x44, 0xaa, 0x08, + 0xac, 0xaa, 0x79, 0x1d, 0x52, 0x3c, 0x0e, 0xfe, 0xbe, 0x25, 0xa3, 0x2d, 0x33, 0xc2, 0xe3, 0x3f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0x4f, 0x91, 0x9b, 0x3e, 0x03, 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 + +// TestServiceClient is the client API for TestService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type TestServiceClient interface { + Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) + SayHello(ctx context.Context, in *SayHelloRequest, opts ...grpc.CallOption) (*SayHelloResponse, error) +} + +type testServiceClient struct { + cc grpc1.ClientConn +} + +func NewTestServiceClient(cc grpc1.ClientConn) TestServiceClient { + return &testServiceClient{cc} +} + +func (c *testServiceClient) Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) { + out := new(EchoResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.codec.v1.TestService/Echo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *testServiceClient) SayHello(ctx context.Context, in *SayHelloRequest, opts ...grpc.CallOption) (*SayHelloResponse, error) { + out := new(SayHelloResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.codec.v1.TestService/SayHello", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// TestServiceServer is the server API for TestService service. +type TestServiceServer interface { + Echo(context.Context, *EchoRequest) (*EchoResponse, error) + SayHello(context.Context, *SayHelloRequest) (*SayHelloResponse, error) +} + +// UnimplementedTestServiceServer can be embedded to have forward compatible implementations. +type UnimplementedTestServiceServer struct { +} + +func (*UnimplementedTestServiceServer) Echo(ctx context.Context, req *EchoRequest) (*EchoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") +} +func (*UnimplementedTestServiceServer) SayHello(ctx context.Context, req *SayHelloRequest) (*SayHelloResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") +} + +func RegisterTestServiceServer(s grpc1.Server, srv TestServiceServer) { + s.RegisterService(&_TestService_serviceDesc, srv) +} + +func _TestService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EchoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TestServiceServer).Echo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.codec.v1.TestService/Echo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TestServiceServer).Echo(ctx, req.(*EchoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _TestService_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SayHelloRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TestServiceServer).SayHello(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.codec.v1.TestService/SayHello", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TestServiceServer).SayHello(ctx, req.(*SayHelloRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _TestService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos_sdk.codec.v1.TestService", + HandlerType: (*TestServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Echo", + Handler: _TestService_Echo_Handler, + }, + { + MethodName: "SayHello", + Handler: _TestService_SayHello_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "codec/testdata/proto.proto", } func (m *Dog) Marshal() (dAtA []byte, err error) { @@ -482,6 +791,126 @@ func (m *HasHasHasAnimal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EchoRequest) 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 *EchoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EchoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Message) > 0 { + i -= len(m.Message) + copy(dAtA[i:], m.Message) + i = encodeVarintProto(dAtA, i, uint64(len(m.Message))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EchoResponse) 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 *EchoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EchoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Message) > 0 { + i -= len(m.Message) + copy(dAtA[i:], m.Message) + i = encodeVarintProto(dAtA, i, uint64(len(m.Message))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SayHelloRequest) 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 *SayHelloRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SayHelloRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintProto(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SayHelloResponse) 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 *SayHelloResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SayHelloResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Greeting) > 0 { + i -= len(m.Greeting) + copy(dAtA[i:], m.Greeting) + i = encodeVarintProto(dAtA, i, uint64(len(m.Greeting))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintProto(dAtA []byte, offset int, v uint64) int { offset -= sovProto(v) base := offset @@ -552,29 +981,410 @@ func (m *HasHasAnimal) Size() (n int) { l = m.HasAnimal.Size() n += 1 + l + sovProto(uint64(l)) } - return n -} + return n +} + +func (m *HasHasHasAnimal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.HasHasAnimal != nil { + l = m.HasHasAnimal.Size() + n += 1 + l + sovProto(uint64(l)) + } + return n +} + +func (m *EchoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Message) + if l > 0 { + n += 1 + l + sovProto(uint64(l)) + } + return n +} + +func (m *EchoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Message) + if l > 0 { + n += 1 + l + sovProto(uint64(l)) + } + return n +} + +func (m *SayHelloRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovProto(uint64(l)) + } + return n +} + +func (m *SayHelloResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Greeting) + if l > 0 { + n += 1 + l + sovProto(uint64(l)) + } + return n +} + +func sovProto(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozProto(x uint64) (n int) { + return sovProto(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Dog) 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 ErrIntOverflowProto + } + 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: Dog: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Dog: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Size_", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProto + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProto + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Size_ = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProto + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProto + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProto(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Cat) 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 ErrIntOverflowProto + } + 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: Cat: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Cat: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProto + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProto + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Moniker = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Lives", wireType) + } + m.Lives = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Lives |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProto(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HasAnimal) 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 ErrIntOverflowProto + } + 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: HasAnimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Animal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProto + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProto + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Animal == nil { + m.Animal = &types.Any{} + } + if err := m.Animal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field X", wireType) + } + m.X = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.X |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProto(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } -func (m *HasHasHasAnimal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.HasHasAnimal != nil { - l = m.HasHasAnimal.Size() - n += 1 + l + sovProto(uint64(l)) + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n -} - -func sovProto(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozProto(x uint64) (n int) { - return sovProto(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + return nil } -func (m *Dog) Unmarshal(dAtA []byte) error { +func (m *HasHasAnimal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -597,17 +1407,17 @@ func (m *Dog) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Dog: wiretype end group for non-group") + return fmt.Errorf("proto: HasHasAnimal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Dog: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: HasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Size_", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HasAnimal", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowProto @@ -617,29 +1427,86 @@ func (m *Dog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthProto } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthProto } if postIndex > l { return io.ErrUnexpectedEOF } - m.Size_ = string(dAtA[iNdEx:postIndex]) + if m.HasAnimal == nil { + m.HasAnimal = &types.Any{} + } + if err := m.HasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 2: + default: + iNdEx = preIndex + skippy, err := skipProto(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProto + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HasHasHasAnimal) 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 ErrIntOverflowProto + } + 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: HasHasHasAnimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HasHasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HasHasAnimal", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowProto @@ -649,23 +1516,27 @@ func (m *Dog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthProto } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthProto } if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = string(dAtA[iNdEx:postIndex]) + if m.HasHasAnimal == nil { + m.HasHasAnimal = &types.Any{} + } + if err := m.HasHasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -691,7 +1562,7 @@ func (m *Dog) Unmarshal(dAtA []byte) error { } return nil } -func (m *Cat) Unmarshal(dAtA []byte) error { +func (m *EchoRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -714,15 +1585,15 @@ func (m *Cat) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Cat: wiretype end group for non-group") + return fmt.Errorf("proto: EchoRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Cat: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: EchoRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -750,27 +1621,8 @@ func (m *Cat) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Moniker = string(dAtA[iNdEx:postIndex]) + m.Message = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lives", wireType) - } - m.Lives = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProto - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lives |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipProto(dAtA[iNdEx:]) @@ -795,7 +1647,7 @@ func (m *Cat) Unmarshal(dAtA []byte) error { } return nil } -func (m *HasAnimal) Unmarshal(dAtA []byte) error { +func (m *EchoResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -818,17 +1670,17 @@ func (m *HasAnimal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: HasAnimal: wiretype end group for non-group") + return fmt.Errorf("proto: EchoResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: HasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: EchoResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Animal", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowProto @@ -838,47 +1690,24 @@ func (m *HasAnimal) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthProto } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthProto } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Animal == nil { - m.Animal = &types.Any{} - } - if err := m.Animal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Message = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field X", wireType) - } - m.X = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProto - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.X |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipProto(dAtA[iNdEx:]) @@ -903,7 +1732,7 @@ func (m *HasAnimal) Unmarshal(dAtA []byte) error { } return nil } -func (m *HasHasAnimal) Unmarshal(dAtA []byte) error { +func (m *SayHelloRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -926,17 +1755,17 @@ func (m *HasHasAnimal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: HasHasAnimal: wiretype end group for non-group") + return fmt.Errorf("proto: SayHelloRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: HasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: SayHelloRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HasAnimal", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowProto @@ -946,27 +1775,23 @@ func (m *HasHasAnimal) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthProto } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthProto } if postIndex > l { return io.ErrUnexpectedEOF } - if m.HasAnimal == nil { - m.HasAnimal = &types.Any{} - } - if err := m.HasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Name = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -992,7 +1817,7 @@ func (m *HasHasAnimal) Unmarshal(dAtA []byte) error { } return nil } -func (m *HasHasHasAnimal) Unmarshal(dAtA []byte) error { +func (m *SayHelloResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1015,17 +1840,17 @@ func (m *HasHasHasAnimal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: HasHasHasAnimal: wiretype end group for non-group") + return fmt.Errorf("proto: SayHelloResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: HasHasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: SayHelloResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HasHasAnimal", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Greeting", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowProto @@ -1035,27 +1860,23 @@ func (m *HasHasHasAnimal) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthProto } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthProto } if postIndex > l { return io.ErrUnexpectedEOF } - if m.HasHasAnimal == nil { - m.HasHasAnimal = &types.Any{} - } - if err := m.HasHasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Greeting = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/codec/testdata/proto.proto b/codec/testdata/proto.proto index 9316a5edee1c..f0b5f60a0ed2 100644 --- a/codec/testdata/proto.proto +++ b/codec/testdata/proto.proto @@ -27,3 +27,24 @@ message HasHasAnimal { message HasHasHasAnimal { google.protobuf.Any has_has_animal = 1; } + +service TestService { + rpc Echo(EchoRequest) returns (EchoResponse); + rpc SayHello(SayHelloRequest) returns (SayHelloResponse); +} + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} + +message SayHelloRequest { + string name = 1; +} + +message SayHelloResponse { + string greeting = 1; +} diff --git a/go.mod b/go.mod index 05057cbdbf29..435b42d83e51 100644 --- a/go.mod +++ b/go.mod @@ -32,9 +32,11 @@ require ( github.com/tendermint/iavl v0.13.3 github.com/tendermint/tendermint v0.33.5 github.com/tendermint/tm-db v0.5.1 + google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73 + google.golang.org/grpc v1.28.1 gopkg.in/yaml.v2 v2.3.0 ) -replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.1 +replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 go 1.14 diff --git a/go.sum b/go.sum index 507be717e0b5..75923b2dea80 100644 --- a/go.sum +++ b/go.sum @@ -406,8 +406,8 @@ github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= -github.com/regen-network/protobuf v1.3.2-alpha.regen.1 h1:YdeZbBS0lG1D13COb7b57+nM/RGgIs8WF9DwitU6EBM= -github.com/regen-network/protobuf v1.3.2-alpha.regen.1/go.mod h1:lye6mqhOn/GCw1zRl3uPD5VP8rC+LPMyTyPAyQV872U= +github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= +github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= @@ -563,8 +563,6 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -597,7 +595,6 @@ golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200107162124-548cf772de50/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -662,8 +659,8 @@ google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f h1:2wh8dWY8959cBGQvk1RD+/eQBgRYYDaZ+hT0/zsARoA= -google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73 h1:+yTMTeazSO5iBqU9NR53hgriivQQbYa5Uuaj8r3qKII= +google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -675,6 +672,7 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.0 h1:bO/TA4OxCOummhSf10siHuG7vJOiwh7SpRpFZDkOgl4= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 5737b8aa8ac1..7f2e72c4d2f3 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -6,7 +6,7 @@ proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xarg for dir in $proto_dirs; do protoc \ -I. \ - --gocosmos_out=plugins=interfacetype,paths=source_relative,\ + --gocosmos_out=plugins=interfacetype+grpc,paths=source_relative,\ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ $(find "${dir}" -maxdepth 1 -name '*.proto') done diff --git a/simapp/app.go b/simapp/app.go index e13a361b8af4..b9ac2214d1e4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -304,6 +304,7 @@ func NewSimApp( app.mm.RegisterInvariants(&app.CrisisKeeper) app.mm.RegisterRoutes(app.Router(), app.QueryRouter()) + app.mm.RegisterQueryServices(app.Router(), app.GRPCRouter()) // create the simulation manager and define the order of the modules for deterministic simulations // diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 780fcaca7f42..66a1cb90051d 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -102,8 +102,13 @@ func queryCmd(cdc *codec.Codec) *cobra.Command { flags.LineBreak, ) + clientCtx := client.Context{} + clientCtx = clientCtx. + WithJSONMarshaler(appCodec). + WithCodec(cdc) + // add modules' query commands - simapp.ModuleBasics.AddQueryCommands(queryCmd, cdc) + simapp.ModuleBasics.AddQueryCommands(queryCmd, clientCtx) return queryCmd } diff --git a/tests/mocks/tendermint_tm_db_DB.go b/tests/mocks/tendermint_tm_db_DB.go index bed59a498d03..cdf5e5ab0a27 100644 --- a/tests/mocks/tendermint_tm_db_DB.go +++ b/tests/mocks/tendermint_tm_db_DB.go @@ -6,7 +6,7 @@ package mocks import ( gomock "github.com/golang/mock/gomock" - tm_db "github.com/tendermint/tm-db" + db "github.com/tendermint/tm-db" reflect "reflect" ) @@ -106,10 +106,10 @@ func (mr *MockDBMockRecorder) Has(arg0 interface{}) *gomock.Call { } // Iterator mocks base method -func (m *MockDB) Iterator(arg0, arg1 []byte) (tm_db.Iterator, error) { +func (m *MockDB) Iterator(arg0, arg1 []byte) (db.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Iterator", arg0, arg1) - ret0, _ := ret[0].(tm_db.Iterator) + ret0, _ := ret[0].(db.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -121,10 +121,10 @@ func (mr *MockDBMockRecorder) Iterator(arg0, arg1 interface{}) *gomock.Call { } // NewBatch mocks base method -func (m *MockDB) NewBatch() tm_db.Batch { +func (m *MockDB) NewBatch() db.Batch { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NewBatch") - ret0, _ := ret[0].(tm_db.Batch) + ret0, _ := ret[0].(db.Batch) return ret0 } @@ -149,10 +149,10 @@ func (mr *MockDBMockRecorder) Print() *gomock.Call { } // ReverseIterator mocks base method -func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (tm_db.Iterator, error) { +func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (db.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReverseIterator", arg0, arg1) - ret0, _ := ret[0].(tm_db.Iterator) + ret0, _ := ret[0].(db.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 22b353a97eb5..c0237794fe17 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -9,6 +9,7 @@ import ( client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" types "github.com/cosmos/cosmos-sdk/types" + grpc "github.com/gogo/protobuf/grpc" gomock "github.com/golang/mock/gomock" mux "github.com/gorilla/mux" cobra "github.com/spf13/cobra" @@ -120,7 +121,7 @@ func (mr *MockAppModuleBasicMockRecorder) GetTxCmd(arg0 interface{}) *gomock.Cal } // GetQueryCmd mocks base method -func (m *MockAppModuleBasic) GetQueryCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModuleBasic) GetQueryCmd(arg0 client.Context) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueryCmd", arg0) ret0, _ := ret[0].(*cobra.Command) @@ -237,7 +238,7 @@ func (mr *MockAppModuleGenesisMockRecorder) GetTxCmd(arg0 interface{}) *gomock.C } // GetQueryCmd mocks base method -func (m *MockAppModuleGenesis) GetQueryCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModuleGenesis) GetQueryCmd(arg0 client.Context) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueryCmd", arg0) ret0, _ := ret[0].(*cobra.Command) @@ -382,7 +383,7 @@ func (mr *MockAppModuleMockRecorder) GetTxCmd(arg0 interface{}) *gomock.Call { } // GetQueryCmd mocks base method -func (m *MockAppModule) GetQueryCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModule) GetQueryCmd(arg0 client.Context) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueryCmd", arg0) ret0, _ := ret[0].(*cobra.Command) @@ -491,6 +492,18 @@ func (mr *MockAppModuleMockRecorder) NewQuerierHandler() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewQuerierHandler", reflect.TypeOf((*MockAppModule)(nil).NewQuerierHandler)) } +// RegisterQueryService mocks base method +func (m *MockAppModule) RegisterQueryService(arg0 grpc.Server) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterQueryService", arg0) +} + +// RegisterQueryService indicates an expected call of RegisterQueryService +func (mr *MockAppModuleMockRecorder) RegisterQueryService(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterQueryService", reflect.TypeOf((*MockAppModule)(nil).RegisterQueryService), arg0) +} + // BeginBlock mocks base method func (m *MockAppModule) BeginBlock(arg0 types.Context, arg1 types0.RequestBeginBlock) { m.ctrl.T.Helper() diff --git a/tests/mocks/types_router.go b/tests/mocks/types_router.go index 924d95146eda..536a4a3a9635 100644 --- a/tests/mocks/types_router.go +++ b/tests/mocks/types_router.go @@ -7,6 +7,7 @@ package mocks import ( types "github.com/cosmos/cosmos-sdk/types" gomock "github.com/golang/mock/gomock" + grpc "google.golang.org/grpc" reflect "reflect" ) @@ -111,3 +112,15 @@ func (mr *MockQueryRouterMockRecorder) Route(path interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockQueryRouter)(nil).Route), path) } + +// RegisterService mocks base method +func (m *MockQueryRouter) RegisterService(sd *grpc.ServiceDesc, querier interface{}) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterService", sd, querier) +} + +// RegisterService indicates an expected call of RegisterService +func (mr *MockQueryRouterMockRecorder) RegisterService(sd, querier interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterService", reflect.TypeOf((*MockQueryRouter)(nil).RegisterService), sd, querier) +} diff --git a/third_party/proto/google/api/annotations.proto b/third_party/proto/google/api/annotations.proto new file mode 100644 index 000000000000..cfdc57f4d8f4 --- /dev/null +++ b/third_party/proto/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright (c) 2015, Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "third_party/proto/google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/third_party/proto/google/api/http.proto b/third_party/proto/google/api/http.proto new file mode 100644 index 000000000000..b2977f514741 --- /dev/null +++ b/third_party/proto/google/api/http.proto @@ -0,0 +1,376 @@ +// Copyright 2019 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/types/context.go b/types/context.go index ed4b693c9770..b48fe2d5733c 100644 --- a/types/context.go +++ b/types/context.go @@ -225,3 +225,22 @@ func (c Context) CacheContext() (cc Context, writeCache func()) { cc = c.WithMultiStore(cms).WithEventManager(NewEventManager()) return cc, cms.Write } + +type sdkContextKeyType string + +const sdkContextKey sdkContextKeyType = "sdk-context" + +// WrapSDKContext attaches a Context to that Context's context.Context member +// and returns that context. It is useful for passing a Context through methods +// that take a generic context.Context parameter such as generated gRPC +// methods +func WrapSDKContext(ctx Context) context.Context { + return context.WithValue(ctx.ctx, sdkContextKey, ctx) +} + +// UnwrapSDKContext retrieves a Context from a context.Context instance +// attached with WrapSDKContext. It panics if a Context was not properly +// attached +func UnwrapSDKContext(ctx context.Context) Context { + return ctx.Value(sdkContextKey).(Context) +} diff --git a/types/context_test.go b/types/context_test.go index 97336badeb98..a33fe65f64e2 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -231,3 +231,15 @@ func TestContextHeaderClone(t *testing.T) { }) } } + +func TestUnwrapSDKContext(t *testing.T) { + sdkCtx := types.NewContext(nil, abci.Header{}, false, nil) + ctx := types.WrapSDKContext(sdkCtx) + sdkCtx2 := types.UnwrapSDKContext(ctx) + require.Equal(t, sdkCtx, sdkCtx2) + + ctx = context.Background() + require.Panics(t, func() { + types.UnwrapSDKContext(ctx) + }) +} diff --git a/types/errors/errors.go b/types/errors/errors.go index 1ec52fbe72e0..1bf06295a8a1 100644 --- a/types/errors/errors.go +++ b/types/errors/errors.go @@ -106,6 +106,12 @@ var ( // ErrInvalidType defines an error an invalid type. ErrInvalidType = Register(RootCodespace, 29, "invalid type") + // ErrProtoarshal defines an ABCI typed protobuf marshalling error + ErrProtoMarshal = Register(RootCodespace, 30, "failed to marshal proto bytes") + + // ErrProtoUnmarshal defines an ABCI typed protobuf unmarshalling error + ErrProtoUnmarshal = Register(RootCodespace, 31, "failed to unmarshal proto bytes") + // ErrPanic is only set when we recover from a panic, so we know to // redact potentially sensitive system info ErrPanic = Register(UndefinedCodespace, 111222, "panic") diff --git a/types/module/module.go b/types/module/module.go index 2ef4cc98a66a..5c16cf13762b 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -31,6 +31,8 @@ package module import ( "encoding/json" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -53,7 +55,7 @@ type AppModuleBasic interface { // client functionality RegisterRESTRoutes(client.Context, *mux.Router) GetTxCmd(client.Context) *cobra.Command - GetQueryCmd(*codec.Codec) *cobra.Command + GetQueryCmd(client.Context) *cobra.Command } // BasicManager is a collection of AppModuleBasic @@ -113,9 +115,9 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, ctx client.Contex } // AddQueryCommands adds all query commands to the rootQueryCmd -func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) { +func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, clientCtx client.Context) { for _, b := range bm { - if cmd := b.GetQueryCmd(cdc); cmd != nil { + if cmd := b.GetQueryCmd(clientCtx); cmd != nil { rootQueryCmd.AddCommand(cmd) } } @@ -141,8 +143,12 @@ type AppModule interface { // routes Route() string NewHandler() sdk.Handler + // Deprecated: use RegisterQueryService QuerierRoute() string + // Deprecated: use RegisterQueryService NewQuerierHandler() sdk.Querier + // RegisterQueryService allows a module to register a query service grpc + RegisterQueryService(grpc.Server) // ABCI BeginBlock(sdk.Context, abci.RequestBeginBlock) @@ -178,6 +184,8 @@ func (GenesisOnlyAppModule) QuerierRoute() string { return "" } // NewQuerierHandler returns an empty module querier func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier { return nil } +func (gam GenesisOnlyAppModule) RegisterQueryService(grpc.Server) {} + // BeginBlock returns an empty module begin-block func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} @@ -256,6 +264,13 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) } } +// RegisterQueryServices registers all module query services +func (m *Manager) RegisterQueryServices(router sdk.Router, grpcRouter grpc.Server) { + for _, module := range m.Modules { + module.RegisterQueryService(grpcRouter) + } +} + // InitGenesis performs init genesis functionality for modules func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisData map[string]json.RawMessage) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate diff --git a/types/module/module_test.go b/types/module/module_test.go index 45b6e8c46ad1..4f359dffde22 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -55,7 +55,7 @@ func TestBasicManager(t *testing.T) { mockCmd := &cobra.Command{Use: "root"} mm.AddTxCommands(mockCmd, clientCtx) - mm.AddQueryCommands(mockCmd, cdc) + mm.AddQueryCommands(mockCmd, clientCtx) // validate genesis returns nil require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, wantDefaultGenesis)) diff --git a/types/query/pagination.go b/types/query/pagination.go new file mode 100644 index 000000000000..b63ec4e7ca74 --- /dev/null +++ b/types/query/pagination.go @@ -0,0 +1,83 @@ +package query + +import ( + "github.com/cosmos/cosmos-sdk/store/types" +) + +// Paginate does pagination of the results in the prefixStore based on the +// provided PageRequest. onResult should be used to do actual unmarshaling. +// +// Ex: +// prefixStore := prefix.NewStore(store, someRequestParam) +// var results []Result +// pageRes, err := query.Paginate(accountStore, req.Page, func(key []byte, value []byte) error { +// var result Result +// err := Unmarshal(value, &balance) +// results = append(results, result) +// ... +// }) +func Paginate( + prefixStore types.KVStore, + req *PageRequest, + onResult func(key []byte, value []byte) error, +) (*PageResponse, error) { + pageNum := req.PageNum + limit := req.Limit + + if pageNum >= 1 { + iterator := prefixStore.Iterator(req.PageKey, nil) + defer iterator.Close() + + pageStart := pageNum * limit + pageEnd := pageStart + limit + var count uint64 + var nextPageKey []byte + + for ; iterator.Valid(); iterator.Next() { + count++ + + if count < pageStart { + continue + } else if count <= pageEnd { + err := onResult(iterator.Key(), iterator.Value()) + if err != nil { + return nil, err + } + } else if !req.CountTotal { + nextPageKey = iterator.Key() + break + } + } + + res := &PageResponse{NextPageKey: nextPageKey} + if req.CountTotal { + res.Total = count + } + + return res, nil + } else { + iterator := prefixStore.Iterator(req.PageKey, nil) + defer iterator.Close() + + var count uint64 + var nextPageKey []byte + + for ; iterator.Valid(); iterator.Next() { + if count == limit { + nextPageKey = iterator.Key() + break + } + + err := onResult(iterator.Key(), iterator.Value()) + if err != nil { + return nil, err + } + + count++ + } + + return &PageResponse{ + NextPageKey: nextPageKey, + }, nil + } +} diff --git a/types/query/pagination.pb.go b/types/query/pagination.pb.go new file mode 100644 index 000000000000..cb8fd00c9b2d --- /dev/null +++ b/types/query/pagination.pb.go @@ -0,0 +1,674 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types/query/pagination.proto + +package query + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + 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 + +// PageRequest is to be embedded in gRPC request messages for efficient +// pagination. Ex: +// +// message SomeRequest { +// Foo some_parameter = 1; +// PageRequest page = 2; +// } +type PageRequest struct { + // page_key is a value returned in PageResponse.next_page_key to begin + // querying the next page most efficiently + PageKey []byte `protobuf:"bytes,1,opt,name=page_key,json=pageKey,proto3" json:"page_key,omitempty"` + // page_num is a page number that can be used when PageResponse.next_page_key + // is unavailable. It is less efficient than using page_key. page_num 0 + // is the first page and page_num n indicates the page starting from result + // n * limit + PageNum uint64 `protobuf:"varint,2,opt,name=page_num,json=pageNum,proto3" json:"page_num,omitempty"` + // limit is the total number of results to be returned in the result page + Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + // count_total is set to true to indicate that the result set should include + // a count of the total number of items available for pagination in UIs + CountTotal bool `protobuf:"varint,4,opt,name=count_total,json=countTotal,proto3" json:"count_total,omitempty"` +} + +func (m *PageRequest) Reset() { *m = PageRequest{} } +func (m *PageRequest) String() string { return proto.CompactTextString(m) } +func (*PageRequest) ProtoMessage() {} +func (*PageRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1bc1d15c71a57e43, []int{0} +} +func (m *PageRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PageRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PageRequest.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 *PageRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_PageRequest.Merge(m, src) +} +func (m *PageRequest) XXX_Size() int { + return m.Size() +} +func (m *PageRequest) XXX_DiscardUnknown() { + xxx_messageInfo_PageRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_PageRequest proto.InternalMessageInfo + +func (m *PageRequest) GetPageKey() []byte { + if m != nil { + return m.PageKey + } + return nil +} + +func (m *PageRequest) GetPageNum() uint64 { + if m != nil { + return m.PageNum + } + return 0 +} + +func (m *PageRequest) GetLimit() uint64 { + if m != nil { + return m.Limit + } + return 0 +} + +func (m *PageRequest) GetCountTotal() bool { + if m != nil { + return m.CountTotal + } + return false +} + +// PageResponse is to be embedded in gRPC response messages where the corresponding +// request message has used PageRequest +// +// message SomeResponse { +// repeated Bar results = 1; +// PageResponse page = 2; +// } +type PageResponse struct { + // next_page_key is the key to be passed to PageRequest.page_key to + // query the next page most efficiently + NextPageKey []byte `protobuf:"bytes,1,opt,name=next_page_key,json=nextPageKey,proto3" json:"next_page_key,omitempty"` + // total is total number of results available if PageRequest.count_total + // was set, its value is undefined otherwise + Total uint64 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"` +} + +func (m *PageResponse) Reset() { *m = PageResponse{} } +func (m *PageResponse) String() string { return proto.CompactTextString(m) } +func (*PageResponse) ProtoMessage() {} +func (*PageResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1bc1d15c71a57e43, []int{1} +} +func (m *PageResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PageResponse.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 *PageResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PageResponse.Merge(m, src) +} +func (m *PageResponse) XXX_Size() int { + return m.Size() +} +func (m *PageResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PageResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PageResponse proto.InternalMessageInfo + +func (m *PageResponse) GetNextPageKey() []byte { + if m != nil { + return m.NextPageKey + } + return nil +} + +func (m *PageResponse) GetTotal() uint64 { + if m != nil { + return m.Total + } + return 0 +} + +func init() { + proto.RegisterType((*PageRequest)(nil), "cosmos_sdk.query.v1.PageRequest") + proto.RegisterType((*PageResponse)(nil), "cosmos_sdk.query.v1.PageResponse") +} + +func init() { proto.RegisterFile("types/query/pagination.proto", fileDescriptor_1bc1d15c71a57e43) } + +var fileDescriptor_1bc1d15c71a57e43 = []byte{ + // 266 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0xa9, 0x2c, 0x48, + 0x2d, 0xd6, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2f, 0x48, 0x4c, 0xcf, 0xcc, 0x4b, 0x2c, 0xc9, + 0xcc, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4e, 0xce, 0x2f, 0xce, 0xcd, 0x2f, + 0x8e, 0x2f, 0x4e, 0xc9, 0xd6, 0x03, 0x2b, 0xd1, 0x2b, 0x33, 0x54, 0xaa, 0xe2, 0xe2, 0x0e, 0x48, + 0x4c, 0x4f, 0x0d, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0x92, 0xe4, 0xe2, 0x28, 0x48, 0x4c, + 0x4f, 0x8d, 0xcf, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x62, 0x07, 0xf1, 0xbd, + 0x53, 0x2b, 0xe1, 0x52, 0x79, 0xa5, 0xb9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x10, 0x29, 0xbf, + 0xd2, 0x5c, 0x21, 0x11, 0x2e, 0xd6, 0x9c, 0xcc, 0xdc, 0xcc, 0x12, 0x09, 0x66, 0xb0, 0x38, 0x84, + 0x23, 0x24, 0xcf, 0xc5, 0x9d, 0x9c, 0x5f, 0x9a, 0x57, 0x12, 0x5f, 0x92, 0x5f, 0x92, 0x98, 0x23, + 0xc1, 0xa2, 0xc0, 0xa8, 0xc1, 0x11, 0xc4, 0x05, 0x16, 0x0a, 0x01, 0x89, 0x28, 0x79, 0x70, 0xf1, + 0x40, 0xec, 0x2e, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x15, 0x52, 0xe2, 0xe2, 0xcd, 0x4b, 0xad, 0x28, + 0x89, 0x47, 0x73, 0x01, 0x37, 0x48, 0x30, 0x00, 0xea, 0x0a, 0x11, 0x2e, 0x56, 0x88, 0x71, 0x10, + 0x27, 0x40, 0x38, 0x4e, 0x4e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, + 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, + 0x91, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0xf1, 0x3f, 0x94, 0xd2, + 0x2d, 0x4e, 0xc9, 0xd6, 0x47, 0x0a, 0xaf, 0x24, 0x36, 0x70, 0x28, 0x19, 0x03, 0x02, 0x00, 0x00, + 0xff, 0xff, 0x8f, 0x7c, 0x3c, 0x37, 0x45, 0x01, 0x00, 0x00, +} + +func (m *PageRequest) 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 *PageRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PageRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CountTotal { + i-- + if m.CountTotal { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x20 + } + if m.Limit != 0 { + i = encodeVarintPagination(dAtA, i, uint64(m.Limit)) + i-- + dAtA[i] = 0x18 + } + if m.PageNum != 0 { + i = encodeVarintPagination(dAtA, i, uint64(m.PageNum)) + i-- + dAtA[i] = 0x10 + } + if len(m.PageKey) > 0 { + i -= len(m.PageKey) + copy(dAtA[i:], m.PageKey) + i = encodeVarintPagination(dAtA, i, uint64(len(m.PageKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PageResponse) 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 *PageResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PageResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Total != 0 { + i = encodeVarintPagination(dAtA, i, uint64(m.Total)) + i-- + dAtA[i] = 0x10 + } + if len(m.NextPageKey) > 0 { + i -= len(m.NextPageKey) + copy(dAtA[i:], m.NextPageKey) + i = encodeVarintPagination(dAtA, i, uint64(len(m.NextPageKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPagination(dAtA []byte, offset int, v uint64) int { + offset -= sovPagination(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PageRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PageKey) + if l > 0 { + n += 1 + l + sovPagination(uint64(l)) + } + if m.PageNum != 0 { + n += 1 + sovPagination(uint64(m.PageNum)) + } + if m.Limit != 0 { + n += 1 + sovPagination(uint64(m.Limit)) + } + if m.CountTotal { + n += 2 + } + return n +} + +func (m *PageResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NextPageKey) + if l > 0 { + n += 1 + l + sovPagination(uint64(l)) + } + if m.Total != 0 { + n += 1 + sovPagination(uint64(m.Total)) + } + return n +} + +func sovPagination(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPagination(x uint64) (n int) { + return sovPagination(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PageRequest) 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 ErrIntOverflowPagination + } + 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: PageRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PageRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PageKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPagination + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPagination + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PageKey = append(m.PageKey[:0], dAtA[iNdEx:postIndex]...) + if m.PageKey == nil { + m.PageKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PageNum", wireType) + } + m.PageNum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PageNum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) + } + m.Limit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Limit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CountTotal", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.CountTotal = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipPagination(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPagination + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPagination + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PageResponse) 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 ErrIntOverflowPagination + } + 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: PageResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PageResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextPageKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPagination + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPagination + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NextPageKey = append(m.NextPageKey[:0], dAtA[iNdEx:postIndex]...) + if m.NextPageKey == nil { + m.NextPageKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + m.Total = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPagination + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Total |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPagination(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPagination + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPagination + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPagination(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, ErrIntOverflowPagination + } + 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, ErrIntOverflowPagination + } + 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, ErrIntOverflowPagination + } + 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, ErrInvalidLengthPagination + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPagination + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPagination + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPagination = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPagination = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPagination = fmt.Errorf("proto: unexpected end of group") +) diff --git a/types/query/pagination.proto b/types/query/pagination.proto new file mode 100644 index 000000000000..ec2791f4c314 --- /dev/null +++ b/types/query/pagination.proto @@ -0,0 +1,47 @@ +syntax = "proto3"; +package cosmos_sdk.query.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/types/query"; + +// PageRequest is to be embedded in gRPC request messages for efficient +// pagination. Ex: +// +// message SomeRequest { +// Foo some_parameter = 1; +// PageRequest page = 2; +// } +message PageRequest { + // page_key is a value returned in PageResponse.next_page_key to begin + // querying the next page most efficiently + bytes page_key = 1; + + // page_num is a page number that can be used when PageResponse.next_page_key + // is unavailable. It is less efficient than using page_key. page_num 0 + // is the first page and page_num n indicates the page starting from result + // n * limit + uint64 page_num = 2; + + // limit is the total number of results to be returned in the result page + uint64 limit = 3; + + // count_total is set to true to indicate that the result set should include + // a count of the total number of items available for pagination in UIs + bool count_total = 4; +} + +// PageResponse is to be embedded in gRPC response messages where the corresponding +// request message has used PageRequest +// +// message SomeResponse { +// repeated Bar results = 1; +// PageResponse page = 2; +// } +message PageResponse { + // next_page_key is the key to be passed to PageRequest.page_key to + // query the next page most efficiently + bytes next_page_key = 1; + + // total is total number of results available if PageRequest.count_total + // was set, its value is undefined otherwise + uint64 total = 2; +} diff --git a/types/router.go b/types/router.go index 12d0455f805d..c6328e92d782 100644 --- a/types/router.go +++ b/types/router.go @@ -1,6 +1,8 @@ package types -import "regexp" +import ( + "regexp" +) var ( // IsAlphaNumeric defines a regular expression for matching against alpha-numeric diff --git a/x/auth/module.go b/x/auth/module.go index 8ec50779d76c..0d07d9cfbdb9 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -68,8 +70,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns the root query command for the auth module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(context.Codec) } // RegisterInterfaceTypes registers interfaces and implementations of the auth module. @@ -118,6 +120,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.accountKeeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/bank/alias.go b/x/bank/alias.go index 769fdf985faf..10a95b428249 100644 --- a/x/bank/alias.go +++ b/x/bank/alias.go @@ -28,7 +28,6 @@ var ( NewBaseKeeper = keeper.NewBaseKeeper NewBaseSendKeeper = keeper.NewBaseSendKeeper NewBaseViewKeeper = keeper.NewBaseViewKeeper - NewQuerier = keeper.NewQuerier RegisterCodec = types.RegisterCodec ErrNoInputs = types.ErrNoInputs ErrNoOutputs = types.ErrNoOutputs @@ -44,8 +43,8 @@ var ( NewOutput = types.NewOutput ValidateInputsOutputs = types.ValidateInputsOutputs ParamKeyTable = types.ParamKeyTable - NewQueryBalanceParams = types.NewQueryBalanceParams - NewQueryAllBalancesParams = types.NewQueryAllBalancesParams + NewQueryBalanceParams = types.NewQueryBalanceRequest + NewQueryAllBalancesParams = types.NewQueryAllBalancesRequest ModuleCdc = types.ModuleCdc ParamStoreKeySendEnabled = types.ParamStoreKeySendEnabled BalancesPrefix = types.BalancesPrefix @@ -67,8 +66,8 @@ type ( MsgMultiSend = types.MsgMultiSend Input = types.Input Output = types.Output - QueryBalanceParams = types.QueryBalanceParams - QueryAllBalancesParams = types.QueryAllBalancesParams + BalanceRequest = types.BalanceRequest + AllBalancesRequest = types.AllBalancesRequest GenesisBalancesIterator = types.GenesisBalancesIterator Keeper = keeper.Keeper GenesisState = types.GenesisState diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 03378be26544..f443c87232c6 100644 --- a/x/bank/client/cli/query.go +++ b/x/bank/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + gocontext "context" "fmt" "strings" @@ -9,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -19,17 +19,8 @@ const ( flagDenom = "denom" ) -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetQueryCmd returns the parent querying command for the bank module. -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetQueryCmd(cdc *codec.Codec) *cobra.Command { +// NewQueryCmd returns a root CLI command handler for all x/bank query commands. +func NewQueryCmd(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Querying commands for the bank module", @@ -39,73 +30,42 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command { } cmd.AddCommand( - GetBalancesCmd(cdc), - GetCmdQueryTotalSupply(cdc), + NewBalancesCmd(clientCtx), + NewCmdQueryTotalSupply(clientCtx), ) return cmd } -// GetAccountCmd returns a CLI command handler that facilitates querying for a -// single or all account balances by address. -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetBalancesCmd(cdc *codec.Codec) *cobra.Command { +// NewBalancesCmd returns a CLI command handler for querying account balance(s). +func NewBalancesCmd(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "balances [address]", - Short: "Query for account balances by address", + Short: "Query for account balance(s) by address", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) - addr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - var ( - params interface{} - result interface{} - route string - ) - + queryClient := types.NewQueryClient(clientCtx.QueryConn()) denom := viper.GetString(flagDenom) if denom == "" { - params = types.NewQueryAllBalancesParams(addr) - route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAllBalances) - } else { - params = types.NewQueryBalanceParams(addr, denom) - route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBalance) - } - - bz, err := cdc.MarshalJSON(params) - if err != nil { - return fmt.Errorf("failed to marshal params: %w", err) - } - - res, _, err := clientCtx.QueryWithData(route, bz) - if err != nil { - return err - } - - if denom == "" { - var balances sdk.Coins - if err := cdc.UnmarshalJSON(res, &balances); err != nil { + request := types.NewQueryAllBalancesRequest(addr) + result, err := queryClient.AllBalances(gocontext.Background(), request) + if err != nil { return err } - - result = balances + return clientCtx.Println(result.Balances) } else { - var balance sdk.Coin - if err := cdc.UnmarshalJSON(res, &balance); err != nil { + params := types.NewQueryBalanceRequest(addr, denom) + result, err := queryClient.Balance(gocontext.Background(), params) + if err != nil { return err } - - result = balance + return clientCtx.Println(result) } - - return clientCtx.PrintOutput(result) }, } @@ -114,9 +74,7 @@ func GetBalancesCmd(cdc *codec.Codec) *cobra.Command { return flags.GetCommands(cmd)[0] } -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command { +func NewCmdQueryTotalSupply(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "total [denom]", Args: cobra.MaximumNArgs(1), @@ -135,13 +93,21 @@ $ %s query %s total stake ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + queryClient := types.NewQueryClient(clientCtx.QueryConn()) if len(args) == 0 { - return queryTotalSupply(clientCtx, cdc) + res, err := queryClient.TotalSupply(gocontext.Background(), &types.TotalSupplyRequest{}) + if err != nil { + return err + } + return clientCtx.PrintOutput(res.Balances) } - return querySupplyOf(clientCtx, cdc, args[0]) + res, err := queryClient.SupplyOf(gocontext.Background(), &types.SupplyOfRequest{Denom: args[0]}) + if err != nil { + return err + } + return clientCtx.PrintOutput(res.Amount) }, } diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index 55ddb6338fd0..524ed077aaf0 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -49,10 +49,10 @@ func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { denom := r.FormValue("denom") if denom == "" { - params = types.NewQueryAllBalancesParams(addr) + params = types.NewQueryAllBalancesRequest(addr) route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAllBalances) } else { - params = types.NewQueryBalanceParams(addr, denom) + params = types.NewQueryBalanceRequest(addr, denom) route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBalance) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index d50655566959..6c0fa582c038 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -41,6 +41,8 @@ type Keeper interface { UnmarshalSupply(bz []byte) (exported.SupplyI, error) MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) + + types.QueryServer } // BaseKeeper manages transfers between accounts. It implements the Keeper interface. diff --git a/x/bank/keeper/querier.go b/x/bank/keeper/querier.go index 24ef415fdc55..50f4597371e4 100644 --- a/x/bank/keeper/querier.go +++ b/x/bank/keeper/querier.go @@ -1,6 +1,11 @@ package keeper import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + "github.com/cosmos/cosmos-sdk/types/query" + abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/client" @@ -10,6 +15,58 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/types" ) +var _ types.QueryServer = BaseKeeper{} + +func (q BaseKeeper) Balance(ctx context.Context, req *types.BalanceRequest) (*types.BalanceResponse, error) { + balance := q.GetBalance(sdk.UnwrapSDKContext(ctx), req.Address, req.Denom) + return &types.BalanceResponse{Balance: &balance}, nil +} + +func (q BaseKeeper) AllBalances(c context.Context, req *types.AllBalancesRequest) (*types.AllBalancesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + store := ctx.KVStore(q.storeKey) + + balancesStore := prefix.NewStore(store, types.BalancesPrefix) + accountStore := prefix.NewStore(balancesStore, req.Address.Bytes()) + + balances := sdk.Coins{} + + pageRes, err := query.Paginate(accountStore, req.Page, func(key []byte, value []byte) error { + var balance sdk.Coin + + err := q.cdc.UnmarshalBinaryBare(value, &balance) + if err != nil { + return err + } + + balances = balances.Add(balance) + + return nil + }) + if err != nil { + return nil, err + } + + return &types.AllBalancesResponse{Balances: balances, Page: pageRes}, nil +} + +func (q BaseKeeper) TotalSupply(c context.Context, request *types.TotalSupplyRequest) (*types.TotalSupplyResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + // TODO: add pagination once it can be supported properly with supply no longer being stored as a single blob + totalSupply := q.GetSupply(ctx).GetTotal() + + return &types.TotalSupplyResponse{Balances: totalSupply}, nil +} + +func (q BaseKeeper) SupplyOf(c context.Context, request *types.SupplyOfRequest) (*types.SupplyOfResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + supply := q.GetSupply(ctx).GetTotal().AmountOf(request.Denom) + + return &types.SupplyOfResponse{Amount: supply}, nil +} + // NewQuerier returns a new sdk.Keeper instance. func NewQuerier(k Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { @@ -33,7 +90,7 @@ func NewQuerier(k Keeper) sdk.Querier { } func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { - var params types.QueryBalanceParams + var params types.BalanceRequest if err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) @@ -50,7 +107,7 @@ func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, err } func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { - var params types.QueryAllBalancesParams + var params types.AllBalancesRequest if err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index be68730460b9..5ade98dae9bd 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -1,10 +1,12 @@ package keeper_test import ( + gocontext "context" "fmt" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" @@ -15,25 +17,16 @@ import ( func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { app, ctx := suite.app, suite.ctx _, _, addr := authtypes.KeyTestPubAddr() - req := abci.RequestQuery{ - Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryBalance), - Data: []byte{}, - } - - querier := keeper.NewQuerier(app.BankKeeper) - res, err := querier(ctx, []string{types.QueryBalance}, req) - suite.Require().NotNil(err) - suite.Require().Nil(res) + queryHelper := baseapp.NewQueryServerTestHelper(ctx) + types.RegisterQueryServer(queryHelper, app.BankKeeper) + queryClient := types.NewQueryClient(queryHelper) - req.Data = app.Codec().MustMarshalJSON(types.NewQueryBalanceParams(addr, fooDenom)) - res, err = querier(ctx, []string{types.QueryBalance}, req) + req := types.NewQueryBalanceRequest(addr, fooDenom) + res, err := queryClient.Balance(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) - - var balance sdk.Coin - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balance)) - suite.True(balance.IsZero()) + suite.True(res.Balance.IsZero()) origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr) @@ -41,35 +34,25 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { app.AccountKeeper.SetAccount(ctx, acc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, acc.GetAddress(), origCoins)) - res, err = querier(ctx, []string{types.QueryBalance}, req) + res, err = queryClient.Balance(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balance)) - suite.True(balance.IsEqual(newFooCoin(50))) + suite.True(res.Balance.IsEqual(newFooCoin(50))) } func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { app, ctx := suite.app, suite.ctx _, _, addr := authtypes.KeyTestPubAddr() - req := abci.RequestQuery{ - Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryAllBalances), - Data: []byte{}, - } - - querier := keeper.NewQuerier(app.BankKeeper) - res, err := querier(ctx, []string{types.QueryAllBalances}, req) - suite.Require().NotNil(err) - suite.Require().Nil(res) + queryHelper := baseapp.NewQueryServerTestHelper(ctx) + types.RegisterQueryServer(queryHelper, app.BankKeeper) + queryClient := types.NewQueryClient(queryHelper) - req.Data = app.Codec().MustMarshalJSON(types.NewQueryAllBalancesParams(addr)) - res, err = querier(ctx, []string{types.QueryAllBalances}, req) + req := types.NewQueryAllBalancesRequest(addr) + res, err := queryClient.AllBalances(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) - - var balances sdk.Coins - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balances)) - suite.True(balances.IsZero()) + suite.True(res.Balances.IsZero()) origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr) @@ -77,11 +60,10 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { app.AccountKeeper.SetAccount(ctx, acc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, acc.GetAddress(), origCoins)) - res, err = querier(ctx, []string{types.QueryAllBalances}, req) + res, err = queryClient.AllBalances(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().NoError(app.Codec().UnmarshalJSON(res, &balances)) - suite.True(balances.IsEqual(origCoins)) + suite.True(res.Balances.IsEqual(origCoins)) } func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { diff --git a/x/bank/module.go b/x/bank/module.go index 9af9d684f267..dfb726b07e66 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -67,8 +69,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns no root query command for the bank module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.NewQueryCmd(context) } // RegisterInterfaceTypes registers interfaces and implementations of the bank module. @@ -86,6 +88,10 @@ type AppModule struct { accountKeeper types.AccountKeeper } +func (am AppModule) RegisterQueryService(server grpc.Server) { + types.RegisterQueryServer(server, am.keeper) +} + // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Marshaler, keeper Keeper, accountKeeper types.AccountKeeper) AppModule { return AppModule{ diff --git a/x/bank/types/querier.go b/x/bank/types/querier.go index 4767c65aa89a..ff39e216d582 100644 --- a/x/bank/types/querier.go +++ b/x/bank/types/querier.go @@ -12,25 +12,14 @@ const ( QuerySupplyOf = "supply_of" ) -// QueryBalanceParams defines the params for querying an account balance. -type QueryBalanceParams struct { - Address sdk.AccAddress - Denom string +// NewQueryBalanceRequest creates a new instance of QueryBalanceRequest. +func NewQueryBalanceRequest(addr sdk.AccAddress, denom string) *BalanceRequest { + return &BalanceRequest{Address: addr, Denom: denom} } -// NewQueryBalanceParams creates a new instance of QueryBalanceParams. -func NewQueryBalanceParams(addr sdk.AccAddress, denom string) QueryBalanceParams { - return QueryBalanceParams{Address: addr, Denom: denom} -} - -// QueryAllBalancesParams defines the params for querying all account balances -type QueryAllBalancesParams struct { - Address sdk.AccAddress -} - -// NewQueryAllBalancesParams creates a new instance of QueryAllBalancesParams. -func NewQueryAllBalancesParams(addr sdk.AccAddress) QueryAllBalancesParams { - return QueryAllBalancesParams{Address: addr} +// NewQueryAllBalancesRequest creates a new instance of QueryAllBalancesRequest. +func NewQueryAllBalancesRequest(addr sdk.AccAddress) *AllBalancesRequest { + return &AllBalancesRequest{Address: addr} } // QueryTotalSupply defines the params for the following queries: diff --git a/x/bank/types/query.pb.go b/x/bank/types/query.pb.go new file mode 100644 index 000000000000..cb1e89dc5114 --- /dev/null +++ b/x/bank/types/query.pb.go @@ -0,0 +1,1914 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/bank/types/query.proto + +package types + +import ( + context "context" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/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 + +// QueryBalanceParams defines the params for querying an account balance. +type BalanceRequest struct { + Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *BalanceRequest) Reset() { *m = BalanceRequest{} } +func (m *BalanceRequest) String() string { return proto.CompactTextString(m) } +func (*BalanceRequest) ProtoMessage() {} +func (*BalanceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{0} +} +func (m *BalanceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BalanceRequest.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 *BalanceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BalanceRequest.Merge(m, src) +} +func (m *BalanceRequest) XXX_Size() int { + return m.Size() +} +func (m *BalanceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BalanceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BalanceRequest proto.InternalMessageInfo + +func (m *BalanceRequest) GetAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *BalanceRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +// QueryBalanceResponse is the response for the QueryBalance rpc method +type BalanceResponse struct { + Balance *types.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (m *BalanceResponse) Reset() { *m = BalanceResponse{} } +func (m *BalanceResponse) String() string { return proto.CompactTextString(m) } +func (*BalanceResponse) ProtoMessage() {} +func (*BalanceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{1} +} +func (m *BalanceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BalanceResponse.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 *BalanceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BalanceResponse.Merge(m, src) +} +func (m *BalanceResponse) XXX_Size() int { + return m.Size() +} +func (m *BalanceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BalanceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BalanceResponse proto.InternalMessageInfo + +func (m *BalanceResponse) GetBalance() *types.Coin { + if m != nil { + return m.Balance + } + return nil +} + +// QueryAllBalancesParams defines the params for querying all account balances +type AllBalancesRequest struct { + Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` + Page *query.PageRequest `protobuf:"bytes,2,opt,name=page,proto3" json:"page,omitempty"` +} + +func (m *AllBalancesRequest) Reset() { *m = AllBalancesRequest{} } +func (m *AllBalancesRequest) String() string { return proto.CompactTextString(m) } +func (*AllBalancesRequest) ProtoMessage() {} +func (*AllBalancesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{2} +} +func (m *AllBalancesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllBalancesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllBalancesRequest.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 *AllBalancesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllBalancesRequest.Merge(m, src) +} +func (m *AllBalancesRequest) XXX_Size() int { + return m.Size() +} +func (m *AllBalancesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_AllBalancesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_AllBalancesRequest proto.InternalMessageInfo + +func (m *AllBalancesRequest) GetAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *AllBalancesRequest) GetPage() *query.PageRequest { + if m != nil { + return m.Page + } + return nil +} + +// QueryAllBalancesResponse is the response to the QueryAllBalances rpc method +type AllBalancesResponse struct { + Balances github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=balances,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balances"` + Page *query.PageResponse `protobuf:"bytes,2,opt,name=page,proto3" json:"page,omitempty"` +} + +func (m *AllBalancesResponse) Reset() { *m = AllBalancesResponse{} } +func (m *AllBalancesResponse) String() string { return proto.CompactTextString(m) } +func (*AllBalancesResponse) ProtoMessage() {} +func (*AllBalancesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{3} +} +func (m *AllBalancesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllBalancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllBalancesResponse.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 *AllBalancesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllBalancesResponse.Merge(m, src) +} +func (m *AllBalancesResponse) XXX_Size() int { + return m.Size() +} +func (m *AllBalancesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_AllBalancesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_AllBalancesResponse proto.InternalMessageInfo + +func (m *AllBalancesResponse) GetBalances() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Balances + } + return nil +} + +func (m *AllBalancesResponse) GetPage() *query.PageResponse { + if m != nil { + return m.Page + } + return nil +} + +type TotalSupplyRequest struct { +} + +func (m *TotalSupplyRequest) Reset() { *m = TotalSupplyRequest{} } +func (m *TotalSupplyRequest) String() string { return proto.CompactTextString(m) } +func (*TotalSupplyRequest) ProtoMessage() {} +func (*TotalSupplyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{4} +} +func (m *TotalSupplyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TotalSupplyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TotalSupplyRequest.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 *TotalSupplyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TotalSupplyRequest.Merge(m, src) +} +func (m *TotalSupplyRequest) XXX_Size() int { + return m.Size() +} +func (m *TotalSupplyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TotalSupplyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_TotalSupplyRequest proto.InternalMessageInfo + +type TotalSupplyResponse struct { + Balances github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=balances,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balances"` +} + +func (m *TotalSupplyResponse) Reset() { *m = TotalSupplyResponse{} } +func (m *TotalSupplyResponse) String() string { return proto.CompactTextString(m) } +func (*TotalSupplyResponse) ProtoMessage() {} +func (*TotalSupplyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{5} +} +func (m *TotalSupplyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TotalSupplyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TotalSupplyResponse.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 *TotalSupplyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TotalSupplyResponse.Merge(m, src) +} +func (m *TotalSupplyResponse) XXX_Size() int { + return m.Size() +} +func (m *TotalSupplyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TotalSupplyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_TotalSupplyResponse proto.InternalMessageInfo + +func (m *TotalSupplyResponse) GetBalances() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Balances + } + return nil +} + +type SupplyOfRequest struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *SupplyOfRequest) Reset() { *m = SupplyOfRequest{} } +func (m *SupplyOfRequest) String() string { return proto.CompactTextString(m) } +func (*SupplyOfRequest) ProtoMessage() {} +func (*SupplyOfRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{6} +} +func (m *SupplyOfRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SupplyOfRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SupplyOfRequest.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 *SupplyOfRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SupplyOfRequest.Merge(m, src) +} +func (m *SupplyOfRequest) XXX_Size() int { + return m.Size() +} +func (m *SupplyOfRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SupplyOfRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SupplyOfRequest proto.InternalMessageInfo + +func (m *SupplyOfRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +type SupplyOfResponse struct { + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *SupplyOfResponse) Reset() { *m = SupplyOfResponse{} } +func (m *SupplyOfResponse) String() string { return proto.CompactTextString(m) } +func (*SupplyOfResponse) ProtoMessage() {} +func (*SupplyOfResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b761440f9b86d1e8, []int{7} +} +func (m *SupplyOfResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SupplyOfResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SupplyOfResponse.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 *SupplyOfResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SupplyOfResponse.Merge(m, src) +} +func (m *SupplyOfResponse) XXX_Size() int { + return m.Size() +} +func (m *SupplyOfResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SupplyOfResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SupplyOfResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*BalanceRequest)(nil), "cosmos_sdk.x.bank.v1.BalanceRequest") + proto.RegisterType((*BalanceResponse)(nil), "cosmos_sdk.x.bank.v1.BalanceResponse") + proto.RegisterType((*AllBalancesRequest)(nil), "cosmos_sdk.x.bank.v1.AllBalancesRequest") + proto.RegisterType((*AllBalancesResponse)(nil), "cosmos_sdk.x.bank.v1.AllBalancesResponse") + proto.RegisterType((*TotalSupplyRequest)(nil), "cosmos_sdk.x.bank.v1.TotalSupplyRequest") + proto.RegisterType((*TotalSupplyResponse)(nil), "cosmos_sdk.x.bank.v1.TotalSupplyResponse") + proto.RegisterType((*SupplyOfRequest)(nil), "cosmos_sdk.x.bank.v1.SupplyOfRequest") + proto.RegisterType((*SupplyOfResponse)(nil), "cosmos_sdk.x.bank.v1.SupplyOfResponse") +} + +func init() { proto.RegisterFile("x/bank/types/query.proto", fileDescriptor_b761440f9b86d1e8) } + +var fileDescriptor_b761440f9b86d1e8 = []byte{ + // 612 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x95, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x86, 0xe3, 0x7e, 0xfd, 0xfb, 0x26, 0x40, 0x61, 0x12, 0xa4, 0xc8, 0x20, 0x27, 0xb5, 0x20, + 0x4d, 0x17, 0x19, 0x93, 0x00, 0x7b, 0x92, 0x4a, 0x48, 0x88, 0x05, 0x60, 0x58, 0x75, 0x53, 0x4d, + 0x62, 0xe3, 0x5a, 0x75, 0x66, 0xdc, 0xcc, 0x24, 0x24, 0xaa, 0x2a, 0x10, 0xe2, 0x02, 0x90, 0x58, + 0x70, 0x0f, 0x6c, 0xb8, 0x8d, 0x2e, 0x2b, 0xb1, 0x41, 0x2c, 0x02, 0x4a, 0xb8, 0x0a, 0x56, 0xc8, + 0x33, 0xe3, 0xc4, 0xa1, 0x49, 0x9b, 0x0d, 0x6c, 0xf2, 0x33, 0x7e, 0xcf, 0x9c, 0xe7, 0x9c, 0xf3, + 0xce, 0x18, 0xe4, 0x7a, 0x56, 0x03, 0x93, 0x03, 0x8b, 0xf7, 0x43, 0x97, 0x59, 0x87, 0x1d, 0xb7, + 0xdd, 0x47, 0x61, 0x9b, 0x72, 0x0a, 0xb3, 0x4d, 0xca, 0x5a, 0x94, 0xed, 0x31, 0xe7, 0x00, 0xf5, + 0x50, 0x24, 0x42, 0xdd, 0x8a, 0x5e, 0xe4, 0xfb, 0x7e, 0xdb, 0xd9, 0x0b, 0x71, 0x9b, 0xf7, 0x2d, + 0x21, 0xb4, 0x3c, 0xea, 0xd1, 0xc9, 0x2f, 0x19, 0xad, 0xa3, 0x59, 0x3a, 0xea, 0x05, 0xae, 0x85, + 0x43, 0xdf, 0xc2, 0x84, 0x50, 0x8e, 0xb9, 0x4f, 0x09, 0x53, 0xfa, 0x6b, 0x12, 0x40, 0x7c, 0xaa, + 0xa5, 0x9b, 0x09, 0x26, 0x2b, 0xc4, 0x9e, 0x4f, 0x44, 0x84, 0x7c, 0x6a, 0x32, 0x70, 0xa5, 0x8e, + 0x03, 0x4c, 0x9a, 0xae, 0xed, 0x1e, 0x76, 0x5c, 0xc6, 0xe1, 0x63, 0xb0, 0x86, 0x1d, 0xa7, 0xed, + 0x32, 0x96, 0xd3, 0x0a, 0x5a, 0xe9, 0x52, 0xbd, 0xf2, 0x6b, 0x90, 0x2f, 0x7b, 0x3e, 0xdf, 0xef, + 0x34, 0x50, 0x93, 0xb6, 0x2c, 0x59, 0x90, 0xfa, 0x2a, 0x33, 0x47, 0x55, 0x8d, 0x6a, 0xcd, 0x66, + 0x4d, 0x06, 0xda, 0xf1, 0x0e, 0x30, 0x0b, 0x56, 0x1c, 0x97, 0xd0, 0x56, 0x6e, 0xa9, 0xa0, 0x95, + 0xfe, 0xb7, 0xe5, 0x1f, 0xf3, 0x01, 0xd8, 0x18, 0x27, 0x65, 0x21, 0x25, 0xcc, 0x85, 0x65, 0xb0, + 0xd6, 0x90, 0x4b, 0x22, 0x6b, 0xba, 0x9a, 0x41, 0x89, 0xc6, 0x75, 0x2b, 0x68, 0x87, 0xfa, 0xc4, + 0x8e, 0x35, 0xe6, 0x47, 0x0d, 0xc0, 0x5a, 0x10, 0xa8, 0x5d, 0xd8, 0x5f, 0x61, 0xbf, 0x07, 0x96, + 0x43, 0xec, 0xb9, 0x02, 0x3d, 0x5d, 0x2d, 0x24, 0x79, 0xe4, 0x80, 0xbb, 0x15, 0xf4, 0x14, 0x7b, + 0x71, 0xe3, 0x6c, 0xa1, 0x36, 0x3f, 0x6b, 0x20, 0x33, 0x45, 0xa6, 0x0a, 0xc4, 0x60, 0x5d, 0xc1, + 0x47, 0x6c, 0xff, 0xcd, 0xa9, 0xb0, 0x7e, 0xe7, 0x64, 0x90, 0x4f, 0x7d, 0xfa, 0x9e, 0x2f, 0x2d, + 0x00, 0x1d, 0x05, 0x30, 0x7b, 0xbc, 0x2d, 0xbc, 0x3f, 0x05, 0xbc, 0x79, 0x0e, 0xb0, 0x64, 0x52, + 0xc4, 0x59, 0x00, 0x5f, 0x50, 0x8e, 0x83, 0xe7, 0x9d, 0x30, 0x0c, 0xfa, 0xaa, 0x1a, 0xb3, 0x07, + 0x32, 0x53, 0xab, 0xff, 0xac, 0x0c, 0x73, 0x0b, 0x6c, 0xc8, 0xa4, 0x4f, 0x5e, 0xc6, 0x73, 0x1d, + 0xdb, 0x48, 0x4b, 0xda, 0x68, 0x17, 0x5c, 0x9d, 0x08, 0x15, 0xdf, 0x43, 0xb0, 0x8a, 0x5b, 0xb4, + 0x43, 0xb8, 0x94, 0xd6, 0x51, 0x04, 0xf2, 0x6d, 0x90, 0x2f, 0x2e, 0x00, 0xf2, 0x88, 0x70, 0x5b, + 0x45, 0x57, 0xdf, 0x2c, 0x83, 0x95, 0x67, 0x51, 0xd3, 0xe0, 0x6b, 0xb0, 0xa6, 0x86, 0x09, 0x6f, + 0xa1, 0x59, 0x87, 0x19, 0x4d, 0x1f, 0x20, 0xfd, 0xf6, 0x05, 0x2a, 0x49, 0x6a, 0x6e, 0xbd, 0xfd, + 0xf2, 0xf3, 0xc3, 0xd2, 0x26, 0xcc, 0xcb, 0x9b, 0x43, 0x95, 0x6f, 0x1d, 0x29, 0xfb, 0x1d, 0x5b, + 0x47, 0xa2, 0xca, 0x63, 0xf8, 0x4e, 0x03, 0xe9, 0x84, 0xa3, 0x60, 0x69, 0xf6, 0xfe, 0x67, 0x8f, + 0x83, 0xbe, 0xbd, 0x80, 0x52, 0xd1, 0x14, 0x04, 0x8d, 0x0e, 0x73, 0x53, 0x34, 0x6c, 0x82, 0x03, + 0x5f, 0x81, 0x74, 0xc2, 0x10, 0xf3, 0x28, 0xce, 0x3a, 0x69, 0x1e, 0xc5, 0x0c, 0x77, 0x99, 0x19, + 0x41, 0x71, 0x19, 0xa6, 0xd5, 0x6d, 0x1a, 0x49, 0x60, 0x17, 0xac, 0xc7, 0x63, 0x86, 0x73, 0x7a, + 0xfb, 0x87, 0x5f, 0xf4, 0xe2, 0x45, 0x32, 0x95, 0xef, 0x86, 0xc8, 0x77, 0x1d, 0x66, 0x12, 0xf9, + 0xe2, 0xbe, 0xd7, 0x77, 0x4e, 0x86, 0x86, 0x76, 0x3a, 0x34, 0xb4, 0x1f, 0x43, 0x43, 0x7b, 0x3f, + 0x32, 0x52, 0xa7, 0x23, 0x23, 0xf5, 0x75, 0x64, 0xa4, 0x76, 0xb7, 0xcf, 0x35, 0x53, 0xf2, 0x55, + 0xd0, 0x58, 0x15, 0xd7, 0xec, 0xdd, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0a, 0xf6, 0x39, 0x8d, + 0x21, 0x06, 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 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Balance queries the balance of a single coin for a single account + Balance(ctx context.Context, in *BalanceRequest, opts ...grpc.CallOption) (*BalanceResponse, error) + // AllBalances queries the balance of all coins for a single account + AllBalances(ctx context.Context, in *AllBalancesRequest, opts ...grpc.CallOption) (*AllBalancesResponse, error) + TotalSupply(ctx context.Context, in *TotalSupplyRequest, opts ...grpc.CallOption) (*TotalSupplyResponse, error) + SupplyOf(ctx context.Context, in *SupplyOfRequest, opts ...grpc.CallOption) (*SupplyOfResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Balance(ctx context.Context, in *BalanceRequest, opts ...grpc.CallOption) (*BalanceResponse, error) { + out := new(BalanceResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.x.bank.v1.Query/Balance", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AllBalances(ctx context.Context, in *AllBalancesRequest, opts ...grpc.CallOption) (*AllBalancesResponse, error) { + out := new(AllBalancesResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.x.bank.v1.Query/AllBalances", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TotalSupply(ctx context.Context, in *TotalSupplyRequest, opts ...grpc.CallOption) (*TotalSupplyResponse, error) { + out := new(TotalSupplyResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.x.bank.v1.Query/TotalSupply", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) SupplyOf(ctx context.Context, in *SupplyOfRequest, opts ...grpc.CallOption) (*SupplyOfResponse, error) { + out := new(SupplyOfResponse) + err := c.cc.Invoke(ctx, "/cosmos_sdk.x.bank.v1.Query/SupplyOf", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Balance queries the balance of a single coin for a single account + Balance(context.Context, *BalanceRequest) (*BalanceResponse, error) + // AllBalances queries the balance of all coins for a single account + AllBalances(context.Context, *AllBalancesRequest) (*AllBalancesResponse, error) + TotalSupply(context.Context, *TotalSupplyRequest) (*TotalSupplyResponse, error) + SupplyOf(context.Context, *SupplyOfRequest) (*SupplyOfResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Balance(ctx context.Context, req *BalanceRequest) (*BalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Balance not implemented") +} +func (*UnimplementedQueryServer) AllBalances(ctx context.Context, req *AllBalancesRequest) (*AllBalancesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllBalances not implemented") +} +func (*UnimplementedQueryServer) TotalSupply(ctx context.Context, req *TotalSupplyRequest) (*TotalSupplyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalSupply not implemented") +} +func (*UnimplementedQueryServer) SupplyOf(ctx context.Context, req *SupplyOfRequest) (*SupplyOfResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SupplyOf not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Balance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Balance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.x.bank.v1.Query/Balance", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Balance(ctx, req.(*BalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AllBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllBalancesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllBalances(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.x.bank.v1.Query/AllBalances", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllBalances(ctx, req.(*AllBalancesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TotalSupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TotalSupplyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalSupply(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.x.bank.v1.Query/TotalSupply", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalSupply(ctx, req.(*TotalSupplyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_SupplyOf_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SupplyOfRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).SupplyOf(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos_sdk.x.bank.v1.Query/SupplyOf", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).SupplyOf(ctx, req.(*SupplyOfRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos_sdk.x.bank.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Balance", + Handler: _Query_Balance_Handler, + }, + { + MethodName: "AllBalances", + Handler: _Query_AllBalances_Handler, + }, + { + MethodName: "TotalSupply", + Handler: _Query_TotalSupply_Handler, + }, + { + MethodName: "SupplyOf", + Handler: _Query_SupplyOf_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "x/bank/types/query.proto", +} + +func (m *BalanceRequest) 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 *BalanceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BalanceResponse) 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 *BalanceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Balance != nil { + { + size, err := m.Balance.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 (m *AllBalancesRequest) 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 *AllBalancesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllBalancesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Page != nil { + { + size, err := m.Page.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *AllBalancesResponse) 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 *AllBalancesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllBalancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Page != nil { + { + size, err := m.Page.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Balances) > 0 { + for iNdEx := len(m.Balances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balances[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 (m *TotalSupplyRequest) 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 *TotalSupplyRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TotalSupplyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *TotalSupplyResponse) 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 *TotalSupplyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TotalSupplyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Balances) > 0 { + for iNdEx := len(m.Balances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balances[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 (m *SupplyOfRequest) 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 *SupplyOfRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SupplyOfRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SupplyOfResponse) 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 *SupplyOfResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SupplyOfResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + 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 *BalanceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *BalanceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Balance != nil { + l = m.Balance.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *AllBalancesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Page != nil { + l = m.Page.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *AllBalancesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Balances) > 0 { + for _, e := range m.Balances { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Page != nil { + l = m.Page.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *TotalSupplyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *TotalSupplyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Balances) > 0 { + for _, e := range m.Balances { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *SupplyOfRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *SupplyOfResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.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 *BalanceRequest) 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: BalanceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BalanceResponse) 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: BalanceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", 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 + } + if m.Balance == nil { + m.Balance = &types.Coin{} + } + if err := m.Balance.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 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllBalancesRequest) 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: AllBalancesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllBalancesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Page", 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 + } + if m.Page == nil { + m.Page = &query.PageRequest{} + } + if err := m.Page.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 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllBalancesResponse) 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: AllBalancesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balances", 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.Balances = append(m.Balances, types.Coin{}) + if err := m.Balances[len(m.Balances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Page", 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 + } + if m.Page == nil { + m.Page = &query.PageResponse{} + } + if err := m.Page.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 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TotalSupplyRequest) 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: TotalSupplyRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TotalSupplyRequest: 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 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TotalSupplyResponse) 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: TotalSupplyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TotalSupplyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balances", 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.Balances = append(m.Balances, types.Coin{}) + if err := m.Balances[len(m.Balances)-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 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SupplyOfRequest) 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: SupplyOfRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SupplyOfRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SupplyOfResponse) 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: SupplyOfResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SupplyOfResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.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 { + return ErrInvalidLengthQuery + } + if (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/bank/types/query.proto b/x/bank/types/query.proto new file mode 100644 index 000000000000..387d76c056c0 --- /dev/null +++ b/x/bank/types/query.proto @@ -0,0 +1,81 @@ +syntax = "proto3"; +package cosmos_sdk.x.bank.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "third_party/proto/google/api/annotations.proto"; +import "types/types.proto"; +import "types/query/pagination.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; + +// Query provides defines the gRPC querier service +service Query { + // Balance queries the balance of a single coin for a single account + rpc Balance (BalanceRequest) returns (BalanceResponse) { + option (google.api.http) = { + get: "/bank/balance/{address}/{denom}" + }; + } + + // AllBalances queries the balance of all coins for a single account + rpc AllBalances (AllBalancesRequest) returns (AllBalancesResponse) { + option (google.api.http) = { + get: "/bank/balances/{address}" + }; + } + + rpc TotalSupply (TotalSupplyRequest) returns (TotalSupplyResponse) { + option (google.api.http) = { + get: "/bank/total" + }; + } + + rpc SupplyOf (SupplyOfRequest) returns (SupplyOfResponse) { + option (google.api.http) = { + get: "/bank/total/{denom}" + }; + } +} + +// QueryBalanceParams defines the params for querying an account balance. +message BalanceRequest { + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string denom = 2; +} + +// QueryBalanceResponse is the response for the QueryBalance rpc method +message BalanceResponse { + cosmos_sdk.v1.Coin balance = 1; +} + +// QueryAllBalancesParams defines the params for querying all account balances +message AllBalancesRequest { + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + cosmos_sdk.query.v1.PageRequest page = 2; +} + +// QueryAllBalancesResponse is the response to the QueryAllBalances rpc method +message AllBalancesResponse { + repeated cosmos_sdk.v1.Coin balances = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + cosmos_sdk.query.v1.PageResponse page = 2; +} + +message TotalSupplyRequest { + // TODO: add pagination once supply is can be supported + // cosmos_sdk.query.v1.PageRequest page = 1; +} + +message TotalSupplyResponse { + repeated cosmos_sdk.v1.Coin balances = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + + // TODO: add pagination once supply is can be supported + // cosmos_sdk.query.v1.PageResponse page = 2; +} + +message SupplyOfRequest { + string denom = 1; +} + +message SupplyOfResponse { + string amount = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; +} diff --git a/x/capability/module.go b/x/capability/module.go index db6ae3487385..9daefa2f59bd 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -5,6 +5,11 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,10 +17,6 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/capability/simulation" "github.com/cosmos/cosmos-sdk/x/capability/types" - - "github.com/gorilla/mux" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" ) var ( @@ -68,7 +69,7 @@ func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} func (a AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil } // GetQueryCmd returns the capability module's root query command. -func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command { return nil } // ---------------------------------------------------------------------------- // AppModule @@ -105,6 +106,8 @@ func (am AppModule) NewHandler() sdk.Handler { return nil } // NewQuerierHandler returns the capability module's Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { return nil } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // RegisterInvariants registers the capability module's invariants. func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} diff --git a/x/crisis/module.go b/x/crisis/module.go index 304673fc1444..a2f6ac38659f 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -61,7 +63,7 @@ func (b AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns no root query command for the crisis module. -func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command { return nil } //____________________________________________________________________________ @@ -107,6 +109,9 @@ func (AppModule) QuerierRoute() string { return "" } // NewQuerierHandler returns no sdk.Querier. func (AppModule) NewQuerierHandler() sdk.Querier { return nil } +func (am AppModule) RegisterQueryService(grpc.Server) { +} + // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/distribution/module.go b/x/distribution/module.go index 71a6cd2324cf..6879c63defc7 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -71,8 +73,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns the root query command for the distribution module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(StoreKey, context.Codec) } // RegisterInterfaceTypes implements InterfaceModule @@ -136,6 +138,9 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) { +} + // InitGenesis performs genesis initialization for the distribution module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/evidence/module.go b/x/evidence/module.go index ee8afdcd552c..35d6a9cb241e 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -93,8 +95,8 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetTxCmd returns the evidence module's root query command. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) +func (AppModuleBasic) GetQueryCmd(cdc client.Context) *cobra.Command { + return cli.GetQueryCmd(StoreKey, cdc.Codec) } func (AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) { @@ -144,6 +146,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // RegisterInvariants registers the evidence module's invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} diff --git a/x/genutil/module.go b/x/genutil/module.go index f0a7d866aa17..cff4cc98ea6e 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -55,7 +55,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil } // GetQueryCmd returns no root query command for the genutil module. -func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command { return nil } //____________________________________________________________________________ diff --git a/x/gov/module.go b/x/gov/module.go index 1908aa0018e4..899808a169c2 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -7,6 +7,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -92,8 +94,8 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns the root query command for the gov module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(StoreKey, context.Codec) } // RegisterInterfaceTypes implements InterfaceModule.RegisterInterfaceTypes @@ -152,6 +154,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 0118fa764382..f4a1b1c26b17 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -75,8 +77,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd implements AppModuleBasic interface -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(cdc, QuerierRoute) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(context.Codec, QuerierRoute) } // RegisterInterfaceTypes registers module concrete types into protobuf Any. @@ -122,6 +124,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return nil } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the ibc transfer module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/ibc/module.go b/x/ibc/module.go index f0e1eff8107d..a865acfc3bc5 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -71,8 +72,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns no root query command for the ibc module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(QuerierRoute, cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(QuerierRoute, context.Codec) } // RegisterInterfaceTypes registers module concrete types into protobuf Any. @@ -126,6 +127,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(*am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the ibc module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/mint/module.go b/x/mint/module.go index 1a97a1be6efa..3f3506ad6028 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -66,8 +68,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil } // GetQueryCmd returns the root query command for the mint module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(context.Codec) } //____________________________________________________________________________ @@ -113,6 +115,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the mint module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/params/module.go b/x/params/module.go index c8008df03514..cdfb62f2e5ed 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -4,6 +4,8 @@ import ( "encoding/json" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -52,7 +54,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { return nil } // GetQueryCmd returns no root query command for the params module. -func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command { return nil } func (am AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) { proposal.RegisterInterfaces(registry) @@ -97,6 +99,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // ProposalContents returns all the params content functions used to // simulate governance proposals. func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { diff --git a/x/slashing/module.go b/x/slashing/module.go index 1d95e24395cb..73fab6f1c68e 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -72,8 +74,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns no root query command for the slashing module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(StoreKey, context.Codec) } //____________________________________________________________________________ @@ -127,6 +129,9 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(server grpc.Server) { +} + // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/staking/module.go b/x/staking/module.go index 432096f59107..635cc7ab9f9e 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -75,8 +77,8 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { } // GetQueryCmd returns no root query command for the staking module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) +func (AppModuleBasic) GetQueryCmd(context client.Context) *cobra.Command { + return cli.GetQueryCmd(StoreKey, context.Codec) } //_____________________________________ @@ -151,6 +153,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) {} + // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/upgrade/module.go b/x/upgrade/module.go index f87025c2ece7..1153e025fca7 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -3,6 +3,8 @@ package upgrade import ( "encoding/json" + "github.com/gogo/protobuf/grpc" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -51,14 +53,14 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router } // GetQueryCmd returns the cli query commands for this module -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { +func (AppModuleBasic) GetQueryCmd(cdc client.Context) *cobra.Command { queryCmd := &cobra.Command{ Use: "upgrade", Short: "Querying commands for the upgrade module", } queryCmd.AddCommand(flags.GetCommands( - cli.GetPlanCmd(StoreKey, cdc), - cli.GetAppliedHeightCmd(StoreKey, cdc), + cli.GetPlanCmd(StoreKey, cdc.Codec), + cli.GetAppliedHeightCmd(StoreKey, cdc.Codec), )...) return queryCmd @@ -109,6 +111,9 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } +func (am AppModule) RegisterQueryService(grpc.Server) { +} + // InitGenesis is ignored, no sense in serializing future upgrades func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{}