From e00a3eb179a5da67d17613a5a8f98a8aef0f0b20 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 9 Jun 2022 12:56:32 -0400 Subject: [PATCH] feat: support indexing denom metadata denom units (#258) --- docs/core/proto-docs.md | 35 +- proto/cosmos/bank/v1beta1/query.proto | 16 + types/query/pagination_test.go | 7 +- x/auth/types/query.pb.go | 4 +- x/bank/keeper/grpc_query.go | 70 ++-- x/bank/keeper/grpc_query_test.go | 49 +++ x/bank/keeper/keeper.go | 61 +++- x/bank/keeper/keeper_test.go | 69 ++-- x/bank/module.go | 7 +- x/bank/types/key.go | 9 +- x/bank/types/query.pb.go | 507 ++++++++++++++++++++++---- x/bank/types/query.pb.gw.go | 80 ++++ 12 files changed, 784 insertions(+), 130 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index d7e5a193a224..8b40ca024202 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -96,6 +96,8 @@ - [QueryAllBalancesResponse](#cosmos.bank.v1beta1.QueryAllBalancesResponse) - [QueryBalanceRequest](#cosmos.bank.v1beta1.QueryBalanceRequest) - [QueryBalanceResponse](#cosmos.bank.v1beta1.QueryBalanceResponse) + - [QueryBaseDenomRequest](#cosmos.bank.v1beta1.QueryBaseDenomRequest) + - [QueryBaseDenomResponse](#cosmos.bank.v1beta1.QueryBaseDenomResponse) - [QueryDenomMetadataRequest](#cosmos.bank.v1beta1.QueryDenomMetadataRequest) - [QueryDenomMetadataResponse](#cosmos.bank.v1beta1.QueryDenomMetadataResponse) - [QueryDenomsMetadataRequest](#cosmos.bank.v1beta1.QueryDenomsMetadataRequest) @@ -911,7 +913,7 @@ Query defines the gRPC querier service. Since: cosmos-sdk 0.43 | GET|/cosmos/auth/v1beta1/accounts| | `Account` | [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest) | [QueryAccountResponse](#cosmos.auth.v1beta1.QueryAccountResponse) | Account returns account details based on address. | GET|/cosmos/auth/v1beta1/accounts/{address}| | `Params` | [QueryParamsRequest](#cosmos.auth.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.auth.v1beta1.QueryParamsResponse) | Params queries all parameters. | GET|/cosmos/auth/v1beta1/params| -| `ModuleAccounts` | [QueryModuleAccountsRequest](#cosmos.auth.v1beta1.QueryModuleAccountsRequest) | [QueryModuleAccountsResponse](#cosmos.auth.v1beta1.QueryModuleAccountsResponse) | ModuleAccounts returns all the existing Module Accounts. | GET|/cosmos/auth/v1beta1/module_accounts| +| `ModuleAccounts` | [QueryModuleAccountsRequest](#cosmos.auth.v1beta1.QueryModuleAccountsRequest) | [QueryModuleAccountsResponse](#cosmos.auth.v1beta1.QueryModuleAccountsResponse) | ModuleAccounts returns all the existing module accounts. | GET|/cosmos/auth/v1beta1/module_accounts| @@ -1841,6 +1843,36 @@ QueryBalanceResponse is the response type for the Query/Balance RPC method. + + +### QueryBaseDenomRequest +QueryBaseDenomRequest defines the request type for the BaseDenom gRPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | | + + + + + + + + +### QueryBaseDenomResponse +QueryBaseDenomResponse defines the response type for the BaseDenom gRPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `base_denom` | [string](#string) | | | + + + + + + ### QueryDenomMetadataRequest @@ -2085,6 +2117,7 @@ Query defines the gRPC querier service. | `Params` | [QueryParamsRequest](#cosmos.bank.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.bank.v1beta1.QueryParamsResponse) | Params queries the parameters of x/bank module. | GET|/cosmos/bank/v1beta1/params| | `DenomMetadata` | [QueryDenomMetadataRequest](#cosmos.bank.v1beta1.QueryDenomMetadataRequest) | [QueryDenomMetadataResponse](#cosmos.bank.v1beta1.QueryDenomMetadataResponse) | DenomsMetadata queries the client metadata of a given coin denomination. | GET|/cosmos/bank/v1beta1/denoms_metadata/{denom}| | `DenomsMetadata` | [QueryDenomsMetadataRequest](#cosmos.bank.v1beta1.QueryDenomsMetadataRequest) | [QueryDenomsMetadataResponse](#cosmos.bank.v1beta1.QueryDenomsMetadataResponse) | DenomsMetadata queries the client metadata for all registered coin denominations. | GET|/cosmos/bank/v1beta1/denoms_metadata| +| `BaseDenom` | [QueryBaseDenomRequest](#cosmos.bank.v1beta1.QueryBaseDenomRequest) | [QueryBaseDenomResponse](#cosmos.bank.v1beta1.QueryBaseDenomResponse) | BaseDenom queries for a base denomination given a denom that can either be the base denom itself or a metadata denom unit that maps to the base denom. | GET|/cosmos/bank/v1beta1/base_denom| diff --git a/proto/cosmos/bank/v1beta1/query.proto b/proto/cosmos/bank/v1beta1/query.proto index f2da3bfcff08..c982e46cfd6e 100644 --- a/proto/cosmos/bank/v1beta1/query.proto +++ b/proto/cosmos/bank/v1beta1/query.proto @@ -55,6 +55,12 @@ service Query { rpc DenomsMetadata(QueryDenomsMetadataRequest) returns (QueryDenomsMetadataResponse) { option (google.api.http).get = "/cosmos/bank/v1beta1/denoms_metadata"; } + + // BaseDenom queries for a base denomination given a denom that can either be + // the base denom itself or a metadata denom unit that maps to the base denom. + rpc BaseDenom(QueryBaseDenomRequest) returns (QueryBaseDenomResponse) { + option (google.api.http).get = "/cosmos/bank/v1beta1/base_denom"; + } } // QueryBalanceRequest is the request type for the Query/Balance RPC method. @@ -208,3 +214,13 @@ message QueryDenomMetadataResponse { // metadata describes and provides all the client information for the requested token. Metadata metadata = 1 [(gogoproto.nullable) = false]; } + +// QueryBaseDenomRequest defines the request type for the BaseDenom gRPC method. +message QueryBaseDenomRequest { + string denom = 1; +} + +// QueryBaseDenomResponse defines the response type for the BaseDenom gRPC method. +message QueryBaseDenomResponse { + string base_denom = 1; +} diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 529200515d70..71a5f2bbfbed 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -3,10 +3,10 @@ package query_test import ( gocontext "context" "fmt" - "github.com/tendermint/tendermint/libs/log" "testing" "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -19,6 +19,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/query" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -63,7 +64,7 @@ func (s *paginationTestSuite) TestParsePagination() { func (s *paginationTestSuite) TestPagination() { app, ctx, _ := setupTest() queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.BankKeeper) + types.RegisterQueryServer(queryHelper, bankkeeper.Querier{BaseKeeper: app.BankKeeper.(bankkeeper.BaseKeeper)}) queryClient := types.NewQueryClient(queryHelper) var balances sdk.Coins @@ -172,7 +173,7 @@ func (s *paginationTestSuite) TestPagination() { func (s *paginationTestSuite) TestReversePagination() { app, ctx, _ := setupTest() queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.BankKeeper) + types.RegisterQueryServer(queryHelper, bankkeeper.Querier{BaseKeeper: app.BankKeeper.(bankkeeper.BaseKeeper)}) queryClient := types.NewQueryClient(queryHelper) var balances sdk.Coins diff --git a/x/auth/types/query.pb.go b/x/auth/types/query.pb.go index 8e8d516ce7c1..9f2f5a88ec8d 100644 --- a/x/auth/types/query.pb.go +++ b/x/auth/types/query.pb.go @@ -462,7 +462,7 @@ type QueryClient interface { Account(ctx context.Context, in *QueryAccountRequest, opts ...grpc.CallOption) (*QueryAccountResponse, error) // Params queries all parameters. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // ModuleAccounts returns all the existing Module Accounts. + // ModuleAccounts returns all the existing module accounts. ModuleAccounts(ctx context.Context, in *QueryModuleAccountsRequest, opts ...grpc.CallOption) (*QueryModuleAccountsResponse, error) } @@ -520,7 +520,7 @@ type QueryServer interface { Account(context.Context, *QueryAccountRequest) (*QueryAccountResponse, error) // Params queries all parameters. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // ModuleAccounts returns all the existing Module Accounts. + // ModuleAccounts returns all the existing module accounts. ModuleAccounts(context.Context, *QueryModuleAccountsRequest) (*QueryModuleAccountsResponse, error) } diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index 68521e1d0d13..73335bfb8d4b 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -12,10 +12,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/types" ) -var _ types.QueryServer = BaseKeeper{} +var _ types.QueryServer = Querier{} + +// Querier defines a wrapper around the x/bank keeper and implements the gRPC +// query interface. +type Querier struct { + BaseKeeper +} // Balance implements the Query/Balance gRPC method -func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { +func (q Querier) Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -34,13 +40,13 @@ func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } - balance := k.GetBalance(sdkCtx, address, req.Denom) + balance := q.GetBalance(sdkCtx, address, req.Denom) return &types.QueryBalanceResponse{Balance: &balance}, nil } // AllBalances implements the Query/AllBalances gRPC method -func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) { +func (q Querier) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -57,14 +63,14 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances sdkCtx := sdk.UnwrapSDKContext(ctx) balances := sdk.NewCoins() - accountStore := k.getAccountStore(sdkCtx, addr) + accountStore := q.getAccountStore(sdkCtx, addr) pageRes, err := query.Paginate(accountStore, req.Pagination, func(_, value []byte) error { var result sdk.Coin - err := k.cdc.Unmarshal(value, &result) - if err != nil { + if err := q.cdc.Unmarshal(value, &result); err != nil { return err } + balances = append(balances, result) return nil }) @@ -77,9 +83,9 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances } // TotalSupply implements the Query/TotalSupply gRPC method -func (k BaseKeeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequest) (*types.QueryTotalSupplyResponse, error) { +func (q Querier) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequest) (*types.QueryTotalSupplyResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - totalSupply, pageRes, err := k.GetPaginatedTotalSupplyWithOffsets(sdkCtx, req.Pagination) + totalSupply, pageRes, err := q.GetPaginatedTotalSupplyWithOffsets(sdkCtx, req.Pagination) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -88,7 +94,7 @@ func (k BaseKeeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupply } // SupplyOf implements the Query/SupplyOf gRPC method -func (k BaseKeeper) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) (*types.QuerySupplyOfResponse, error) { +func (q Querier) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) (*types.QuerySupplyOfResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -98,15 +104,15 @@ func (k BaseKeeper) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) } ctx := sdk.UnwrapSDKContext(c) - supply := k.GetSupplyWithOffset(ctx, req.Denom) + supply := q.GetSupplyWithOffset(ctx, req.Denom) return &types.QuerySupplyOfResponse{Amount: sdk.NewCoin(req.Denom, supply.Amount)}, nil } // TotalSupply implements the Query/TotalSupplyWithoutOffset gRPC method -func (k BaseKeeper) TotalSupplyWithoutOffset(ctx context.Context, req *types.QueryTotalSupplyWithoutOffsetRequest) (*types.QueryTotalSupplyWithoutOffsetResponse, error) { +func (q Querier) TotalSupplyWithoutOffset(ctx context.Context, req *types.QueryTotalSupplyWithoutOffsetRequest) (*types.QueryTotalSupplyWithoutOffsetResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - totalSupply, pageRes, err := k.GetPaginatedTotalSupply(sdkCtx, req.Pagination) + totalSupply, pageRes, err := q.GetPaginatedTotalSupply(sdkCtx, req.Pagination) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -115,7 +121,7 @@ func (k BaseKeeper) TotalSupplyWithoutOffset(ctx context.Context, req *types.Que } // SupplyOf implements the Query/SupplyOf gRPC method -func (k BaseKeeper) SupplyOfWithoutOffset(c context.Context, req *types.QuerySupplyOfWithoutOffsetRequest) (*types.QuerySupplyOfWithoutOffsetResponse, error) { +func (q Querier) SupplyOfWithoutOffset(c context.Context, req *types.QuerySupplyOfWithoutOffsetRequest) (*types.QuerySupplyOfWithoutOffsetResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -125,36 +131,38 @@ func (k BaseKeeper) SupplyOfWithoutOffset(c context.Context, req *types.QuerySup } ctx := sdk.UnwrapSDKContext(c) - supply := k.GetSupply(ctx, req.Denom) + supply := q.GetSupply(ctx, req.Denom) return &types.QuerySupplyOfWithoutOffsetResponse{Amount: sdk.NewCoin(req.Denom, supply.Amount)}, nil } // Params implements the gRPC service handler for querying x/bank parameters. -func (k BaseKeeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { +func (q Querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } sdkCtx := sdk.UnwrapSDKContext(ctx) - params := k.GetParams(sdkCtx) + params := q.GetParams(sdkCtx) return &types.QueryParamsResponse{Params: params}, nil } // DenomsMetadata implements Query/DenomsMetadata gRPC method. -func (k BaseKeeper) DenomsMetadata(c context.Context, req *types.QueryDenomsMetadataRequest) (*types.QueryDenomsMetadataResponse, error) { +func (q Querier) DenomsMetadata(c context.Context, req *types.QueryDenomsMetadataRequest) (*types.QueryDenomsMetadataResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } ctx := sdk.UnwrapSDKContext(c) - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomMetadataPrefix) + store := prefix.NewStore(ctx.KVStore(q.storeKey), types.DenomMetadataPrefix) metadatas := []types.Metadata{} pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error { var metadata types.Metadata - k.cdc.MustUnmarshal(value, &metadata) + if err := q.cdc.Unmarshal(value, &metadata); err != nil { + return err + } metadatas = append(metadatas, metadata) return nil @@ -171,7 +179,7 @@ func (k BaseKeeper) DenomsMetadata(c context.Context, req *types.QueryDenomsMeta } // DenomMetadata implements Query/DenomMetadata gRPC method. -func (k BaseKeeper) DenomMetadata(c context.Context, req *types.QueryDenomMetadataRequest) (*types.QueryDenomMetadataResponse, error) { +func (q Querier) DenomMetadata(c context.Context, req *types.QueryDenomMetadataRequest) (*types.QueryDenomMetadataResponse, error) { if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } @@ -182,7 +190,7 @@ func (k BaseKeeper) DenomMetadata(c context.Context, req *types.QueryDenomMetada ctx := sdk.UnwrapSDKContext(c) - metadata, found := k.GetDenomMetaData(ctx, req.Denom) + metadata, found := q.GetDenomMetaData(ctx, req.Denom) if !found { return nil, status.Errorf(codes.NotFound, "client metadata for denom %s", req.Denom) } @@ -191,3 +199,21 @@ func (k BaseKeeper) DenomMetadata(c context.Context, req *types.QueryDenomMetada Metadata: metadata, }, nil } + +func (q Querier) BaseDenom(c context.Context, req *types.QueryBaseDenomRequest) (*types.QueryBaseDenomResponse, error) { + if req == nil { + return nil, status.Errorf(codes.InvalidArgument, "empty request") + } + if req.Denom == "" { + return nil, status.Error(codes.InvalidArgument, "invalid denom") + } + + ctx := sdk.UnwrapSDKContext(c) + + baseDenom, ok := q.GetBaseDenom(ctx, req.Denom) + if !ok { + return nil, status.Errorf(codes.NotFound, "base denom not found for: %s", req.Denom) + } + + return &types.QueryBaseDenomResponse{BaseDenom: baseDenom}, nil +} diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index b167f6e2a98a..d5a0d0e6ec55 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -336,3 +336,52 @@ func (suite *IntegrationTestSuite) QueryDenomMetadataRequest() { }) } } + +func (s *IntegrationTestSuite) TestGRPC_BaseDenom() { + testCases := []struct { + name string + req *types.QueryBaseDenomRequest + expectErr bool + expectResult *types.QueryBaseDenomResponse + }{ + { + name: "valid base denom", + req: &types.QueryBaseDenomRequest{Denom: "uatom"}, + expectErr: false, + expectResult: &types.QueryBaseDenomResponse{BaseDenom: "uatom"}, + }, + { + name: "valid denom", + req: &types.QueryBaseDenomRequest{Denom: "atom"}, + expectErr: false, + expectResult: &types.QueryBaseDenomResponse{BaseDenom: "uatom"}, + }, + { + name: "invalid denom", + req: &types.QueryBaseDenomRequest{Denom: "foo"}, + expectErr: true, + }, + } + + expMetadata := s.getTestMetadata() + for _, md := range expMetadata { + s.app.BankKeeper.SetDenomMetaData(s.ctx, md) + } + + for _, tc := range testCases { + tc := tc + + s.Run(tc.name, func() { + ctx := sdk.WrapSDKContext(s.ctx) + + res, err := s.queryClient.BaseDenom(ctx, tc.req) + if tc.expectErr { + s.Require().Error(err) + s.Require().Nil(res) + } else { + s.Require().NoError(err) + s.Require().Equal(tc.expectResult, res) + } + }) + } +} diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 6b1255e6f8c4..a85d0a0536fd 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -35,6 +35,8 @@ type Keeper interface { GetSupplyWithOffset(ctx sdk.Context, denom string) sdk.Coin GetPaginatedTotalSupplyWithOffsets(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) IterateTotalSupplyWithOffsets(ctx sdk.Context, cb func(sdk.Coin) bool) + GetBaseDenom(ctx sdk.Context, denom string) (string, bool) + GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata) IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool) @@ -52,8 +54,6 @@ type Keeper interface { DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error - - types.QueryServer } // BaseKeeper manages transfers between accounts. It implements the Keeper interface. @@ -328,13 +328,60 @@ func (k BaseKeeper) IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metad } } -// SetDenomMetaData sets the denominations metadata -func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata) { +// SetDenomMetaData sets denomination metadata. It also stores a reverse lookup +// key from each of the denom's base units to the base denom itself, allowing a +// caller to be able to query for the base denom without knowing it ahead of time, +// only requiring knowledge of any given denom unit. E.g. a caller could fetch +// the base denom of an ATOM IBC asset using the denom unit of 'uatom'. +// +// Note, it is the caller's responsibility to ensure they are not overwriting +// denomination metadata for assets with the same base denom, or rather to +// ensure that metadata cannot exist for more than one base denom. The same +// applies for base units. In other words, the caller must ensure base denoms +// and their denom units are globally unique. +func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetadata types.Metadata) { + store := ctx.KVStore(k.storeKey) + denomMetaDataStore := prefix.NewStore(store, types.DenomMetadataKey(denomMetadata.Base)) + + m := k.cdc.MustMarshal(&denomMetadata) + denomMetaDataStore.Set([]byte(denomMetadata.Base), m) + + // Store denom units under a separate store that acts as a reverse lookup index + // to the base denom and the corresponding metadata. + denomMetadataReverseStore := prefix.NewStore(store, types.DenomMetadataReversePrefix) + for _, unit := range denomMetadata.DenomUnits { + denomMetadataReverseStore.Set([]byte(unit.Denom), []byte(denomMetadata.Base)) + } +} + +// GetBaseDenom queries for a base denom, given a denom that can either be the +// base denom itself, or a metadata denom unit, that maps to the base denom. There +// are three cases where we can find the base denom: +// +// 1. The denom provided is already the base denom, which means we'll have +// supply for it. +// 2. The denom provided is already the base denom, which we can get from +// metadata, but that does not necessarily need to exist. +// 3. The denom provided is a metadata denom unit that maps to the base denom. +// +// We can skip case (2) as case (1) should handle that for us. If the base denom +// exists, we return (, true), otherwise, we return ("", false). +func (k BaseKeeper) GetBaseDenom(ctx sdk.Context, denom string) (string, bool) { store := ctx.KVStore(k.storeKey) - denomMetaDataStore := prefix.NewStore(store, types.DenomMetadataKey(denomMetaData.Base)) - m := k.cdc.MustMarshal(&denomMetaData) - denomMetaDataStore.Set([]byte(denomMetaData.Base), m) + // first, check if the provided denom is already the base denom + if k.HasSupply(ctx, denom) { + return denom, true + } + + // otherwise, check for a denom unit and return the corresponding base denom + reversePrefixStore := prefix.NewStore(store, types.DenomMetadataReversePrefix) + if bz := reversePrefixStore.Get([]byte(denom)); len(bz) > 0 { + // the value is the base denom + return string(bz), true + } + + return "", false } // SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress. diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 5b5a673e0568..74218383cb04 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -103,7 +103,7 @@ func (suite *IntegrationTestSuite) SetupTest() { app.BankKeeper.SetParams(ctx, types.DefaultParams()) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, app.BankKeeper) + types.RegisterQueryServer(queryHelper, keeper.Querier{BaseKeeper: app.BankKeeper.(keeper.BaseKeeper)}) queryClient := types.NewQueryClient(queryHelper) suite.app = app @@ -1053,23 +1053,35 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins_Invalid() { suite.Require().Error(app.BankKeeper.UndelegateCoins(ctx, addrModule, addr1, delCoins)) } -func (suite *IntegrationTestSuite) TestSetDenomMetaData() { - app, ctx := suite.app, suite.ctx +func (s *IntegrationTestSuite) TestSetDenomMetaData() { + app, ctx := s.app, s.ctx - metadata := suite.getTestMetadata() + bk := app.BankKeeper + expMetadata := s.getTestMetadata() + for _, md := range expMetadata { + s.app.BankKeeper.SetDenomMetaData(s.ctx, md) + } - for i := range []int{1, 2} { - app.BankKeeper.SetDenomMetaData(ctx, metadata[i]) + gotMetadata, found := bk.GetDenomMetaData(ctx, expMetadata[1].Base) + s.Require().True(found) + s.Require().Equal(expMetadata[1].GetBase(), gotMetadata.GetBase()) + s.Require().Equal(expMetadata[1].GetDisplay(), gotMetadata.GetDisplay()) + s.Require().Equal(expMetadata[1].GetDescription(), gotMetadata.GetDescription()) + s.Require().Equal(expMetadata[1].GetDenomUnits()[1].GetDenom(), gotMetadata.GetDenomUnits()[1].GetDenom()) + s.Require().Equal(expMetadata[1].GetDenomUnits()[1].GetExponent(), gotMetadata.GetDenomUnits()[1].GetExponent()) + s.Require().Equal(expMetadata[1].GetDenomUnits()[1].GetAliases(), gotMetadata.GetDenomUnits()[1].GetAliases()) + + // require reverse indexes are stored correctly + expBaseDenom := expMetadata[0].Base + for _, denomUnit := range expMetadata[0].DenomUnits { + gotBaseDenom, ok := bk.GetBaseDenom(ctx, denomUnit.Denom) + s.Require().True(ok) + s.Require().Equal(expBaseDenom, gotBaseDenom) } - actualMetadata, found := app.BankKeeper.GetDenomMetaData(ctx, metadata[1].Base) - suite.Require().True(found) - suite.Require().Equal(metadata[1].GetBase(), actualMetadata.GetBase()) - suite.Require().Equal(metadata[1].GetDisplay(), actualMetadata.GetDisplay()) - suite.Require().Equal(metadata[1].GetDescription(), actualMetadata.GetDescription()) - suite.Require().Equal(metadata[1].GetDenomUnits()[1].GetDenom(), actualMetadata.GetDenomUnits()[1].GetDenom()) - suite.Require().Equal(metadata[1].GetDenomUnits()[1].GetExponent(), actualMetadata.GetDenomUnits()[1].GetExponent()) - suite.Require().Equal(metadata[1].GetDenomUnits()[1].GetAliases(), actualMetadata.GetDenomUnits()[1].GetAliases()) + gotBaseDenom, ok := bk.GetBaseDenom(ctx, "NON_EXISTENT_DENOM_UNIT") + s.Require().False(ok) + s.Require().Empty(gotBaseDenom) } func (suite *IntegrationTestSuite) TestIterateAllDenomMetaData() { @@ -1196,26 +1208,27 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() { } func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata { - return []types.Metadata{{ - Name: "Cosmos Hub Atom", - Symbol: "ATOM", - Description: "The native staking token of the Cosmos Hub.", - DenomUnits: []*types.DenomUnit{ - {"uatom", uint32(0), []string{"microatom"}}, - {"matom", uint32(3), []string{"milliatom"}}, - {"atom", uint32(6), nil}, + return []types.Metadata{ + { + Name: "Cosmos Hub Atom", + Symbol: "ATOM", + Description: "The native staking token of the Cosmos Hub.", + DenomUnits: []*types.DenomUnit{ + {Denom: "uatom", Exponent: uint32(0), Aliases: []string{"microatom"}}, + {Denom: "matom", Exponent: uint32(3), Aliases: []string{"milliatom"}}, + {Denom: "atom", Exponent: uint32(6), Aliases: nil}, + }, + Base: "uatom", + Display: "atom", }, - Base: "uatom", - Display: "atom", - }, { Name: "Token", Symbol: "TOKEN", Description: "The native staking token of the Token Hub.", DenomUnits: []*types.DenomUnit{ - {"1token", uint32(5), []string{"decitoken"}}, - {"2token", uint32(4), []string{"centitoken"}}, - {"3token", uint32(7), []string{"dekatoken"}}, + {Denom: "1token", Exponent: uint32(5), Aliases: []string{"decitoken"}}, + {Denom: "2token", Exponent: uint32(4), Aliases: []string{"centitoken"}}, + {Denom: "3token", Exponent: uint32(7), Aliases: []string{"dekatoken"}}, }, Base: "utoken", Display: "token", diff --git a/x/bank/module.go b/x/bank/module.go index 9349e268eca8..feeab6507834 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -105,9 +105,12 @@ type AppModule struct { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) - m := keeper.NewMigrator(am.keeper.(keeper.BaseKeeper)) + baseKeeper := am.keeper.(keeper.BaseKeeper) + querier := keeper.Querier{BaseKeeper: baseKeeper} + types.RegisterQueryServer(cfg.QueryServer(), querier) + + m := keeper.NewMigrator(baseKeeper) cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2) } diff --git a/x/bank/types/key.go b/x/bank/types/key.go index e0a4f9047f71..875093bf0874 100644 --- a/x/bank/types/key.go +++ b/x/bank/types/key.go @@ -23,10 +23,11 @@ const ( var ( // BalancesPrefix is the prefix for the account balances store. We use a byte // (instead of `[]byte("balances")` to save some disk space). - BalancesPrefix = []byte{0x02} - SupplyKey = []byte{0x00} - DenomMetadataPrefix = []byte{0x1} - SupplyOffsetKey = []byte{0x88} + BalancesPrefix = []byte{0x02} + SupplyKey = []byte{0x00} + DenomMetadataPrefix = []byte{0x1} + DenomMetadataReversePrefix = []byte{0x03} + SupplyOffsetKey = []byte{0x88} ) // DenomMetadataKey returns the denomination metadata key. diff --git a/x/bank/types/query.pb.go b/x/bank/types/query.pb.go index 4d2928b5f161..3af52b138df5 100644 --- a/x/bank/types/query.pb.go +++ b/x/bank/types/query.pb.go @@ -877,6 +877,96 @@ func (m *QueryDenomMetadataResponse) GetMetadata() Metadata { return Metadata{} } +// QueryBaseDenomRequest defines the request type for the BaseDenom gRPC method. +type QueryBaseDenomRequest struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryBaseDenomRequest) Reset() { *m = QueryBaseDenomRequest{} } +func (m *QueryBaseDenomRequest) String() string { return proto.CompactTextString(m) } +func (*QueryBaseDenomRequest) ProtoMessage() {} +func (*QueryBaseDenomRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9c6fc1939682df13, []int{18} +} +func (m *QueryBaseDenomRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBaseDenomRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBaseDenomRequest.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 *QueryBaseDenomRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBaseDenomRequest.Merge(m, src) +} +func (m *QueryBaseDenomRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryBaseDenomRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBaseDenomRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBaseDenomRequest proto.InternalMessageInfo + +func (m *QueryBaseDenomRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +// QueryBaseDenomResponse defines the response type for the BaseDenom gRPC method. +type QueryBaseDenomResponse struct { + BaseDenom string `protobuf:"bytes,1,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` +} + +func (m *QueryBaseDenomResponse) Reset() { *m = QueryBaseDenomResponse{} } +func (m *QueryBaseDenomResponse) String() string { return proto.CompactTextString(m) } +func (*QueryBaseDenomResponse) ProtoMessage() {} +func (*QueryBaseDenomResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9c6fc1939682df13, []int{19} +} +func (m *QueryBaseDenomResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBaseDenomResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBaseDenomResponse.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 *QueryBaseDenomResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBaseDenomResponse.Merge(m, src) +} +func (m *QueryBaseDenomResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryBaseDenomResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBaseDenomResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBaseDenomResponse proto.InternalMessageInfo + +func (m *QueryBaseDenomResponse) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + func init() { proto.RegisterType((*QueryBalanceRequest)(nil), "cosmos.bank.v1beta1.QueryBalanceRequest") proto.RegisterType((*QueryBalanceResponse)(nil), "cosmos.bank.v1beta1.QueryBalanceResponse") @@ -896,72 +986,77 @@ func init() { proto.RegisterType((*QueryDenomsMetadataResponse)(nil), "cosmos.bank.v1beta1.QueryDenomsMetadataResponse") proto.RegisterType((*QueryDenomMetadataRequest)(nil), "cosmos.bank.v1beta1.QueryDenomMetadataRequest") proto.RegisterType((*QueryDenomMetadataResponse)(nil), "cosmos.bank.v1beta1.QueryDenomMetadataResponse") + proto.RegisterType((*QueryBaseDenomRequest)(nil), "cosmos.bank.v1beta1.QueryBaseDenomRequest") + proto.RegisterType((*QueryBaseDenomResponse)(nil), "cosmos.bank.v1beta1.QueryBaseDenomResponse") } func init() { proto.RegisterFile("cosmos/bank/v1beta1/query.proto", fileDescriptor_9c6fc1939682df13) } var fileDescriptor_9c6fc1939682df13 = []byte{ - // 947 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x57, 0xcf, 0x8b, 0x23, 0x45, - 0x14, 0x4e, 0xad, 0x6e, 0x26, 0xfb, 0x82, 0x1e, 0x6a, 0xb3, 0x98, 0xed, 0x71, 0x13, 0xed, 0xfd, - 0x31, 0x99, 0x31, 0xdb, 0x3d, 0x93, 0x5d, 0x5c, 0x67, 0x2e, 0xb2, 0x59, 0xd1, 0x83, 0xc8, 0xc4, - 0x28,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, 0x80, 0xd6, 0x07, 0x02, 0xda, 0xa2, - 0x82, 0xea, 0x0f, 0x08, 0x2e, 0x69, 0x87, 0x32, 0x7e, 0x71, 0xb1, 0x75, 0x5a, 0x05, 0x77, 0xfe, - 0x31, 0x4e, 0xd2, 0xdf, 0xe1, 0xf4, 0x6f, 0xe3, 0x5a, 0x7a, 0xfa, 0x61, 0x3b, 0x3e, 0x44, 0x90, - 0x15, 0x13, 0x1b, 0xaf, 0xcd, 0xaf, 0x1f, 0x5b, 0x0f, 0x46, 0x65, 0x71, 0x60, 0xaa, 0x2b, 0x2a, - 0x76, 0x03, 0xfe, 0x06, 0xc1, 0x53, 0xb1, 0x91, 0x86, 0xad, 0xf9, 0x05, 0x74, 0xe3, 0xd2, 0xb0, - 0x53, 0xc7, 0x4b, 0x5e, 0xb7, 0x39, 0x2f, 0x0b, 0x57, 0xb5, 0xbc, 0xb8, 0x35, 0xac, 0xa5, 0x06, - 0x63, 0xe8, 0xd5, 0xd7, 0x08, 0x9e, 0x8e, 0x6f, 0x16, 0xbc, 0xa8, 0xf2, 0xf4, 0xaa, 0x33, 0x36, - 0xd3, 0x03, 0x24, 0xd7, 0x2a, 0xe7, 0x7a, 0x03, 0x5f, 0x4b, 0xc3, 0xb5, 0x7e, 0xef, 0xf0, 0xb8, - 0x84, 0x8e, 0x8e, 0x4b, 0xe8, 0x8f, 0xe3, 0x12, 0xfa, 0xfc, 0xa4, 0x94, 0x39, 0x3a, 0x29, 0x65, - 0x7e, 0x3d, 0x29, 0x65, 0xde, 0x5d, 0x4f, 0x7c, 0xff, 0x79, 0x28, 0xd2, 0xf2, 0xd7, 0xa0, 0x76, - 0x96, 0xff, 0xd7, 0x76, 0xeb, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x6d, 0x5e, 0x63, 0x8d, - 0x0e, 0x00, 0x00, + // 1004 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02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de, 0x75, 0xa3, 0xfd, 0xd0, 0x13, 0xd2, 0x41, 0x34, + 0xe2, 0xe0, 0xf4, 0x35, 0x43, 0x5d, 0xf3, 0x63, 0xeb, 0x52, 0x94, 0xc9, 0xc2, 0xec, 0x5d, 0x54, + 0xf5, 0x6d, 0x1e, 0xb1, 0xee, 0x5b, 0xfd, 0x30, 0xec, 0xee, 0x6b, 0x55, 0xd3, 0xda, 0x91, 0x53, + 0xd0, 0xee, 0x40, 0x6b, 0x97, 0xca, 0x86, 0xda, 0xb5, 0xa0, 0x28, 0xe4, 0xc9, 0xa3, 0x50, 0x0e, + 0x43, 0x9f, 0x9e, 0x6e, 0x55, 0x7c, 0xb6, 0x55, 0x11, 0x9b, 0x3b, 0x5a, 0xb4, 0xf8, 0x9d, 0x20, + 0x89, 0x77, 0xc2, 0xde, 0x82, 0xf3, 0x43, 0xd6, 0x58, 0xf4, 0x1a, 0x14, 0x59, 0x8f, 0xf7, 0x83, + 0x68, 0xec, 0x9b, 0x50, 0x7f, 0x72, 0x50, 0x74, 0x03, 0xcd, 0xed, 0xbb, 0x70, 0x79, 0x58, 0xc9, + 0x77, 0x3a, 0xd1, 0x6d, 0xde, 0x8f, 0x36, 0x77, 0x76, 0x84, 0x17, 0x3d, 0xba, 0x26, 0xfe, 0x4a, + 0xe0, 0xca, 0x98, 0xd4, 0x8f, 0x65, 0x47, 0xd7, 0xe1, 0x62, 0xaa, 0x47, 0x46, 0x39, 0xcd, 0xed, + 0x7d, 0x0f, 0xec, 0x2c, 0xd7, 0xff, 0xdb, 0xeb, 0x19, 0xa0, 0x32, 0xfc, 0x16, 0xdb, 0x63, 0x3d, + 0x3d, 0xf4, 0xec, 0x2d, 0x1c, 0xd7, 0xfa, 0x14, 0xb3, 0xac, 0x43, 0x31, 0x94, 0x27, 0x98, 0x65, + 0xd6, 0x31, 0xec, 0x22, 0x47, 0x39, 0xe9, 0x3c, 0xca, 0xc1, 0x6e, 0x83, 0x25, 0x23, 0xbe, 0x32, + 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 0x4c, 0xc5, 0x93, 0x9f, 0x2e, + 0x65, 0x8d, 0xe4, 0xf4, 0x36, 0xb1, 0xae, 0xe5, 0xb2, 0x45, 0xa8, 0x79, 0x09, 0x75, 0x91, 0x56, + 0x46, 0x4c, 0x46, 0xbd, 0x65, 0xea, 0xb7, 0x0e, 0x0e, 0xcb, 0xe4, 0xe1, 0x61, 0x99, 0xfc, 0x79, + 0x58, 0x26, 0x5f, 0x1c, 0x95, 0x0b, 0x0f, 0x8f, 0xca, 0x85, 0xdf, 0x8e, 0xca, 0x85, 0x77, 0x17, + 0x33, 0xef, 0x7d, 0x77, 0x55, 0x44, 0x79, 0xfd, 0x6b, 0x16, 0xe5, 0x7f, 0xab, 0xd7, 0xff, 0x09, + 0x00, 0x00, 0xff, 0xff, 0x37, 0x40, 0xbd, 0x99, 0x85, 0x0f, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -994,6 +1089,9 @@ type QueryClient interface { DenomMetadata(ctx context.Context, in *QueryDenomMetadataRequest, opts ...grpc.CallOption) (*QueryDenomMetadataResponse, error) // DenomsMetadata queries the client metadata for all registered coin denominations. DenomsMetadata(ctx context.Context, in *QueryDenomsMetadataRequest, opts ...grpc.CallOption) (*QueryDenomsMetadataResponse, error) + // BaseDenom queries for a base denomination given a denom that can either be + // the base denom itself or a metadata denom unit that maps to the base denom. + BaseDenom(ctx context.Context, in *QueryBaseDenomRequest, opts ...grpc.CallOption) (*QueryBaseDenomResponse, error) } type queryClient struct { @@ -1085,6 +1183,15 @@ func (c *queryClient) DenomsMetadata(ctx context.Context, in *QueryDenomsMetadat return out, nil } +func (c *queryClient) BaseDenom(ctx context.Context, in *QueryBaseDenomRequest, opts ...grpc.CallOption) (*QueryBaseDenomResponse, error) { + out := new(QueryBaseDenomResponse) + err := c.cc.Invoke(ctx, "/cosmos.bank.v1beta1.Query/BaseDenom", 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. @@ -1105,6 +1212,9 @@ type QueryServer interface { DenomMetadata(context.Context, *QueryDenomMetadataRequest) (*QueryDenomMetadataResponse, error) // DenomsMetadata queries the client metadata for all registered coin denominations. DenomsMetadata(context.Context, *QueryDenomsMetadataRequest) (*QueryDenomsMetadataResponse, error) + // BaseDenom queries for a base denomination given a denom that can either be + // the base denom itself or a metadata denom unit that maps to the base denom. + BaseDenom(context.Context, *QueryBaseDenomRequest) (*QueryBaseDenomResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1138,6 +1248,9 @@ func (*UnimplementedQueryServer) DenomMetadata(ctx context.Context, req *QueryDe func (*UnimplementedQueryServer) DenomsMetadata(ctx context.Context, req *QueryDenomsMetadataRequest) (*QueryDenomsMetadataResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DenomsMetadata not implemented") } +func (*UnimplementedQueryServer) BaseDenom(ctx context.Context, req *QueryBaseDenomRequest) (*QueryBaseDenomResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BaseDenom not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -1305,6 +1418,24 @@ func _Query_DenomsMetadata_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Query_BaseDenom_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryBaseDenomRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BaseDenom(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.bank.v1beta1.Query/BaseDenom", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BaseDenom(ctx, req.(*QueryBaseDenomRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.bank.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -1345,6 +1476,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "DenomsMetadata", Handler: _Query_DenomsMetadata_Handler, }, + { + MethodName: "BaseDenom", + Handler: _Query_BaseDenom_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/bank/v1beta1/query.proto", @@ -2010,6 +2145,66 @@ func (m *QueryDenomMetadataResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *QueryBaseDenomRequest) 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 *QueryBaseDenomRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBaseDenomRequest) 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 *QueryBaseDenomResponse) 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 *QueryBaseDenomResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBaseDenomResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -2275,6 +2470,32 @@ func (m *QueryDenomMetadataResponse) Size() (n int) { return n } +func (m *QueryBaseDenomRequest) 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 *QueryBaseDenomResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3965,6 +4186,170 @@ func (m *QueryDenomMetadataResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryBaseDenomRequest) 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: QueryBaseDenomRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBaseDenomRequest: 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) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryBaseDenomResponse) 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: QueryBaseDenomResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBaseDenomResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", 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.BaseDenom = string(dAtA[iNdEx:postIndex]) + 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 diff --git a/x/bank/types/query.pb.gw.go b/x/bank/types/query.pb.gw.go index bbc2827200ba..3e04ab0c3387 100644 --- a/x/bank/types/query.pb.gw.go +++ b/x/bank/types/query.pb.gw.go @@ -463,6 +463,42 @@ func local_request_Query_DenomsMetadata_0(ctx context.Context, marshaler runtime } +var ( + filter_Query_BaseDenom_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_BaseDenom_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBaseDenomRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BaseDenom_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.BaseDenom(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BaseDenom_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBaseDenomRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_BaseDenom_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.BaseDenom(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. @@ -649,6 +685,26 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_BaseDenom_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_BaseDenom_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_BaseDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -870,6 +926,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_BaseDenom_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_BaseDenom_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_BaseDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -891,6 +967,8 @@ var ( pattern_Query_DenomMetadata_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "bank", "v1beta1", "denoms_metadata", "denom"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_DenomsMetadata_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "bank", "v1beta1", "denoms_metadata"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_BaseDenom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "bank", "v1beta1", "base_denom"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -911,4 +989,6 @@ var ( forward_Query_DenomMetadata_0 = runtime.ForwardResponseMessage forward_Query_DenomsMetadata_0 = runtime.ForwardResponseMessage + + forward_Query_BaseDenom_0 = runtime.ForwardResponseMessage )