From d7bf2a8b3c8e9b16a38dc6647faf27da8e6b0e24 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 24 Jan 2022 17:01:05 +0100 Subject: [PATCH] feat: query host chain msg events via cli (#782) * 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 --- .../host/client/cli/cli.go | 1 + .../host/client/cli/query.go | 56 +++++++++++++++++++ third_party/proto/buf.yaml | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/client/cli/cli.go b/modules/apps/27-interchain-accounts/host/client/cli/cli.go index 9d88f4cba21..2ae88a48b70 100644 --- a/modules/apps/27-interchain-accounts/host/client/cli/cli.go +++ b/modules/apps/27-interchain-accounts/host/client/cli/cli.go @@ -15,6 +15,7 @@ func GetQueryCmd() *cobra.Command { queryCmd.AddCommand( GetCmdParams(), + GetCmdPacketEvents(), ) return queryCmd diff --git a/modules/apps/27-interchain-accounts/host/client/cli/query.go b/modules/apps/27-interchain-accounts/host/client/cli/query.go index bb4e315ca06..c35e03baa16 100644 --- a/modules/apps/27-interchain-accounts/host/client/cli/query.go +++ b/modules/apps/27-interchain-accounts/host/client/cli/query.go @@ -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. @@ -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 +} diff --git a/third_party/proto/buf.yaml b/third_party/proto/buf.yaml index 8ab26336f50..b111c46ba08 100644 --- a/third_party/proto/buf.yaml +++ b/third_party/proto/buf.yaml @@ -30,4 +30,4 @@ lint: - proofs.proto # confio/ics23 - gogoproto - google - - tendermint + - tendermint \ No newline at end of file