From e443fb71851739c03ec1958989af6e3a32c42392 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 12 Nov 2021 11:16:09 -0500 Subject: [PATCH] fix: query account balance by ibc denom (backport #10394) (#10523) * fix: query account balance by ibc denom (#10394) ## Description Closes: #10381 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 99c5230fad0ca2ede83835cb9ee44f013b2d33ef) # Conflicts: # CHANGELOG.md # x/bank/types/query.pb.go * solve conflicts Co-authored-by: Sai Kumar <17549398+gsk967@users.noreply.github.com> Co-authored-by: marbar3778 --- CHANGELOG.md | 1 + docs/core/proto-docs.md | 2 +- proto/cosmos/bank/v1beta1/query.proto | 12 +++++------ x/bank/client/rest/grpc_query_test.go | 4 ++-- x/bank/types/query.pb.gw.go | 30 ++++++++++++--------------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a30f716c24..d44eee903daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing. * (rosetta) [\#10340](https://github.com/cosmos/cosmos-sdk/pull/10340) Use `GenesisChunked(ctx)` instead `Genesis(ctx)` to get genesis block height +* [\#10394](https://github.com/cosmos/cosmos-sdk/issues/10394) Fixes issue related to grpc-gateway of account balance by ibc-denom. ## [v0.44.2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.2) - 2021-10-12 diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 7524fbec750d..7d876f4e91c0 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1949,7 +1949,7 @@ Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Balance` | [QueryBalanceRequest](#cosmos.bank.v1beta1.QueryBalanceRequest) | [QueryBalanceResponse](#cosmos.bank.v1beta1.QueryBalanceResponse) | Balance queries the balance of a single coin for a single account. | GET|/cosmos/bank/v1beta1/balances/{address}/{denom}| +| `Balance` | [QueryBalanceRequest](#cosmos.bank.v1beta1.QueryBalanceRequest) | [QueryBalanceResponse](#cosmos.bank.v1beta1.QueryBalanceResponse) | Balance queries the balance of a single coin for a single account. | GET|/cosmos/bank/v1beta1/balances/{address}/by_denom| | `AllBalances` | [QueryAllBalancesRequest](#cosmos.bank.v1beta1.QueryAllBalancesRequest) | [QueryAllBalancesResponse](#cosmos.bank.v1beta1.QueryAllBalancesResponse) | AllBalances queries the balance of all coins for a single account. | GET|/cosmos/bank/v1beta1/balances/{address}| | `TotalSupply` | [QueryTotalSupplyRequest](#cosmos.bank.v1beta1.QueryTotalSupplyRequest) | [QueryTotalSupplyResponse](#cosmos.bank.v1beta1.QueryTotalSupplyResponse) | TotalSupply queries the total supply of all coins. | GET|/cosmos/bank/v1beta1/supply| | `SupplyOf` | [QuerySupplyOfRequest](#cosmos.bank.v1beta1.QuerySupplyOfRequest) | [QuerySupplyOfResponse](#cosmos.bank.v1beta1.QuerySupplyOfResponse) | SupplyOf queries the supply of a single coin. | GET|/cosmos/bank/v1beta1/supply/{denom}| diff --git a/proto/cosmos/bank/v1beta1/query.proto b/proto/cosmos/bank/v1beta1/query.proto index b1593513c9a1..520ba0696412 100644 --- a/proto/cosmos/bank/v1beta1/query.proto +++ b/proto/cosmos/bank/v1beta1/query.proto @@ -13,7 +13,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; service Query { // Balance queries the balance of a single coin for a single account. rpc Balance(QueryBalanceRequest) returns (QueryBalanceResponse) { - option (google.api.http).get = "/cosmos/bank/v1beta1/balances/{address}/{denom}"; + option (google.api.http).get = "/cosmos/bank/v1beta1/balances/{address}/by_denom"; } // AllBalances queries the balance of all coins for a single account. @@ -49,7 +49,7 @@ service Query { // QueryBalanceRequest is the request type for the Query/Balance RPC method. message QueryBalanceRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // address is the address to query balances for. @@ -67,7 +67,7 @@ message QueryBalanceResponse { // QueryBalanceRequest is the request type for the Query/AllBalances RPC method. message QueryAllBalancesRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // address is the address to query balances for. @@ -82,7 +82,7 @@ message QueryAllBalancesRequest { message QueryAllBalancesResponse { // balances is the balances of all the coins. repeated cosmos.base.v1beta1.Coin balances = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; // pagination defines the pagination in the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; @@ -91,7 +91,7 @@ message QueryAllBalancesResponse { // QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC // method. message QueryTotalSupplyRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // pagination defines an optional pagination for the request. @@ -105,7 +105,7 @@ message QueryTotalSupplyRequest { message QueryTotalSupplyResponse { // supply is the supply of the coins repeated cosmos.base.v1beta1.Coin supply = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; // pagination defines the pagination in the response. // diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 5277fd22d010..857aa58e4b83 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -234,7 +234,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }, { "gPRC account balance of a denom", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, val.Address.String(), s.cfg.BondDenom), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", baseURL, val.Address.String(), s.cfg.BondDenom), &types.QueryBalanceResponse{}, &types.QueryBalanceResponse{ Balance: &sdk.Coin{ @@ -245,7 +245,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }, { "gPRC account balance of a bogus denom", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/foobar", baseURL, val.Address.String()), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=foobar", baseURL, val.Address.String()), &types.QueryBalanceResponse{}, &types.QueryBalanceResponse{ Balance: &sdk.Coin{ diff --git a/x/bank/types/query.pb.gw.go b/x/bank/types/query.pb.gw.go index 8b8ed9a52607..4cd12b258912 100644 --- a/x/bank/types/query.pb.gw.go +++ b/x/bank/types/query.pb.gw.go @@ -31,6 +31,10 @@ var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var ( + filter_Query_Balance_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryBalanceRequest var metadata runtime.ServerMetadata @@ -53,15 +57,11 @@ func request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, c return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } - val, ok = pathParams["denom"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - - protoReq.Denom, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := client.Balance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -91,15 +91,11 @@ func local_request_Query_Balance_0(ctx context.Context, marshaler runtime.Marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } - val, ok = pathParams["denom"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - - protoReq.Denom, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := server.Balance(ctx, &protoReq) @@ -708,7 +704,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Balance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"cosmos", "bank", "v1beta1", "balances", "address", "denom"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Balance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"cosmos", "bank", "v1beta1", "balances", "address", "by_denom"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_AllBalances_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", "balances", "address"}, "", runtime.AssumeColonVerbOpt(false)))