Skip to content

Commit d7bf2a8

Browse files
authored
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
1 parent e19623f commit d7bf2a8

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

modules/apps/27-interchain-accounts/host/client/cli/cli.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func GetQueryCmd() *cobra.Command {
1515

1616
queryCmd.AddCommand(
1717
GetCmdParams(),
18+
GetCmdPacketEvents(),
1819
)
1920

2021
return queryCmd

modules/apps/27-interchain-accounts/host/client/cli/query.go

+56
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ package cli
22

33
import (
44
"fmt"
5+
"strconv"
56

67
"github.com/cosmos/cosmos-sdk/client"
78
"github.com/cosmos/cosmos-sdk/client/flags"
9+
sdk "github.com/cosmos/cosmos-sdk/types"
810
"github.com/cosmos/cosmos-sdk/version"
11+
"github.com/cosmos/cosmos-sdk/x/auth/tx"
912
"github.com/spf13/cobra"
13+
abci "github.com/tendermint/tendermint/abci/types"
1014

1115
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
16+
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
17+
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
18+
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
1219
)
1320

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

4047
return cmd
4148
}
49+
50+
// GetCmdPacketEvents returns the command handler for the host packet events querying.
51+
func GetCmdPacketEvents() *cobra.Command {
52+
cmd := &cobra.Command{
53+
Use: "packet-events [channel-id] [sequence]",
54+
Short: "Query the interchain-accounts host submodule packet events",
55+
Long: "Query the interchain-accounts host submodule packet events for a particular channel and sequence",
56+
Args: cobra.ExactArgs(2),
57+
Example: fmt.Sprintf("%s query interchain-accounts host packet-events channel-0 100", version.AppName),
58+
RunE: func(cmd *cobra.Command, args []string) error {
59+
clientCtx, err := client.GetClientQueryContext(cmd)
60+
if err != nil {
61+
return err
62+
}
63+
64+
channelID, portID := args[0], icatypes.PortID
65+
if err := host.ChannelIdentifierValidator(channelID); err != nil {
66+
return err
67+
}
68+
69+
seq, err := strconv.ParseUint(args[1], 10, 64)
70+
if err != nil {
71+
return err
72+
}
73+
74+
searchEvents := []string{
75+
fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstChannel, channelID),
76+
fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstPort, portID),
77+
fmt.Sprintf("%s.%s='%d'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeySequence, seq),
78+
}
79+
80+
result, err := tx.QueryTxsByEvents(clientCtx, searchEvents, 1, 1, "")
81+
if err != nil {
82+
return err
83+
}
84+
85+
var resEvents []abci.Event
86+
for _, r := range result.Txs {
87+
resEvents = append(resEvents, r.Events...)
88+
}
89+
90+
return clientCtx.PrintString(sdk.StringifyEvents(resEvents).String())
91+
},
92+
}
93+
94+
flags.AddQueryFlagsToCmd(cmd)
95+
96+
return cmd
97+
}

third_party/proto/buf.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ lint:
3030
- proofs.proto # confio/ics23
3131
- gogoproto
3232
- google
33-
- tendermint
33+
- tendermint

0 commit comments

Comments
 (0)