Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve DenomTrace grpc #1342

Merged
merged 16 commits into from
May 12, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (transfer) [\#1342](https://github.com/cosmos/ibc-go/pull/1342) `DenomTrace` grpc now takes in either an `ibc denom` or a `hash` instead of only accepting a `hash` as input like before.
catShaark marked this conversation as resolved.
Show resolved Hide resolved
* (modules/core/keeper) [\#1284](https://github.com/cosmos/ibc-go/pull/1284) Add sanity check for the keepers passed into `ibckeeper.NewKeeper`. `ibckeeper.NewKeeper` now panics if any of the keepers passed in is empty.
* (middleware) [\#1022](https://github.com/cosmos/ibc-go/pull/1022) Add `GetAppVersion` to the ICS4Wrapper interface. This function should be used by IBC applications to obtain their own version since the version set in the channel structure may be wrapped many times by middleware.
* (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`.
Expand Down
4 changes: 3 additions & 1 deletion docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ paths:
format: byte
parameters:
- name: hash
description: hash (in hex format) of the denomination trace information.
description: >-
hash (in hex format) or denom (full denom with ibc prefix) of the
denomination trace information.
in: path
required: true
type: string
Expand Down
2 changes: 1 addition & 1 deletion docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ method

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `hash` | [string](#string) | | hash (in hex format) of the denomination trace information. |
| `hash` | [string](#string) | | hash (in hex format) or denom (full denom with ibc prefix) of the denomination trace information. |



Expand Down
10 changes: 5 additions & 5 deletions modules/apps/transfer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
)

// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given hash.
// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given trace hash or ibc denom.
func GetCmdQueryDenomTrace() *cobra.Command {
cmd := &cobra.Command{
Use: "denom-trace [hash]",
Short: "Query the denom trace info from a given trace hash",
Long: "Query the denom trace info from a given trace hash",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash]", version.AppName),
Use: "denom-trace [hash/denom]",
Short: "Query the denom trace info from a given trace hash or ibc denom",
Long: "Query the denom trace info from a given trace hash or ibc denom",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash/denom]", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down
13 changes: 11 additions & 2 deletions modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package keeper
import (
"context"
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -22,9 +24,16 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
return nil, status.Error(codes.InvalidArgument, "empty request")
}

hash, err := types.ParseHexHash(req.Hash)
var hash tmbytes.HexBytes
var err error
if strings.HasPrefix(req.Hash, "ibc/") {
hash, err = types.ParseHexHash(req.Hash[4:])
} else {
hash, err = types.ParseHexHash(req.Hash)
}
catShaark marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash %s, %s", req.Hash, err))
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", hash.String(), err))
}

ctx := sdk.UnwrapSDKContext(c)
Expand Down
31 changes: 22 additions & 9 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,50 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
expPass bool
}{
{
"invalid hex hash",
"success: correct ibc denom",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
Hash: expTrace.IBCDenom(),
}
},
false,
true,
},
{
"not found denom trace",
"success: correct hex hash",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
}
},
true,
},
{
"false: invalid hash",
catShaark marked this conversation as resolved.
Show resolved Hide resolved
func() {
req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
}
},
false,
},
{
"success",
"false: not found denom trace",
catShaark marked this conversation as resolved.
Show resolved Hide resolved
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
Hash: expTrace.IBCDenom(),
}
},
true,
false,
},
}

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/ibc/applications/transfer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ service Query {
// QueryDenomTraceRequest is the request type for the Query/DenomTrace RPC
// method
message QueryDenomTraceRequest {
// hash (in hex format) of the denomination trace information.
// hash (in hex format) or denom (full denom with ibc prefix) of the denomination trace information.
string hash = 1;
}

Expand Down