@@ -2,13 +2,20 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
5
6
6
7
"github.com/cosmos/cosmos-sdk/client"
7
8
"github.com/cosmos/cosmos-sdk/client/flags"
9
+ sdk "github.com/cosmos/cosmos-sdk/types"
8
10
"github.com/cosmos/cosmos-sdk/version"
11
+ "github.com/cosmos/cosmos-sdk/x/auth/tx"
9
12
"github.com/spf13/cobra"
13
+ abci "github.com/tendermint/tendermint/abci/types"
10
14
11
15
"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"
12
19
)
13
20
14
21
// GetCmdParams returns the command handler for the host submodule parameter querying.
@@ -39,3 +46,52 @@ func GetCmdParams() *cobra.Command {
39
46
40
47
return cmd
41
48
}
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
+ }
0 commit comments