Skip to content

Commit

Permalink
feat: query host chain msg events via cli (#782)
Browse files Browse the repository at this point in the history
* WIP implementation

* removing grpc query

* update long usage

* removing buf.yaml updates

* use limit of 1

* adding channel id validation to short circuit with invalid ids
  • Loading branch information
damiannolan authored Jan 24, 2022
1 parent e19623f commit d7bf2a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/apps/27-interchain-accounts/host/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func GetQueryCmd() *cobra.Command {

queryCmd.AddCommand(
GetCmdParams(),
GetCmdPacketEvents(),
)

return queryCmd
Expand Down
56 changes: 56 additions & 0 deletions modules/apps/27-interchain-accounts/host/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package cli

import (
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
)

// GetCmdParams returns the command handler for the host submodule parameter querying.
Expand Down Expand Up @@ -39,3 +46,52 @@ func GetCmdParams() *cobra.Command {

return cmd
}

// GetCmdPacketEvents returns the command handler for the host packet events querying.
func GetCmdPacketEvents() *cobra.Command {
cmd := &cobra.Command{
Use: "packet-events [channel-id] [sequence]",
Short: "Query the interchain-accounts host submodule packet events",
Long: "Query the interchain-accounts host submodule packet events for a particular channel and sequence",
Args: cobra.ExactArgs(2),
Example: fmt.Sprintf("%s query interchain-accounts host packet-events channel-0 100", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

channelID, portID := args[0], icatypes.PortID
if err := host.ChannelIdentifierValidator(channelID); err != nil {
return err
}

seq, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

searchEvents := []string{
fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstChannel, channelID),
fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstPort, portID),
fmt.Sprintf("%s.%s='%d'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeySequence, seq),
}

result, err := tx.QueryTxsByEvents(clientCtx, searchEvents, 1, 1, "")
if err != nil {
return err
}

var resEvents []abci.Event
for _, r := range result.Txs {
resEvents = append(resEvents, r.Events...)
}

return clientCtx.PrintString(sdk.StringifyEvents(resEvents).String())
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion third_party/proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ lint:
- proofs.proto # confio/ics23
- gogoproto
- google
- tendermint
- tendermint

0 comments on commit d7bf2a8

Please sign in to comment.