From 89e6c3e64d6bef426718a51b0fa07da49a9b54f3 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 6 Oct 2022 20:22:11 +0200 Subject: [PATCH 1/8] add skeleton for query --- proto/util/v1/query.proto | 34 ++ x/util/client/cli/query.go | 1 + x/util/handler.go | 18 + x/util/module.go | 75 ++++ x/util/types/keys.go | 6 + x/util/types/query.pb.go | 772 ++++++++++++++++++++++++++++++++++++ x/util/types/query.pb.gw.go | 148 +++++++ x/vpool/module.go | 3 +- x/vpool/types/genesis.pb.go | 6 +- 9 files changed, 1058 insertions(+), 5 deletions(-) create mode 100644 proto/util/v1/query.proto create mode 100644 x/util/client/cli/query.go create mode 100644 x/util/handler.go create mode 100644 x/util/module.go create mode 100644 x/util/types/keys.go create mode 100644 x/util/types/query.pb.go create mode 100644 x/util/types/query.pb.gw.go diff --git a/proto/util/v1/query.proto b/proto/util/v1/query.proto new file mode 100644 index 000000000..5f736cf1b --- /dev/null +++ b/proto/util/v1/query.proto @@ -0,0 +1,34 @@ +syntax = "proto3"; + +package nibiru.util.v1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "vpool/v1/state.proto"; + +option go_package = "github.com/NibiruChain/nibiru/x/util/types"; + +// Query defines the gRPC querier service. +service Query { + + // Queries the reserve assets in a given pool, identified by a token pair. + rpc ModuleAccounts(QueryModuleAccountsRequest) returns (QueryModuleAccountsResponse) { + option (google.api.http).get = "/nibiru/util/module_accounts"; + } +} + +// ---------------------------------------- + +message QueryModuleAccountsRequest {} + +message QueryModuleAccountsResponse { +} + +message AccountWithBalance { + string name = 1; + string address = 2; + + repeated cosmos.base.v1beta1.Coin balance = 3 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; +} \ No newline at end of file diff --git a/x/util/client/cli/query.go b/x/util/client/cli/query.go new file mode 100644 index 000000000..7f1e458cd --- /dev/null +++ b/x/util/client/cli/query.go @@ -0,0 +1 @@ +package cli diff --git a/x/util/handler.go b/x/util/handler.go new file mode 100644 index 000000000..24c97a94b --- /dev/null +++ b/x/util/handler.go @@ -0,0 +1,18 @@ +package util + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/NibiruChain/nibiru/x/util/types" +) + +// NewHandler ... +func NewHandler() sdk.Handler { + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } +} diff --git a/x/util/module.go b/x/util/module.go new file mode 100644 index 000000000..4198e318b --- /dev/null +++ b/x/util/module.go @@ -0,0 +1,75 @@ +package util + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/NibiruChain/nibiru/x/util/types" +) + +var ( + _ module.AppModule = AppModule{} +) + +type AppModule struct{} + +func (a AppModule) Name() string { + return "util" +} + +func (a AppModule) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} +func (a AppModule) RegisterInterfaces(codectypes.InterfaceRegistry) {} +func (a AppModule) DefaultGenesis(codec.JSONCodec) json.RawMessage { return nil } +func (a AppModule) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error { + return nil +} +func (a AppModule) RegisterRESTRoutes(client.Context, *mux.Router) {} + +func (a AppModule) RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) {} + +func (a AppModule) GetTxCmd() *cobra.Command { return nil } + +func (a AppModule) GetQueryCmd() *cobra.Command { return nil } + +func (a AppModule) InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate { + return nil +} + +func (a AppModule) ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage { + return nil +} + +func (a AppModule) RegisterInvariants(sdk.InvariantRegistry) {} + +func (a AppModule) Route() sdk.Route { + return sdk.NewRoute("", NewHandler()) +} + +func (a AppModule) QuerierRoute() string { + return types.RouterKey +} + +func (a AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +func (a AppModule) RegisterServices(module.Configurator) {} + +func (a AppModule) ConsensusVersion() uint64 { + return 1 +} + +func (a AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) {} + +func (a AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate { + return nil +} diff --git a/x/util/types/keys.go b/x/util/types/keys.go new file mode 100644 index 000000000..19ac1637a --- /dev/null +++ b/x/util/types/keys.go @@ -0,0 +1,6 @@ +package types + +const ( + ModuleName = "util" + RouterKey = ModuleName +) diff --git a/x/util/types/query.pb.go b/x/util/types/query.pb.go new file mode 100644 index 000000000..5e0052274 --- /dev/null +++ b/x/util/types/query.pb.go @@ -0,0 +1,772 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: util/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/NibiruChain/nibiru/x/vpool/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "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 + +type QueryModuleAccountsRequest struct { +} + +func (m *QueryModuleAccountsRequest) Reset() { *m = QueryModuleAccountsRequest{} } +func (m *QueryModuleAccountsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountsRequest) ProtoMessage() {} +func (*QueryModuleAccountsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea08d750598e4157, []int{0} +} +func (m *QueryModuleAccountsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountsRequest.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 *QueryModuleAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountsRequest.Merge(m, src) +} +func (m *QueryModuleAccountsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountsRequest proto.InternalMessageInfo + +type QueryModuleAccountsResponse struct { +} + +func (m *QueryModuleAccountsResponse) Reset() { *m = QueryModuleAccountsResponse{} } +func (m *QueryModuleAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountsResponse) ProtoMessage() {} +func (*QueryModuleAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea08d750598e4157, []int{1} +} +func (m *QueryModuleAccountsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountsResponse.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 *QueryModuleAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountsResponse.Merge(m, src) +} +func (m *QueryModuleAccountsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountsResponse proto.InternalMessageInfo + +type AccountWithBalance struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + Balance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=balance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balance"` +} + +func (m *AccountWithBalance) Reset() { *m = AccountWithBalance{} } +func (m *AccountWithBalance) String() string { return proto.CompactTextString(m) } +func (*AccountWithBalance) ProtoMessage() {} +func (*AccountWithBalance) Descriptor() ([]byte, []int) { + return fileDescriptor_ea08d750598e4157, []int{2} +} +func (m *AccountWithBalance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AccountWithBalance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AccountWithBalance.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 *AccountWithBalance) XXX_Merge(src proto.Message) { + xxx_messageInfo_AccountWithBalance.Merge(m, src) +} +func (m *AccountWithBalance) XXX_Size() int { + return m.Size() +} +func (m *AccountWithBalance) XXX_DiscardUnknown() { + xxx_messageInfo_AccountWithBalance.DiscardUnknown(m) +} + +var xxx_messageInfo_AccountWithBalance proto.InternalMessageInfo + +func (m *AccountWithBalance) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *AccountWithBalance) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *AccountWithBalance) GetBalance() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Balance + } + return nil +} + +func init() { + proto.RegisterType((*QueryModuleAccountsRequest)(nil), "nibiru.util.v1.QueryModuleAccountsRequest") + proto.RegisterType((*QueryModuleAccountsResponse)(nil), "nibiru.util.v1.QueryModuleAccountsResponse") + proto.RegisterType((*AccountWithBalance)(nil), "nibiru.util.v1.AccountWithBalance") +} + +func init() { proto.RegisterFile("util/v1/query.proto", fileDescriptor_ea08d750598e4157) } + +var fileDescriptor_ea08d750598e4157 = []byte{ + // 392 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0xea, 0xd3, 0x40, + 0x10, 0xc6, 0xb3, 0xff, 0xaa, 0xc5, 0x15, 0x7a, 0x58, 0x7b, 0x88, 0xb1, 0x6e, 0x4b, 0xf1, 0x50, + 0x2a, 0xee, 0x9a, 0xfa, 0x04, 0xb6, 0x5e, 0x15, 0xec, 0x45, 0xf0, 0x22, 0x9b, 0x64, 0x49, 0x17, + 0x93, 0x9d, 0x34, 0xbb, 0x09, 0xf6, 0xea, 0x0b, 0x28, 0x78, 0xf2, 0x11, 0xf4, 0x49, 0x7a, 0x2c, + 0x78, 0xf1, 0xa4, 0xd2, 0xfa, 0x20, 0x92, 0x4d, 0x0a, 0x16, 0x14, 0x3c, 0x65, 0x32, 0xdf, 0x37, + 0x5f, 0xf2, 0x9b, 0xc1, 0xb7, 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a, 0x88, 0xc5, 0x90, + 0xf3, 0x0e, 0xbb, 0x7d, 0x3c, 0x34, 0xc9, 0x1b, 0x6e, 0x77, 0x85, 0x34, 0x6e, 0xc0, 0xac, 0xcf, + 0xd9, 0x8b, 0x4f, 0x08, 0x5f, 0x77, 0x2c, 0xe4, 0x3d, 0xc2, 0x83, 0x4b, 0x20, 0x32, 0x67, 0x97, + 0x07, 0x60, 0xff, 0xde, 0x49, 0xf0, 0xe0, 0xbf, 0xbc, 0xdd, 0x86, 0xee, 0xbf, 0xfb, 0xfa, 0xeb, + 0xe3, 0x15, 0x25, 0x23, 0xde, 0x0e, 0x71, 0x77, 0xfd, 0xdc, 0x99, 0x5f, 0x8b, 0xce, 0xbd, 0x7c, + 0xba, 0x3f, 0x52, 0x74, 0x38, 0x52, 0xf4, 0xf3, 0x48, 0xd1, 0x87, 0x13, 0xf5, 0x0e, 0x27, 0xea, + 0x7d, 0x3b, 0x51, 0xef, 0xd5, 0xfc, 0x0f, 0xd0, 0xe7, 0x2e, 0x61, 0xb5, 0x11, 0x4a, 0x9f, 0xd3, + 0xde, 0xb6, 0x79, 0x0e, 0x38, 0xba, 0xe1, 0x2e, 0xfa, 0xf8, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x89, 0x87, 0xac, 0x8b, 0x62, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// 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 { + // Queries the reserve assets in a given pool, identified by a token pair. + ModuleAccounts(ctx context.Context, in *QueryModuleAccountsRequest, opts ...grpc.CallOption) (*QueryModuleAccountsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) ModuleAccounts(ctx context.Context, in *QueryModuleAccountsRequest, opts ...grpc.CallOption) (*QueryModuleAccountsResponse, error) { + out := new(QueryModuleAccountsResponse) + err := c.cc.Invoke(ctx, "/nibiru.util.v1.Query/ModuleAccounts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Queries the reserve assets in a given pool, identified by a token pair. + ModuleAccounts(context.Context, *QueryModuleAccountsRequest) (*QueryModuleAccountsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) ModuleAccounts(ctx context.Context, req *QueryModuleAccountsRequest) (*QueryModuleAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ModuleAccounts not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_ModuleAccounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryModuleAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ModuleAccounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/nibiru.util.v1.Query/ModuleAccounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ModuleAccounts(ctx, req.(*QueryModuleAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "nibiru.util.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ModuleAccounts", + Handler: _Query_ModuleAccounts_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "util/v1/query.proto", +} + +func (m *QueryModuleAccountsRequest) 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 *QueryModuleAccountsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryModuleAccountsResponse) 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 *QueryModuleAccountsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *AccountWithBalance) 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 *AccountWithBalance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AccountWithBalance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Balance) > 0 { + for iNdEx := len(m.Balance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + 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] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Name))) + 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 *QueryModuleAccountsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryModuleAccountsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *AccountWithBalance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if len(m.Balance) > 0 { + for _, e := range m.Balance { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryModuleAccountsRequest) 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: QueryModuleAccountsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryModuleAccountsResponse) 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: QueryModuleAccountsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AccountWithBalance) 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: AccountWithBalance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AccountWithBalance: 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) + } + 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.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", 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.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 + } + m.Balance = append(m.Balance, types.Coin{}) + if err := m.Balance[len(m.Balance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/util/types/query.pb.gw.go b/x/util/types/query.pb.gw.go new file mode 100644 index 000000000..0ae006579 --- /dev/null +++ b/x/util/types/query.pb.gw.go @@ -0,0 +1,148 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: util/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +func request_Query_ModuleAccounts_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := client.ModuleAccounts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ModuleAccounts_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := server.ModuleAccounts(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_ModuleAccounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ModuleAccounts_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ModuleAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_ModuleAccounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ModuleAccounts_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ModuleAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_ModuleAccounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "util", "module_accounts"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_ModuleAccounts_0 = runtime.ForwardResponseMessage +) diff --git a/x/vpool/module.go b/x/vpool/module.go index bf13113f6..65fd18b08 100644 --- a/x/vpool/module.go +++ b/x/vpool/module.go @@ -130,7 +130,7 @@ func (am AppModule) Route() sdk.Route { func (AppModule) QuerierRoute() string { return types.QuerierRoute } // LegacyQuerierHandler returns the capability module's Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { +func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return nil } @@ -138,7 +138,6 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) - // types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) } // RegisterInvariants registers the capability module's invariants. diff --git a/x/vpool/types/genesis.pb.go b/x/vpool/types/genesis.pb.go index beee11409..835eda211 100644 --- a/x/vpool/types/genesis.pb.go +++ b/x/vpool/types/genesis.pb.go @@ -92,13 +92,13 @@ var fileDescriptor_fc3ffc8cca622811 = []byte{ 0x60, 0x90, 0xb0, 0x90, 0x09, 0x17, 0x1b, 0x58, 0x61, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x98, 0x1e, 0x9a, 0xf1, 0x7a, 0x61, 0x01, 0xf9, 0xf9, 0x39, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0xd5, 0x0a, 0xb9, 0x70, 0x71, 0x16, 0xe7, 0x25, 0x16, 0x14, 0x67, 0xe4, 0x97, - 0x14, 0x4b, 0x30, 0x83, 0x35, 0x2a, 0x60, 0x68, 0x0c, 0x4a, 0x2d, 0x4e, 0x2d, 0x2a, 0x4b, 0x0d, + 0x14, 0x4b, 0x30, 0x81, 0x35, 0x2a, 0x60, 0x68, 0x0c, 0x4a, 0x2d, 0x4e, 0x2d, 0x2a, 0x4b, 0x0d, 0x86, 0x2a, 0x84, 0x1a, 0x81, 0xd0, 0xe8, 0xe4, 0x7a, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xda, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x7e, 0x60, 0x63, 0x9d, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x21, 0x56, 0xe8, 0x57, 0xe8, 0x43, 0x3c, 0x57, - 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x9a, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xc1, - 0xfd, 0x23, 0xf4, 0x31, 0x01, 0x00, 0x00, + 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x9a, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x67, + 0x5a, 0x0d, 0x00, 0x31, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { From b2634ff798156cdb3e5b1ac31767630d43cf5a97 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 6 Oct 2022 21:17:33 +0200 Subject: [PATCH 2/8] temp commit --- app/app.go | 9 ++++++ x/util/client/cli/query.go | 55 ++++++++++++++++++++++++++++++++ x/util/handler.go | 2 +- x/util/keeper/query_server.go | 36 +++++++++++++++++++++ x/util/module.go | 37 +++++++++++---------- x/util/types/expected_keepers.go | 8 +++++ x/util/types/keys.go | 2 +- x/util/types/module_accounts.go | 10 ++++++ x/util/types/query.pb.go | 2 +- x/util/types/query.pb.gw.go | 2 +- 10 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 x/util/keeper/query_server.go create mode 100644 x/util/types/expected_keepers.go create mode 100644 x/util/types/module_accounts.go diff --git a/app/app.go b/app/app.go index c5d183e36..bb38e55a8 100644 --- a/app/app.go +++ b/app/app.go @@ -3,11 +3,14 @@ package app import ( "encoding/json" "fmt" + "github.com/NibiruChain/nibiru/x/util/types" "io" "net/http" "os" "path/filepath" + "github.com/NibiruChain/nibiru/x/util" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -164,6 +167,7 @@ var ( epochs.AppModuleBasic{}, perp.AppModuleBasic{}, vpool.AppModuleBasic{}, + util.AppModule{}, ) // module account permissions @@ -495,6 +499,7 @@ func NewNibiruApp( vpoolModule := vpool.NewAppModule( appCodec, app.vpoolKeeper, app.pricefeedKeeper, ) + utilModule := util.NewAppModule(app.bankKeeper) // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. @@ -523,6 +528,7 @@ func NewNibiruApp( epochsModule, vpoolModule, perpModule, + utilModule, // ibc evidence.NewAppModule(app.evidenceKeeper), @@ -557,6 +563,7 @@ func NewNibiruApp( epochstypes.ModuleName, vpooltypes.ModuleName, perptypes.ModuleName, + utiltypes.ModuleName, // ibc modules ibchost.ModuleName, ibctransfertypes.ModuleName, @@ -583,6 +590,7 @@ func NewNibiruApp( pricefeedtypes.ModuleName, vpooltypes.ModuleName, perptypes.ModuleName, + utiltypes.ModuleName, // ibc ibchost.ModuleName, ibctransfertypes.ModuleName, @@ -615,6 +623,7 @@ func NewNibiruApp( epochstypes.ModuleName, vpooltypes.ModuleName, perptypes.ModuleName, + utiltypes.ModuleName, // ibc ibchost.ModuleName, ibctransfertypes.ModuleName, diff --git a/x/util/client/cli/query.go b/x/util/client/cli/query.go index 7f1e458cd..d2791fedb 100644 --- a/x/util/client/cli/query.go +++ b/x/util/client/cli/query.go @@ -1 +1,56 @@ package cli + +import ( + "fmt" + "github.com/NibiruChain/nibiru/x/util/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd() *cobra.Command { + queryCmd := &cobra.Command{ + Use: utiltypes.ModuleName, + Short: fmt.Sprintf( + "Querying commands for the %s module", utiltypes.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + for _, cmd := range []*cobra.Command{ + CmdQueryParams(), + } { + queryCmd.AddCommand(cmd) + } + + return queryCmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "module-accounts", + Short: "shows all the module accounts in the blockchain", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := utiltypes.NewQueryClient(clientCtx) + + res, err := queryClient.ModuleAccounts(cmd.Context(), &utiltypes.QueryModuleAccountsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/util/handler.go b/x/util/handler.go index 24c97a94b..4cd74258f 100644 --- a/x/util/handler.go +++ b/x/util/handler.go @@ -12,7 +12,7 @@ import ( // NewHandler ... func NewHandler() sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + errMsg := fmt.Sprintf("unrecognized %s message type: %T", utiltypes.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } diff --git a/x/util/keeper/query_server.go b/x/util/keeper/query_server.go new file mode 100644 index 000000000..8f65aa91c --- /dev/null +++ b/x/util/keeper/query_server.go @@ -0,0 +1,36 @@ +package keeper + +import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/NibiruChain/nibiru/x/util/types" +) + +type queryServer struct { + k utiltypes.BankKeeper +} + +func NewQueryServer(k utiltypes.BankKeeper) utiltypes.QueryServer { + return &queryServer{k: k} +} + +func (q queryServer) ModuleAccounts( + ctx context.Context, + _ *utiltypes.QueryModuleAccountsRequest, +) (*utiltypes.QueryModuleAccountsResponse, error) { + sdkContext := sdk.UnwrapSDKContext(ctx) + + var moduleAccountsWithBalances []utiltypes.AccountWithBalance + for _, acc := range utiltypes.ModuleAccounts { + balances := q.k.GetAllBalances(sdkContext, acc.Account) + acc := utiltypes.AccountWithBalance{ + Name: acc.Name, + Address: acc.Account.String(), + Balance: balances, + } + moduleAccountsWithBalances = append(moduleAccountsWithBalances, acc) + } + + return &utiltypes.QueryModuleAccountsResponse{}, nil +} diff --git a/x/util/module.go b/x/util/module.go index 4198e318b..6973bb49d 100644 --- a/x/util/module.go +++ b/x/util/module.go @@ -2,6 +2,7 @@ package util import ( "encoding/json" + "github.com/NibiruChain/nibiru/x/util/client/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -13,6 +14,7 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/NibiruChain/nibiru/x/util/keeper" "github.com/NibiruChain/nibiru/x/util/types" ) @@ -20,7 +22,15 @@ var ( _ module.AppModule = AppModule{} ) -type AppModule struct{} +type AppModule struct { + bankKeeper utiltypes.BankKeeper +} + +func NewAppModule(bk utiltypes.BankKeeper) *AppModule { + return &AppModule{ + bankKeeper: bk, + } +} func (a AppModule) Name() string { return "util" @@ -32,44 +42,33 @@ func (a AppModule) DefaultGenesis(codec.JSONCodec) json.RawMessage { return nil func (a AppModule) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error { return nil } -func (a AppModule) RegisterRESTRoutes(client.Context, *mux.Router) {} - +func (a AppModule) RegisterRESTRoutes(client.Context, *mux.Router) {} func (a AppModule) RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) {} - -func (a AppModule) GetTxCmd() *cobra.Command { return nil } - -func (a AppModule) GetQueryCmd() *cobra.Command { return nil } - +func (a AppModule) GetTxCmd() *cobra.Command { return nil } +func (a AppModule) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } func (a AppModule) InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate { return nil } - func (a AppModule) ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage { return nil } - func (a AppModule) RegisterInvariants(sdk.InvariantRegistry) {} - func (a AppModule) Route() sdk.Route { return sdk.NewRoute("", NewHandler()) } - func (a AppModule) QuerierRoute() string { - return types.RouterKey + return "" } - func (a AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return nil } - -func (a AppModule) RegisterServices(module.Configurator) {} - +func (a AppModule) RegisterServices(cfg module.Configurator) { + utiltypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(a.bankKeeper)) +} func (a AppModule) ConsensusVersion() uint64 { return 1 } - func (a AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) {} - func (a AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate { return nil } diff --git a/x/util/types/expected_keepers.go b/x/util/types/expected_keepers.go new file mode 100644 index 000000000..5548a197c --- /dev/null +++ b/x/util/types/expected_keepers.go @@ -0,0 +1,8 @@ +package utiltypes + +import sdk "github.com/cosmos/cosmos-sdk/types" + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins +} diff --git a/x/util/types/keys.go b/x/util/types/keys.go index 19ac1637a..6b465b40d 100644 --- a/x/util/types/keys.go +++ b/x/util/types/keys.go @@ -1,4 +1,4 @@ -package types +package utiltypes const ( ModuleName = "util" diff --git a/x/util/types/module_accounts.go b/x/util/types/module_accounts.go new file mode 100644 index 000000000..1bb663a56 --- /dev/null +++ b/x/util/types/module_accounts.go @@ -0,0 +1,10 @@ +package utiltypes + +import sdk "github.com/cosmos/cosmos-sdk/types" + +var ModuleAccounts = []struct { + Name string + Account sdk.AccAddress +}{ + {}, +} diff --git a/x/util/types/query.pb.go b/x/util/types/query.pb.go index 5e0052274..1e3dffb6b 100644 --- a/x/util/types/query.pb.go +++ b/x/util/types/query.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: util/v1/query.proto -package types +package utiltypes import ( context "context" diff --git a/x/util/types/query.pb.gw.go b/x/util/types/query.pb.gw.go index 0ae006579..d5898dd71 100644 --- a/x/util/types/query.pb.gw.go +++ b/x/util/types/query.pb.gw.go @@ -6,7 +6,7 @@ Package types is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package types +package utiltypes import ( "context" From d2a9438920fd0e325e1832bde7f01367c4d783a1 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 6 Oct 2022 21:17:52 +0200 Subject: [PATCH 3/8] rename var --- x/util/keeper/query_server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/util/keeper/query_server.go b/x/util/keeper/query_server.go index 8f65aa91c..37e7638c8 100644 --- a/x/util/keeper/query_server.go +++ b/x/util/keeper/query_server.go @@ -24,12 +24,12 @@ func (q queryServer) ModuleAccounts( var moduleAccountsWithBalances []utiltypes.AccountWithBalance for _, acc := range utiltypes.ModuleAccounts { balances := q.k.GetAllBalances(sdkContext, acc.Account) - acc := utiltypes.AccountWithBalance{ + accWithBalance := utiltypes.AccountWithBalance{ Name: acc.Name, Address: acc.Account.String(), Balance: balances, } - moduleAccountsWithBalances = append(moduleAccountsWithBalances, acc) + moduleAccountsWithBalances = append(moduleAccountsWithBalances, accWithBalance) } return &utiltypes.QueryModuleAccountsResponse{}, nil From 58fed21cea1e5204766c00812b2cd268b9feb03b Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 6 Oct 2022 21:20:03 +0200 Subject: [PATCH 4/8] add accounts with balances into response --- proto/util/v1/query.proto | 1 + x/util/types/query.pb.go | 117 +++++++++++++++++++++++++++--------- x/util/types/query.pb.gw.go | 2 +- 3 files changed, 92 insertions(+), 28 deletions(-) diff --git a/proto/util/v1/query.proto b/proto/util/v1/query.proto index 5f736cf1b..3bcce7a97 100644 --- a/proto/util/v1/query.proto +++ b/proto/util/v1/query.proto @@ -23,6 +23,7 @@ service Query { message QueryModuleAccountsRequest {} message QueryModuleAccountsResponse { + repeated AccountWithBalance accounts = 1; } message AccountWithBalance { diff --git a/x/util/types/query.pb.go b/x/util/types/query.pb.go index 1e3dffb6b..ff1b9b17f 100644 --- a/x/util/types/query.pb.go +++ b/x/util/types/query.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: util/v1/query.proto -package utiltypes +package types import ( context "context" @@ -69,6 +69,7 @@ func (m *QueryModuleAccountsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryModuleAccountsRequest proto.InternalMessageInfo type QueryModuleAccountsResponse struct { + Accounts []*AccountWithBalance `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` } func (m *QueryModuleAccountsResponse) Reset() { *m = QueryModuleAccountsResponse{} } @@ -104,6 +105,13 @@ func (m *QueryModuleAccountsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryModuleAccountsResponse proto.InternalMessageInfo +func (m *QueryModuleAccountsResponse) GetAccounts() []*AccountWithBalance { + if m != nil { + return m.Accounts + } + return nil +} + type AccountWithBalance struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` @@ -173,32 +181,33 @@ func init() { func init() { proto.RegisterFile("util/v1/query.proto", fileDescriptor_ea08d750598e4157) } var fileDescriptor_ea08d750598e4157 = []byte{ - // 392 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0xea, 0xd3, 0x40, - 0x10, 0xc6, 0xb3, 0xff, 0xaa, 0xc5, 0x15, 0x7a, 0x58, 0x7b, 0x88, 0xb1, 0x6e, 0x4b, 0xf1, 0x50, - 0x2a, 0xee, 0x9a, 0xfa, 0x04, 0xb6, 0x5e, 0x15, 0xec, 0x45, 0xf0, 0x22, 0x9b, 0x64, 0x49, 0x17, - 0x93, 0x9d, 0x34, 0xbb, 0x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8f, 0xda, 0x41, 0xbf, 0x37, - 0xe9, 0xcd, 0x6e, 0x2d, 0xee, 0xb0, 0x96, 0x84, 0x35, 0x24, 0xac, 0x23, 0x61, 0x2b, 0x50, 0x7a, - 0xf9, 0x68, 0xff, 0x7d, 0xec, 0x7d, 0xf9, 0x31, 0x9e, 0xa5, 0xca, 0x6e, 0xaa, 0x88, 0xc5, 0x90, - 0xf3, 0x0e, 0xbb, 0x7d, 0x3c, 0x34, 0xc9, 0x1b, 0x6e, 0x77, 0x85, 0x34, 0x6e, 0xc0, 0xac, 0xcf, - 0xd9, 0x8b, 0x4f, 0x08, 0x5f, 0x77, 0x2c, 0xe4, 0x3d, 0xc2, 0x83, 0x4b, 0x20, 0x32, 0x67, 0x97, - 0x07, 0x60, 0xff, 0xde, 0x49, 0xf0, 0xe0, 0xbf, 0xbc, 0xdd, 0x86, 0xee, 0xbf, 0xfb, 0xfa, 0xeb, - 0xe3, 0x15, 0x25, 0x23, 0xde, 0x0e, 0x71, 0x77, 0xfd, 0xdc, 0x99, 0x5f, 0x8b, 0xce, 0xbd, 0x7c, - 0xba, 0x3f, 0x52, 0x74, 0x38, 0x52, 0xf4, 0xf3, 0x48, 0xd1, 0x87, 0x13, 0xf5, 0x0e, 0x27, 0xea, - 0x7d, 0x3b, 0x51, 0xef, 0xd5, 0xfc, 0x0f, 0xd0, 0xe7, 0x2e, 0x61, 0xb5, 0x11, 0x4a, 0x9f, 0xd3, - 0xde, 0xb6, 0x79, 0x0e, 0x38, 0xba, 0xe1, 0x2e, 0xfa, 0xf8, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x89, 0x87, 0xac, 0x8b, 0x62, 0x02, 0x00, 0x00, + // 414 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x8a, 0xd5, 0x30, + 0x14, 0xc6, 0x9b, 0x19, 0x75, 0x34, 0xc2, 0x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xe3, 0xa5, 0x50, 0x7a, 0x9a, 0xf6, 0xda, 0xcf, 0x73, 0x81, 0xb3, 0x2b, 0x6e, 0x23, 0xee, + 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x26, 0x25, 0xd0, 0x4c, 0xa2, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -326,6 +335,20 @@ func (m *QueryModuleAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if len(m.Accounts) > 0 { + for iNdEx := len(m.Accounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Accounts[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 } @@ -406,6 +429,12 @@ func (m *QueryModuleAccountsResponse) Size() (n int) { } var l int _ = l + if len(m.Accounts) > 0 { + for _, e := range m.Accounts { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -517,6 +546,40 @@ func (m *QueryModuleAccountsResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: QueryModuleAccountsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Accounts", 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.Accounts = append(m.Accounts, &AccountWithBalance{}) + if err := m.Accounts[len(m.Accounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/util/types/query.pb.gw.go b/x/util/types/query.pb.gw.go index d5898dd71..0ae006579 100644 --- a/x/util/types/query.pb.gw.go +++ b/x/util/types/query.pb.gw.go @@ -6,7 +6,7 @@ Package types is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package utiltypes +package types import ( "context" From 205a30c85e0d1b90a9a3766446a4b13453b50bc9 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 6 Oct 2022 22:20:54 +0200 Subject: [PATCH 5/8] add module accounts for query --- app/app.go | 5 ++- proto/util/v1/query.proto | 2 +- x/util/client/cli/query.go | 4 ++- x/util/handler.go | 2 +- x/util/keeper/query_server.go | 15 +++++--- x/util/module.go | 4 +-- x/util/types/expected_keepers.go | 2 +- x/util/types/keys.go | 2 +- x/util/types/module_accounts.go | 18 ++++++---- x/util/types/query.pb.go | 61 ++++++++++++++++---------------- 10 files changed, 63 insertions(+), 52 deletions(-) diff --git a/app/app.go b/app/app.go index bb38e55a8..306635d0e 100644 --- a/app/app.go +++ b/app/app.go @@ -3,14 +3,11 @@ package app import ( "encoding/json" "fmt" - "github.com/NibiruChain/nibiru/x/util/types" "io" "net/http" "os" "path/filepath" - "github.com/NibiruChain/nibiru/x/util" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -112,6 +109,8 @@ import ( pricefeedcli "github.com/NibiruChain/nibiru/x/pricefeed/client/cli" pricefeedkeeper "github.com/NibiruChain/nibiru/x/pricefeed/keeper" pricefeedtypes "github.com/NibiruChain/nibiru/x/pricefeed/types" + "github.com/NibiruChain/nibiru/x/util" + utiltypes "github.com/NibiruChain/nibiru/x/util/types" "github.com/NibiruChain/nibiru/x/vpool" vpoolcli "github.com/NibiruChain/nibiru/x/vpool/client/cli" vpoolkeeper "github.com/NibiruChain/nibiru/x/vpool/keeper" diff --git a/proto/util/v1/query.proto b/proto/util/v1/query.proto index 3bcce7a97..9fe63a85c 100644 --- a/proto/util/v1/query.proto +++ b/proto/util/v1/query.proto @@ -23,7 +23,7 @@ service Query { message QueryModuleAccountsRequest {} message QueryModuleAccountsResponse { - repeated AccountWithBalance accounts = 1; + repeated AccountWithBalance accounts = 1 [(gogoproto.nullable) = false]; } message AccountWithBalance { diff --git a/x/util/client/cli/query.go b/x/util/client/cli/query.go index d2791fedb..a9839d473 100644 --- a/x/util/client/cli/query.go +++ b/x/util/client/cli/query.go @@ -2,10 +2,12 @@ package cli import ( "fmt" - "github.com/NibiruChain/nibiru/x/util/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" + + utiltypes "github.com/NibiruChain/nibiru/x/util/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/util/handler.go b/x/util/handler.go index 4cd74258f..c151dda04 100644 --- a/x/util/handler.go +++ b/x/util/handler.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/NibiruChain/nibiru/x/util/types" + utiltypes "github.com/NibiruChain/nibiru/x/util/types" ) // NewHandler ... diff --git a/x/util/keeper/query_server.go b/x/util/keeper/query_server.go index 37e7638c8..a8551d190 100644 --- a/x/util/keeper/query_server.go +++ b/x/util/keeper/query_server.go @@ -2,9 +2,11 @@ package keeper import ( "context" + "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/NibiruChain/nibiru/x/util/types" + utiltypes "github.com/NibiruChain/nibiru/x/util/types" ) type queryServer struct { @@ -23,14 +25,17 @@ func (q queryServer) ModuleAccounts( var moduleAccountsWithBalances []utiltypes.AccountWithBalance for _, acc := range utiltypes.ModuleAccounts { - balances := q.k.GetAllBalances(sdkContext, acc.Account) + account := types.NewModuleAddress(acc) + + balances := q.k.GetAllBalances(sdkContext, account) + accWithBalance := utiltypes.AccountWithBalance{ - Name: acc.Name, - Address: acc.Account.String(), + Name: acc, + Address: account.String(), Balance: balances, } moduleAccountsWithBalances = append(moduleAccountsWithBalances, accWithBalance) } - return &utiltypes.QueryModuleAccountsResponse{}, nil + return &utiltypes.QueryModuleAccountsResponse{Accounts: moduleAccountsWithBalances}, nil } diff --git a/x/util/module.go b/x/util/module.go index 6973bb49d..593cabd52 100644 --- a/x/util/module.go +++ b/x/util/module.go @@ -2,7 +2,6 @@ package util import ( "encoding/json" - "github.com/NibiruChain/nibiru/x/util/client/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -14,8 +13,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/NibiruChain/nibiru/x/util/client/cli" "github.com/NibiruChain/nibiru/x/util/keeper" - "github.com/NibiruChain/nibiru/x/util/types" + utiltypes "github.com/NibiruChain/nibiru/x/util/types" ) var ( diff --git a/x/util/types/expected_keepers.go b/x/util/types/expected_keepers.go index 5548a197c..dd5a000f6 100644 --- a/x/util/types/expected_keepers.go +++ b/x/util/types/expected_keepers.go @@ -1,4 +1,4 @@ -package utiltypes +package types import sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/util/types/keys.go b/x/util/types/keys.go index 6b465b40d..19ac1637a 100644 --- a/x/util/types/keys.go +++ b/x/util/types/keys.go @@ -1,4 +1,4 @@ -package utiltypes +package types const ( ModuleName = "util" diff --git a/x/util/types/module_accounts.go b/x/util/types/module_accounts.go index 1bb663a56..812b5c882 100644 --- a/x/util/types/module_accounts.go +++ b/x/util/types/module_accounts.go @@ -1,10 +1,14 @@ -package utiltypes +package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + "github.com/NibiruChain/nibiru/x/common" + perptypes "github.com/NibiruChain/nibiru/x/perp/types" +) -var ModuleAccounts = []struct { - Name string - Account sdk.AccAddress -}{ - {}, +var ModuleAccounts = []string{ + perptypes.ModuleName, + perptypes.VaultModuleAccount, + perptypes.PerpEFModuleAccount, + perptypes.FeePoolModuleAccount, + common.TreasuryPoolModuleAccount, } diff --git a/x/util/types/query.pb.go b/x/util/types/query.pb.go index ff1b9b17f..2b91abfb5 100644 --- a/x/util/types/query.pb.go +++ b/x/util/types/query.pb.go @@ -69,7 +69,7 @@ func (m *QueryModuleAccountsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryModuleAccountsRequest proto.InternalMessageInfo type QueryModuleAccountsResponse struct { - Accounts []*AccountWithBalance `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + Accounts []AccountWithBalance `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts"` } func (m *QueryModuleAccountsResponse) Reset() { *m = QueryModuleAccountsResponse{} } @@ -105,7 +105,7 @@ func (m *QueryModuleAccountsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryModuleAccountsResponse proto.InternalMessageInfo -func (m *QueryModuleAccountsResponse) GetAccounts() []*AccountWithBalance { +func (m *QueryModuleAccountsResponse) GetAccounts() []AccountWithBalance { if m != nil { return m.Accounts } @@ -181,33 +181,34 @@ func init() { func init() { proto.RegisterFile("util/v1/query.proto", fileDescriptor_ea08d750598e4157) } var fileDescriptor_ea08d750598e4157 = []byte{ - // 414 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x8a, 0xd5, 0x30, - 0x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 0xf0, 0xb7, 0xa0, 0x4f, 0xdc, - 0x84, 0xe3, 0xa5, 0x50, 0x7a, 0x9a, 0xf6, 0xda, 0xcf, 0x73, 0x81, 0xb3, 0x2b, 0x6e, 0x23, 0xee, - 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x26, 0x25, 0xd0, 0x4c, 0xa2, 0x02, 0x00, 0x00, + // 417 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xbf, 0x6e, 0xd5, 0x30, + 0x14, 0xc6, 0xaf, 0xdb, 0x42, 0xc1, 0x48, 0x1d, 0x4c, 0x87, 0x10, 0xae, 0xdc, 0x2a, 0x62, 0xb8, + 0x2a, 0xc2, 0x26, 0xe5, 0x09, 0x48, 0xbb, 0x82, 0x44, 0x16, 0x24, 0x16, 0xe4, 0x24, 0x56, 0xae, + 0x45, 0xe2, 0x93, 0xc6, 0x4e, 0x44, 0x57, 0x5e, 0x00, 0x24, 0x26, 0x1e, 0x01, 0x9e, 0xa4, 0x63, + 0x25, 0x16, 0x26, 0x40, 0xf7, 0xf2, 0x20, 0x28, 0x76, 0x82, 0xb8, 0xfc, 0x91, 0x3a, 0xc5, 0x39, + 0xdf, 0xf9, 0x8e, 0xcf, 0xf7, 0x93, 0xf1, 0xed, 0xce, 0xaa, 0x8a, 0xf7, 0x31, 0x3f, 0xeb, 0x64, + 0x7b, 0xce, 0x9a, 0x16, 0x2c, 0x90, 0x3d, 0xad, 0x32, 0xd5, 0x76, 0x6c, 0xd0, 0x58, 0x1f, 0x87, + 0xfb, 0x25, 0x94, 0xe0, 0x24, 0x3e, 0x9c, 0x7c, 0x57, 0x38, 0x2f, 0x01, 0xca, 0x4a, 0x72, 0xd1, + 0x28, 0x2e, 0xb4, 0x06, 0x2b, 0xac, 0x02, 0x6d, 0x46, 0x95, 0xe6, 0x60, 0x6a, 0x30, 0x3c, 0x13, + 0x46, 0xf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 0x3f, 0xc3, 0xff, 0x9f, 0x6c, 0x78, 0xff, 0x4a, + 0xbd, 0x9e, 0x73, 0x74, 0xef, 0xcd, 0xe7, 0x1f, 0xef, 0xb7, 0x28, 0x99, 0x73, 0x6f, 0xe2, 0xee, + 0x0d, 0xd5, 0xae, 0xf9, 0xe5, 0xc4, 0x31, 0x39, 0xbd, 0x58, 0x51, 0x74, 0xb9, 0xa2, 0xe8, 0xfb, + 0x8a, 0xa2, 0x77, 0x6b, 0x3a, 0xbb, 0x5c, 0xd3, 0xd9, 0x97, 0x35, 0x9d, 0xbd, 0x38, 0xfa, 0x2d, + 0xe8, 0x53, 0x37, 0xe1, 0x64, 0x29, 0x94, 0x9e, 0xa6, 0xbd, 0xf6, 0xf3, 0x5c, 0xe0, 0xec, 0xba, + 0x7b, 0x17, 0x8f, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x61, 0x46, 0xb2, 0xa8, 0x02, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -575,7 +576,7 @@ func (m *QueryModuleAccountsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Accounts = append(m.Accounts, &AccountWithBalance{}) + m.Accounts = append(m.Accounts, AccountWithBalance{}) if err := m.Accounts[len(m.Accounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } From 34bc6788a5722452bb0a81fc694680140f356ea0 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 7 Oct 2022 20:33:10 +0200 Subject: [PATCH 6/8] add test for query --- x/util/keeper/query_server.go | 2 +- x/util/keeper/query_server_test.go | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 x/util/keeper/query_server_test.go diff --git a/x/util/keeper/query_server.go b/x/util/keeper/query_server.go index a8551d190..4a44d408d 100644 --- a/x/util/keeper/query_server.go +++ b/x/util/keeper/query_server.go @@ -2,9 +2,9 @@ package keeper import ( "context" - "github.com/cosmos/cosmos-sdk/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" utiltypes "github.com/NibiruChain/nibiru/x/util/types" ) diff --git a/x/util/keeper/query_server_test.go b/x/util/keeper/query_server_test.go new file mode 100644 index 000000000..e76fca0a1 --- /dev/null +++ b/x/util/keeper/query_server_test.go @@ -0,0 +1,38 @@ +package keeper_test + +import ( + "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/util/keeper" + "github.com/NibiruChain/nibiru/x/util/types" + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "testing" +) + +func TestQueryServer_ModuleAccounts(t *testing.T) { + app, ctx := simapp.NewTestNibiruAppAndContext(false) + goCtx := sdktypes.WrapSDKContext(ctx) + + qServer := keeper.NewQueryServer(app.BankKeeper) + + t.Log("query accounts and check empty balance") + accounts, err := qServer.ModuleAccounts(goCtx, &types.QueryModuleAccountsRequest{}) + require.NoError(t, err) + require.Len(t, accounts.Accounts, len(types.ModuleAccounts)) + require.Equal(t, accounts.Accounts[0].Balance, sdktypes.Coins{}) + + t.Log("we send some money") + someModuleAccount := types.ModuleAccounts[0] + err = app.BankKeeper.MintCoins( + ctx, + someModuleAccount, + sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000)), + ) + require.NoError(t, err) + + t.Log("we check that it returns some balance") + accounts, err = qServer.ModuleAccounts(goCtx, &types.QueryModuleAccountsRequest{}) + require.NoError(t, err) + require.Len(t, accounts.Accounts, len(types.ModuleAccounts)) + require.Equal(t, accounts.Accounts[0].Balance, sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000))) +} From dd704f97f15a57b46ddf0117b720de5dbb0c3125 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 7 Oct 2022 20:39:15 +0200 Subject: [PATCH 7/8] add changelog --- CHANGELOG.md | 1 + x/util/keeper/query_server_test.go | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6617eda6a..b82878b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#956](https://github.com/NibiruChain/nibiru/pull/956) - test(perp): partial liquidate unit test * [#981](https://github.com/NibiruChain/nibiru/pull/981) - chore(testutil): clean up x/testutil packages * [#980](https://github.com/NibiruChain/nibiru/pull/980) - test(perp): add `MsgClosePosition`, `MsgAddMargin`, and `MsgRemoveMargin` simulation tests +* [#987](https://github.com/NibiruChain/nibiru/pull/987) - feat: create a query that directly returns all module accounts without pagination or iteration ### Features * [#966](https://github.com/NibiruChain/nibiru/pull/966) - collections: add indexed map diff --git a/x/util/keeper/query_server_test.go b/x/util/keeper/query_server_test.go index e76fca0a1..08b4c568f 100644 --- a/x/util/keeper/query_server_test.go +++ b/x/util/keeper/query_server_test.go @@ -1,12 +1,14 @@ package keeper_test import ( + "testing" + + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/util/keeper" "github.com/NibiruChain/nibiru/x/util/types" - sdktypes "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "testing" ) func TestQueryServer_ModuleAccounts(t *testing.T) { From 0d69c0b34da7e53062dc2d6e36614161012da89a Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 12 Oct 2022 14:21:59 +0200 Subject: [PATCH 8/8] rename query module acccounts --- x/util/client/cli/query.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/util/client/cli/query.go b/x/util/client/cli/query.go index a9839d473..dfe1c1a90 100644 --- a/x/util/client/cli/query.go +++ b/x/util/client/cli/query.go @@ -22,7 +22,7 @@ func GetQueryCmd() *cobra.Command { } for _, cmd := range []*cobra.Command{ - CmdQueryParams(), + CmdQueryModuleAccounts(), } { queryCmd.AddCommand(cmd) } @@ -30,7 +30,7 @@ func GetQueryCmd() *cobra.Command { return queryCmd } -func CmdQueryParams() *cobra.Command { +func CmdQueryModuleAccounts() *cobra.Command { cmd := &cobra.Command{ Use: "module-accounts", Short: "shows all the module accounts in the blockchain",