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: Change Query/DenomTrace gRPC #1312

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ paths:
format: boolean
tags:
- Query
'/ibc/apps/transfer/v1/denom_traces/{hash}':
'/ibc/apps/transfer/v1/denom_traces/{denom}':
get:
summary: DenomTrace queries a denomination trace information.
operationId: DenomTrace
Expand Down Expand Up @@ -234,7 +234,7 @@ paths:
type: string
format: byte
parameters:
- name: hash
- name: denom
description: hash (in hex format) of the denomination trace information.
in: path
required: true
Expand Down
4 changes: 2 additions & 2 deletions 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. |
| `denom` | [string](#string) | | hash (in hex format) of the denomination trace information. |



Expand Down Expand Up @@ -1957,7 +1957,7 @@ Query provides defines the gRPC querier service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `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}|
| `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/{denom}|
| `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|
| `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|
| `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}|
Expand Down
12 changes: 6 additions & 6 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 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 [denom]",
Short: "Query the denom trace info from a denom",
Long: "Query the denom trace info from a denom",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [denom]", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -27,7 +27,7 @@ func GetCmdQueryDenomTrace() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryDenomTraceRequest{
Hash: args[0],
Denom: args[0],
}

res, err := queryClient.DenomTrace(cmd.Context(), req)
Expand Down
11 changes: 8 additions & 3 deletions modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,17 +23,21 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
return nil, status.Error(codes.InvalidArgument, "empty request")
}

hash, err := types.ParseHexHash(req.Hash)
if !strings.HasPrefix(req.Denom, "ibc/") {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom with no ibc prefix %s", req.Denom))
}

hash, err := types.ParseHexHash(req.Denom[4:])
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, %s", req.Denom[4:], err))
}

ctx := sdk.UnwrapSDKContext(c)
denomTrace, found := q.GetDenomTrace(ctx, hash)
if !found {
return nil, status.Error(
codes.NotFound,
sdkerrors.Wrap(types.ErrTraceNotFound, req.Hash).Error(),
sdkerrors.Wrap(types.ErrTraceNotFound, req.Denom).Error(),
)
}

Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
expPass bool
}{
{
"invalid hex hash",
"invalid ibc denom",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we put the success case first? :=)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss

func() {
req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
Denom: "!@#!@#!",
}
},
false,
Expand All @@ -35,7 +35,7 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
Denom: expTrace.IBCDenom(),
}
},
false,
Expand All @@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
Denom: expTrace.IBCDenom(),
}
},
true,
Expand Down
95 changes: 47 additions & 48 deletions modules/apps/transfer/types/query.pb.go

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

18 changes: 9 additions & 9 deletions modules/apps/transfer/types/query.pb.gw.go

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

4 changes: 2 additions & 2 deletions proto/ibc/applications/transfer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option go_package = "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types";
service Query {
// DenomTrace queries a denomination trace information.
rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) {
option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash}";
option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{denom}";
}

// DenomTraces queries all denomination traces.
Expand All @@ -36,7 +36,7 @@ service Query {
// method
message QueryDenomTraceRequest {
// hash (in hex format) of the denomination trace information.
string hash = 1;
string denom = 1;
}

// QueryDenomTraceResponse is the response type for the Query/DenomTrace RPC
Expand Down