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: query host chain msg events via cli #782

Merged
merged 9 commits into from
Jan 24, 2022
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
Copy link
Member Author

@damiannolan damiannolan Jan 21, 2022

Choose a reason for hiding this comment

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

I think this appeared as a result of #781 where I made the changes here and reverted them. Not sure why this is flagged by the GH diff