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

feat: add the ability to query the hash associated with an IBC denom trace #1436

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func queryCmd(a *appState) *cobra.Command {
queryIBCDenoms(a),
queryBaseDenomFromIBCDenom(a),
feegrantQueryCmd(a),
queryIBCDenomHash(a),
)

return cmd
Expand Down Expand Up @@ -123,6 +124,7 @@ $ %s q denom-trace osmosis 9BBA9A1C257E971E38C1422780CE6F0B0686F0A3085E2D61118D9
if !ok {
return errChainNotFound(args[0])
}

res, err := c.ChainProvider.QueryDenomTrace(cmd.Context(), args[1])
if err != nil {
return err
Expand All @@ -136,6 +138,35 @@ $ %s q denom-trace osmosis 9BBA9A1C257E971E38C1422780CE6F0B0686F0A3085E2D61118D9
return cmd
}

func queryIBCDenomHash(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "denom-hash chain_id trace",
Short: "query the denom hash info from a given denom trace",
Args: withUsage(cobra.ExactArgs(2)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s query denom-hash osmosis transfer/channel-0/uatom
Copy link
Member

Choose a reason for hiding this comment

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

TIL this is the IBC denom trace and than you can take this and convert to the hash. Cool!

$ %s q denom-hash osmosis transfer/channel-0/uatom`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
c, ok := a.config.Chains[args[0]]
if !ok {
return errChainNotFound(args[0])
}

res, err := c.ChainProvider.QueryDenomHash(cmd.Context(), args[1])
if err != nil {
return err
}

fmt.Fprintln(cmd.OutOrStdout(), res)
return nil
},
}
cmd = addOutputFlag(a.viper, cmd)
return cmd
}

func queryTx(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "tx chain_name tx_hash",
Expand Down
16 changes: 16 additions & 0 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ func (cc *CosmosProvider) QueryDenomTrace(ctx context.Context, denom string) (*t
if err != nil {
return nil, err
}

return transfers.DenomTrace, nil
}

Expand Down Expand Up @@ -1245,6 +1246,21 @@ func (cc *CosmosProvider) QueryDenomTraces(ctx context.Context, offset, limit ui
return transfers, nil
}

func (cc *CosmosProvider) QueryDenomHash(ctx context.Context, trace string) (string, error) {
qc := transfertypes.NewQueryClient(cc)

req := &transfertypes.QueryDenomHashRequest{
Trace: trace,
}

resp, err := qc.DenomHash(ctx, req, nil)
if err != nil {
return "", err
}

return resp.Hash, nil
}

func (cc *CosmosProvider) QueryStakingParams(ctx context.Context) (*stakingtypes.Params, error) {
res, err := stakingtypes.NewQueryClient(cc).Params(ctx, &stakingtypes.QueryParamsRequest{})
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions relayer/chains/penumbra/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ func (cc *PenumbraProvider) QueryDenomTraces(ctx context.Context, offset, limit
return transfers.DenomTraces, nil
}

func (cc *PenumbraProvider) QueryDenomHash(ctx context.Context, trace string) (string, error) {
panic("not implemented")
}

func (cc *PenumbraProvider) QueryStakingParams(ctx context.Context) (*stakingtypes.Params, error) {
res, err := stakingtypes.NewQueryClient(cc).Params(ctx, &stakingtypes.QueryParamsRequest{})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ type QueryProvider interface {
// ics 20 - transfer
QueryDenomTrace(ctx context.Context, denom string) (*transfertypes.DenomTrace, error)
QueryDenomTraces(ctx context.Context, offset, limit uint64, height int64) ([]transfertypes.DenomTrace, error)
QueryDenomHash(ctx context.Context, trace string) (string, error)
}

type RelayPacket interface {
Expand Down
Loading