Skip to content

Commit

Permalink
Problem: url encoded characters are not properly handled in contract_…
Browse files Browse the repository at this point in the history
…by_denom
  • Loading branch information
mmsqe committed Aug 29, 2024
1 parent eb0a15d commit 23c2e31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
11 changes: 8 additions & 3 deletions x/cronos/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"net/url"

errorsmod "cosmossdk.io/errors"
"google.golang.org/grpc/codes"
Expand All @@ -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
}
Expand Down

0 comments on commit 23c2e31

Please sign in to comment.