Skip to content

Commit e55bfd9

Browse files
nir1218mergify-bot
authored and
mergify-bot
committed
add cli to get denom hash from trace path and base denom (#679)
* get denom hash from denom trace * revert .gitignore * final revert * ignore history files * Update modules/apps/transfer/client/cli/query.go Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * Update modules/apps/transfer/keeper/grpc_query.go Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * Update modules/apps/transfer/keeper/keeper.go Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * Update modules/apps/transfer/keeper/grpc_query.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * code review feedback integration * moved new feature to unreleased section * fix duplicate block in success test case * fix CHANGELOG format * fix invalid trace path argument error handling * refactor positive test case code Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> (cherry picked from commit cb9bf5d) # Conflicts: # CHANGELOG.md # modules/apps/transfer/types/query.pb.go
1 parent df58b8e commit e55bfd9

File tree

11 files changed

+830
-0
lines changed

11 files changed

+830
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ dependency-graph.png
5252
*.aux
5353
*.out
5454
*.synctex.gz
55+
56+
*.history
57+

CHANGELOG.md

+56
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,62 @@ Ref: https://keepachangelog.com/en/1.0.0/
3939
### Improvements
4040

4141
* (channel) [\#692](https://github.com/cosmos/ibc-go/pull/692) Minimize channel logging by only emitting the packet sequence, source port/channel, destination port/channel upon packet receives, acknowledgements and timeouts.
42+
<<<<<<< HEAD
43+
=======
44+
* [\#383](https://github.com/cosmos/ibc-go/pull/383) Adds helper functions for merging and splitting middleware versions from the underlying app version.
45+
* (modules/core/05-port) [\#288](https://github.com/cosmos/ibc-go/issues/288) Making the 05-port keeper function IsBound public. The IsBound function checks if the provided portID is already binded to a module.
46+
* (channel) [\#644](https://github.com/cosmos/ibc-go/pull/644) Adds `GetChannelConnection` to the ChannelKeeper. This function returns the connectionID and connection state associated with a channel.
47+
* (channel) [\647](https://github.com/cosmos/ibc-go/pull/647) Reorganizes channel handshake handling to set channel state after IBC application callbacks.
48+
49+
### Features
50+
51+
* [\#432](https://github.com/cosmos/ibc-go/pull/432) Introduce `MockIBCApp` struct to the mock module. Allows the mock module to be reused to perform custom logic on each IBC App interface function. This might be useful when testing out IBC applications written as middleware.
52+
* [\#380](https://github.com/cosmos/ibc-go/pull/380) Adding the Interchain Accounts module v1
53+
* [\#679](https://github.com/cosmos/ibc-go/pull/679) New CLI command `query ibc-transfer denom-hash <denom trace>` to get the denom hash for a denom trace; this might be useful for debug
54+
55+
### Bug Fixes
56+
57+
## [v2.0.2](https://github.com/cosmos/ibc-go/releases/tag/v2.0.2) - 2021-12-15
58+
59+
### Dependencies
60+
61+
* [\#589](https://github.com/cosmos/ibc-go/pull/589) Bump SDK version to v0.44.5
62+
63+
### Bug Fixes
64+
65+
* (modules/core) [\#603](https://github.com/cosmos/ibc-go/pull/603) Fix module name emitted as part of `OnChanOpenInit` event. Replacing `connection` module name with `channel`.
66+
67+
## [v2.0.1](https://github.com/cosmos/ibc-go/releases/tag/v2.0.1) - 2021-12-05
68+
69+
### Dependencies
70+
71+
* [\#567](https://github.com/cosmos/ibc-go/pull/567) Bump SDK version to v0.44.4
72+
73+
### Improvements
74+
75+
* (02-client) [\#568](https://github.com/cosmos/ibc-go/pull/568) In IBC `transfer` cli command use local clock time as reference for relative timestamp timeout if greater than the block timestamp queried from the latest consensus state corresponding to the counterparty channel.
76+
* [\#583](https://github.com/cosmos/ibc-go/pull/583) Move third_party/proto/confio/proofs.proto to third_party/proto/proofs.proto to enable proto service reflection. Migrate `buf` from v1beta1 to v1.
77+
78+
### Bug Fixes
79+
80+
* (02-client) [\#500](https://github.com/cosmos/ibc-go/pull/500) Fix IBC `update-client proposal` cli command to expect correct number of args.
81+
82+
## [v2.0.0](https://github.com/cosmos/ibc-go/releases/tag/v2.0.0) - 2021-11-09
83+
84+
### Dependencies
85+
86+
* [\#489](https://github.com/cosmos/ibc-go/pull/489) Bump Tendermint to v0.34.14
87+
* [\#503](https://github.com/cosmos/ibc-go/pull/503) Bump SDK version to v0.44.3
88+
89+
### API Breaking
90+
91+
* (core) [\#227](https://github.com/cosmos/ibc-go/pull/227) Remove sdk.Result from application callbacks
92+
* (transfer) [\#350](https://github.com/cosmos/ibc-go/pull/350) Change FungibleTokenPacketData to use a string for the Amount field. This enables token transfers with amounts previously restricted by uint64. Up to the maximum uint256 value is supported.
93+
94+
### Features
95+
96+
* [\#384](https://github.com/cosmos/ibc-go/pull/384) Added `NegotiateAppVersion` method to `IBCModule` interface supported by a gRPC query service in `05-port`. This provides routing of requests to the desired application module callback, which in turn performs application version negotiation.
97+
>>>>>>> cb9bf5d (add cli to get denom hash from trace path and base denom (#679))
4298
4399
## [v1.2.5](https://github.com/cosmos/ibc-go/releases/tag/v1.2.5) - 2021-12-15
44100

docs/client/swagger-ui/swagger.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,54 @@ info:
44
description: A REST interface for state queries
55
version: 1.0.0
66
paths:
7+
'/ibc/apps/transfer/v1/denom_hashes/{trace}':
8+
get:
9+
summary: DenomHash queries a denomination hash information.
10+
operationId: DenomHash
11+
responses:
12+
'200':
13+
description: A successful response.
14+
schema:
15+
type: object
16+
properties:
17+
hash:
18+
type: string
19+
description: hash (in hex format) of the denomination trace information.
20+
description: >-
21+
QueryDenomHashResponse is the response type for the
22+
Query/DenomHash RPC
23+
24+
method.
25+
default:
26+
description: An unexpected error response
27+
schema:
28+
type: object
29+
properties:
30+
error:
31+
type: string
32+
code:
33+
type: integer
34+
format: int32
35+
message:
36+
type: string
37+
details:
38+
type: array
39+
items:
40+
type: object
41+
properties:
42+
type_url:
43+
type: string
44+
value:
45+
type: string
46+
format: byte
47+
parameters:
48+
- name: trace
49+
description: 'The denomination trace ([port_id]/[channel_id])+/[denom]'
50+
in: path
51+
required: true
52+
type: string
53+
tags:
54+
- Query
755
/ibc/apps/transfer/v1/denom_traces:
856
get:
957
summary: DenomTraces queries all denomination traces.
@@ -7326,6 +7374,15 @@ paths:
73267374
required: false
73277375
type: boolean
73287376
format: boolean
7377+
- name: packet_commitment_sequences
7378+
description: list of packet sequences.
7379+
in: query
7380+
required: false
7381+
type: array
7382+
items:
7383+
type: string
7384+
format: uint64
7385+
collectionFormat: multi
73297386
tags:
73307387
- Query
73317388
'/ibc/core/channel/v1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}':
@@ -9839,6 +9896,15 @@ definitions:
98399896
SendEnabled
98409897
98419898
parameter for the denomination to false.
9899+
ibc.applications.transfer.v1.QueryDenomHashResponse:
9900+
type: object
9901+
properties:
9902+
hash:
9903+
type: string
9904+
description: hash (in hex format) of the denomination trace information.
9905+
description: |-
9906+
QueryDenomHashResponse is the response type for the Query/DenomHash RPC
9907+
method.
98429908
ibc.applications.transfer.v1.QueryDenomTraceResponse:
98439909
type: object
98449910
properties:

docs/ibc/proto-docs.md

+35
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [GenesisState](#ibc.applications.transfer.v1.GenesisState)
1414

1515
- [ibc/applications/transfer/v1/query.proto](#ibc/applications/transfer/v1/query.proto)
16+
- [QueryDenomHashRequest](#ibc.applications.transfer.v1.QueryDenomHashRequest)
17+
- [QueryDenomHashResponse](#ibc.applications.transfer.v1.QueryDenomHashResponse)
1618
- [QueryDenomTraceRequest](#ibc.applications.transfer.v1.QueryDenomTraceRequest)
1719
- [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse)
1820
- [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest)
@@ -358,6 +360,38 @@ GenesisState defines the ibc-transfer genesis state
358360

359361

360362

363+
<a name="ibc.applications.transfer.v1.QueryDenomHashRequest"></a>
364+
365+
### QueryDenomHashRequest
366+
QueryDenomHashRequest is the request type for the Query/DenomHash RPC
367+
method
368+
369+
370+
| Field | Type | Label | Description |
371+
| ----- | ---- | ----- | ----------- |
372+
| `trace` | [string](#string) | | The denomination trace ([port_id]/[channel_id])+/[denom] |
373+
374+
375+
376+
377+
378+
379+
<a name="ibc.applications.transfer.v1.QueryDenomHashResponse"></a>
380+
381+
### QueryDenomHashResponse
382+
QueryDenomHashResponse is the response type for the Query/DenomHash RPC
383+
method.
384+
385+
386+
| Field | Type | Label | Description |
387+
| ----- | ---- | ----- | ----------- |
388+
| `hash` | [string](#string) | | hash (in hex format) of the denomination trace information. |
389+
390+
391+
392+
393+
394+
361395
<a name="ibc.applications.transfer.v1.QueryDenomTraceRequest"></a>
362396

363397
### QueryDenomTraceRequest
@@ -464,6 +498,7 @@ Query provides defines the gRPC querier service.
464498
| `DenomTrace` | [QueryDenomTraceRequest](#ibc.applications.transfer.v1.QueryDenomTraceRequest) | [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse) | DenomTrace queries a denomination trace information. | GET|/ibc/apps/transfer/v1/denom_traces/{hash}|
465499
| `DenomTraces` | [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest) | [QueryDenomTracesResponse](#ibc.applications.transfer.v1.QueryDenomTracesResponse) | DenomTraces queries all denomination traces. | GET|/ibc/apps/transfer/v1/denom_traces|
466500
| `Params` | [QueryParamsRequest](#ibc.applications.transfer.v1.QueryParamsRequest) | [QueryParamsResponse](#ibc.applications.transfer.v1.QueryParamsResponse) | Params queries all parameters of the ibc-transfer module. | GET|/ibc/apps/transfer/v1/params|
501+
| `DenomHash` | [QueryDenomHashRequest](#ibc.applications.transfer.v1.QueryDenomHashRequest) | [QueryDenomHashResponse](#ibc.applications.transfer.v1.QueryDenomHashResponse) | DenomHash queries a denomination hash information. | GET|/ibc/apps/transfer/v1/denom_hashes/{trace}|
467502

468503
<!-- end services -->
469504

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func GetQueryCmd() *cobra.Command {
2020
GetCmdQueryDenomTraces(),
2121
GetCmdParams(),
2222
GetCmdQueryEscrowAddress(),
23+
GetCmdQueryDenomHash(),
2324
)
2425

2526
return queryCmd

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

+32
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,35 @@ func GetCmdQueryEscrowAddress() *cobra.Command {
131131

132132
return cmd
133133
}
134+
135+
// GetCmdQueryDenomHash defines the command to query a denomination hash from a given trace.
136+
func GetCmdQueryDenomHash() *cobra.Command {
137+
cmd := &cobra.Command{
138+
Use: "denom-hash [trace]",
139+
Short: "Query the denom hash info from a given denom trace",
140+
Long: "Query the denom hash info from a given denom trace",
141+
Example: fmt.Sprintf("%s query ibc-transfer denom-hash [denom_trace]", version.AppName),
142+
Args: cobra.ExactArgs(1),
143+
RunE: func(cmd *cobra.Command, args []string) error {
144+
clientCtx, err := client.GetClientQueryContext(cmd)
145+
if err != nil {
146+
return err
147+
}
148+
queryClient := types.NewQueryClient(clientCtx)
149+
150+
req := &types.QueryDenomHashRequest{
151+
Trace: args[0],
152+
}
153+
154+
res, err := queryClient.DenomHash(cmd.Context(), req)
155+
if err != nil {
156+
return err
157+
}
158+
159+
return clientCtx.PrintProto(res)
160+
},
161+
}
162+
163+
flags.AddQueryFlagsToCmd(cmd)
164+
return cmd
165+
}

modules/apps/transfer/keeper/grpc_query.go

+27
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,30 @@ func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q
8181
Params: &params,
8282
}, nil
8383
}
84+
85+
// DenomHash implements the Query/DenomHash gRPC method
86+
func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) {
87+
if req == nil {
88+
return nil, status.Error(codes.InvalidArgument, "empty request")
89+
}
90+
91+
// Convert given request trace path to DenomTrace struct to confirm the path in a valid denom trace format
92+
denomTrace := types.ParseDenomTrace(req.Trace)
93+
if err := denomTrace.Validate(); err != nil {
94+
return nil, status.Error(codes.InvalidArgument, err.Error())
95+
}
96+
97+
ctx := sdk.UnwrapSDKContext(c)
98+
denomHash := denomTrace.Hash()
99+
found := q.HasDenomTrace(ctx, denomHash)
100+
if !found {
101+
return nil, status.Error(
102+
codes.NotFound,
103+
sdkerrors.Wrap(types.ErrTraceNotFound, req.Trace).Error(),
104+
)
105+
}
106+
107+
return &types.QueryDenomHashResponse{
108+
Hash: denomHash.String(),
109+
}, nil
110+
}

modules/apps/transfer/keeper/grpc_query_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,70 @@ func (suite *KeeperTestSuite) TestQueryParams() {
140140
res, _ := suite.queryClient.Params(ctx, &types.QueryParamsRequest{})
141141
suite.Require().Equal(&expParams, res.Params)
142142
}
143+
144+
func (suite *KeeperTestSuite) TestQueryDenomHash() {
145+
146+
reqTrace := types.DenomTrace{
147+
Path: "transfer/channelToA/transfer/channelToB",
148+
BaseDenom: "uatom",
149+
}
150+
151+
var (
152+
req *types.QueryDenomHashRequest
153+
expHash = reqTrace.Hash().String()
154+
)
155+
156+
testCases := []struct {
157+
msg string
158+
malleate func()
159+
expPass bool
160+
}{
161+
{
162+
"invalid trace",
163+
func() {
164+
req = &types.QueryDenomHashRequest{
165+
Trace: "transfer/channelToA/transfer/",
166+
}
167+
},
168+
false,
169+
},
170+
{
171+
"not found denom trace",
172+
func() {
173+
req = &types.QueryDenomHashRequest{
174+
Trace: "transfer/channelToC/uatom",
175+
}
176+
},
177+
false,
178+
},
179+
{
180+
"success",
181+
func() {},
182+
true,
183+
},
184+
}
185+
186+
for _, tc := range testCases {
187+
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
188+
suite.SetupTest() // reset
189+
190+
req = &types.QueryDenomHashRequest{
191+
Trace: reqTrace.GetFullDenomPath(),
192+
}
193+
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), reqTrace)
194+
195+
tc.malleate()
196+
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
197+
198+
res, err := suite.queryClient.DenomHash(ctx, req)
199+
200+
if tc.expPass {
201+
suite.Require().NoError(err)
202+
suite.Require().NotNil(res)
203+
suite.Require().Equal(expHash, res.Hash)
204+
} else {
205+
suite.Require().Error(err)
206+
}
207+
})
208+
}
209+
}

0 commit comments

Comments
 (0)