Skip to content

Commit 23e7e7d

Browse files
catShaarkcrodriguezvegadamiannolan
authored
chore: improve DenomTrace grpc (cosmos#1342)
* change DenomTrace grpc * update CHANGELOG.md * minor * minor * minor * minor * minor * minor * Update modules/apps/transfer/keeper/grpc_query_test.go Co-authored-by: Carlos Rodriguez <[email protected]> * Update modules/apps/transfer/keeper/grpc_query_test.go Co-authored-by: Carlos Rodriguez <[email protected]> * Update CHANGELOG.md Co-authored-by: Damian Nolan <[email protected]> * use TrimPrefix() in DenomTrace() * update migration doc Co-authored-by: Carlos Rodriguez <[email protected]> Co-authored-by: Damian Nolan <[email protected]>
1 parent ab8ab42 commit 23e7e7d

File tree

9 files changed

+40
-21
lines changed

9 files changed

+40
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5151

5252
### Improvements
5353

54+
* (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`.
5455
* (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.
5556
* (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.
5657
* (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`.

docs/client/swagger-ui/swagger.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ paths:
235235
format: byte
236236
parameters:
237237
- name: hash
238-
description: hash (in hex format) of the denomination trace information.
238+
description: >-
239+
hash (in hex format) or denom (full denom with ibc prefix) of the
240+
denomination trace information.
239241
in: path
240242
required: true
241243
type: string

docs/ibc/proto-docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ method
18631863

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

18681868

18691869

docs/migrations/v3-to-v4.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ This is an API breaking change and as such IBC application developers will have
2626
The `OnChanOpenInit` application callback has been modified.
2727
The return signature now includes the application version as detailed in the latest IBC [spec changes](https://github.com/cosmos/ibc/pull/629).
2828

29+
## Relayers
2930

30-
31+
When using the `DenomTrace` gRPC, the full IBC denomination with the `ibc/` prefix may now be passed in.

modules/apps/transfer/client/cli/query.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1212
)
1313

14-
// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given hash.
14+
// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given trace hash or ibc denom.
1515
func GetCmdQueryDenomTrace() *cobra.Command {
1616
cmd := &cobra.Command{
17-
Use: "denom-trace [hash]",
18-
Short: "Query the denom trace info from a given trace hash",
19-
Long: "Query the denom trace info from a given trace hash",
20-
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash]", version.AppName),
17+
Use: "denom-trace [hash/denom]",
18+
Short: "Query the denom trace info from a given trace hash or ibc denom",
19+
Long: "Query the denom trace info from a given trace hash or ibc denom",
20+
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash/denom]", version.AppName),
2121
Args: cobra.ExactArgs(1),
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
clientCtx, err := client.GetClientQueryContext(cmd)

modules/apps/transfer/keeper/grpc_query.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/cosmos/cosmos-sdk/store/prefix"
89
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -22,9 +23,10 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
2223
return nil, status.Error(codes.InvalidArgument, "empty request")
2324
}
2425

25-
hash, err := types.ParseHexHash(req.Hash)
26+
hash, err := types.ParseHexHash(strings.TrimPrefix(req.Hash, "ibc/"))
27+
2628
if err != nil {
27-
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash %s, %s", req.Hash, err))
29+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", hash.String(), err))
2830
}
2931

3032
ctx := sdk.UnwrapSDKContext(c)

modules/apps/transfer/keeper/grpc_query_test.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,50 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
2121
expPass bool
2222
}{
2323
{
24-
"invalid hex hash",
24+
"success: correct ibc denom",
2525
func() {
26+
expTrace.Path = "transfer/channelToA/transfer/channelToB"
27+
expTrace.BaseDenom = "uatom"
28+
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)
29+
2630
req = &types.QueryDenomTraceRequest{
27-
Hash: "!@#!@#!",
31+
Hash: expTrace.IBCDenom(),
2832
}
2933
},
30-
false,
34+
true,
3135
},
3236
{
33-
"not found denom trace",
37+
"success: correct hex hash",
3438
func() {
3539
expTrace.Path = "transfer/channelToA/transfer/channelToB"
3640
expTrace.BaseDenom = "uatom"
41+
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)
42+
3743
req = &types.QueryDenomTraceRequest{
3844
Hash: expTrace.Hash().String(),
3945
}
4046
},
47+
true,
48+
},
49+
{
50+
"failure: invalid hash",
51+
func() {
52+
req = &types.QueryDenomTraceRequest{
53+
Hash: "!@#!@#!",
54+
}
55+
},
4156
false,
4257
},
4358
{
44-
"success",
59+
"failure: not found denom trace",
4560
func() {
4661
expTrace.Path = "transfer/channelToA/transfer/channelToB"
4762
expTrace.BaseDenom = "uatom"
48-
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)
49-
5063
req = &types.QueryDenomTraceRequest{
51-
Hash: expTrace.Hash().String(),
64+
Hash: expTrace.IBCDenom(),
5265
}
5366
},
54-
true,
67+
false,
5568
},
5669
}
5770

modules/apps/transfer/types/query.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/ibc/applications/transfer/v1/query.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ service Query {
3535
// QueryDenomTraceRequest is the request type for the Query/DenomTrace RPC
3636
// method
3737
message QueryDenomTraceRequest {
38-
// hash (in hex format) of the denomination trace information.
38+
// hash (in hex format) or denom (full denom with ibc prefix) of the denomination trace information.
3939
string hash = 1;
4040
}
4141

0 commit comments

Comments
 (0)