From 23c2e3110bd2de67357c626014b44be239c4cc64 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 29 Aug 2024 21:23:52 +0800 Subject: [PATCH] Problem: url encoded characters are not properly handled in contract_by_denom --- CHANGELOG.md | 1 + x/cronos/keeper/grpc_query.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 535b683d49..2ee1e546fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ * [#1520](https://github.com/crypto-org-chain/cronos/pull/1520) Avoid invalid chain id for signer error when rpc call before chain id set in BeginBlock. * [#1539](https://github.com/crypto-org-chain/cronos/pull/1539) Fix go-block-stm bug that causes app hash mismatch. +* [#1560](https://github.com/crypto-org-chain/cronos/pull/1560) Ensure url encoded characters are properly handled in contract_by_denom api. *Jun 18, 2024* diff --git a/x/cronos/keeper/grpc_query.go b/x/cronos/keeper/grpc_query.go index 7bc1568154..b41a132031 100644 --- a/x/cronos/keeper/grpc_query.go +++ b/x/cronos/keeper/grpc_query.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "net/url" errorsmod "cosmossdk.io/errors" "google.golang.org/grpc/codes" @@ -21,18 +22,22 @@ var _ types.QueryServer = Keeper{} // ContractByDenom query contract by denom, returns both external contract and auto deployed contract func (k Keeper) ContractByDenom(goCtx context.Context, req *types.ContractByDenomRequest) (*types.ContractByDenomResponse, error) { + decoded, err := url.QueryUnescape(req.Denom) + if err != nil { + return nil, fmt.Errorf("fail to decode coin denom %s", req.Denom) + } ctx := sdk.UnwrapSDKContext(goCtx) rsp := types.ContractByDenomResponse{} - contract, found := k.getExternalContractByDenom(ctx, req.Denom) + contract, found := k.getExternalContractByDenom(ctx, decoded) if found { rsp.Contract = contract.String() } - autoContract, found := k.getAutoContractByDenom(ctx, req.Denom) + autoContract, found := k.getAutoContractByDenom(ctx, decoded) if found { rsp.AutoContract = autoContract.String() } if len(rsp.Contract) == 0 && len(rsp.AutoContract) == 0 { - return nil, fmt.Errorf("contract for the coin denom %s is not found", req.Denom) + return nil, fmt.Errorf("contract for the coin denom %s is not found", decoded) } return &rsp, nil }