11package cli
22
33import (
4+ "context"
5+ "fmt"
6+ "strings"
7+
8+ "github.com/cosmos/ibc-go/v10/modules/apps/rate-limiting/types"
49 "github.com/spf13/cobra"
510
611 "github.com/cosmos/cosmos-sdk/client"
12+ "github.com/cosmos/cosmos-sdk/client/flags"
13+ "github.com/cosmos/cosmos-sdk/version"
14+ )
715
8- "github.com/cosmos/ibc-go/v10/modules/apps/rate-limiting/types"
16+ const (
17+ FlagDenom = "denom"
918)
1019
11- // GetQueryCmd returns the CLI query commands for the rate-limiting module
20+ // GetQueryCmd returns the cli query commands for this module.
1221func GetQueryCmd () * cobra.Command {
13- queryCmd := & cobra.Command {
22+ // Group ratelimit queries under a subcommand
23+ cmd := & cobra.Command {
1424 Use : types .ModuleName ,
15- Short : "Querying commands for the rate-limiting module" ,
25+ Short : fmt . Sprintf ( "Querying commands for the %s module" , types . ModuleName ) ,
1626 DisableFlagParsing : true ,
1727 SuggestionsMinimumDistance : 2 ,
1828 RunE : client .ValidateCmd ,
1929 }
2030
21- // Add query commands here when defined
22- // Example:
23- // queryCmd.AddCommand(
24- // GetCmdQueryRateLimit(),
25- // GetCmdQueryParams(),
26- // )
27-
28- return queryCmd
31+ cmd .AddCommand (
32+ GetCmdQueryRateLimit (),
33+ GetCmdQueryAllRateLimits (),
34+ GetCmdQueryRateLimitsByChainId (),
35+ GetCmdQueryAllBlacklistedDenoms (), // Add Blacklisted Denoms query
36+ GetCmdQueryAllWhitelistedAddresses (), // Add Whitelisted Addresses query
37+ // TODO: Add GetCmdQueryParams if needed
38+ )
39+ return cmd
2940}
3041
31- // Example query command structure to be implemented
32- /*
33- // GetCmdQueryRateLimit returns the command to query a rate limit
42+ // GetCmdQueryRateLimit implements a command to query rate limits by channel-id or client-id and denom
3443func GetCmdQueryRateLimit () * cobra.Command {
3544 cmd := & cobra.Command {
36- Use: "rate-limit [channel-id] [denom]",
37- Short: "Query a rate limit for a specific channel and denomination",
38- Args: cobra.ExactArgs(2),
45+ Use : "rate-limit [channel-or-client-id]" ,
46+ Short : "Query rate limits by channel-id/client-id and denom" ,
47+ Long : strings .TrimSpace (
48+ fmt .Sprintf (`Query rate limits by channel-id/client-id and denom.
49+ If the denom flag is omitted, all rate limits for the given channel-id/client-id are returned.
50+
51+ Example:
52+ $ %s query %s rate-limit [channel-or-client-id]
53+ $ %s query %s rate-limit [channel-or-client-id] --denom=[denom]
54+ ` ,
55+ version .AppName , types .ModuleName , version .AppName , types .ModuleName ,
56+ ),
57+ ),
58+ Args : cobra .ExactArgs (1 ),
3959 RunE : func (cmd * cobra.Command , args []string ) error {
60+ channelOrClientId := args [0 ]
61+ denom , err := cmd .Flags ().GetString (FlagDenom )
62+ if err != nil {
63+ return err
64+ }
65+
4066 clientCtx , err := client .GetClientQueryContext (cmd )
4167 if err != nil {
4268 return err
4369 }
4470 queryClient := types .NewQueryClient (clientCtx )
4571
46- channelID := args[0]
47- denom := args[1]
72+ if denom == "" {
73+ // Query all rate limits for the channel/client ID if denom is not specified
74+ req := & types.QueryRateLimitsByChannelOrClientIdRequest {
75+ ChannelOrClientId : channelOrClientId ,
76+ }
77+ res , err := queryClient .RateLimitsByChannelOrClientId (context .Background (), req )
78+ if err != nil {
79+ return err
80+ }
81+ // Use PrintProto for slice types as PrintObjectLegacy might not work well
82+ return clientCtx .PrintProto (res )
83+ }
4884
85+ // Query specific rate limit if denom is provided
4986 req := & types.QueryRateLimitRequest {
50- ChannelId: channelID,
51- Denom: denom,
87+ Denom : denom ,
88+ ChannelOrClientId : channelOrClientId ,
89+ }
90+ res , err := queryClient .RateLimit (context .Background (), req )
91+ if err != nil {
92+ return err
93+ }
94+
95+ return clientCtx .PrintProto (res .RateLimit )
96+ },
97+ }
98+
99+ cmd .Flags ().String (FlagDenom , "" , "The denom identifying a specific rate limit" )
100+ flags .AddQueryFlagsToCmd (cmd )
101+
102+ return cmd
103+ }
104+
105+ // GetCmdQueryAllRateLimits return all available rate limits.
106+ func GetCmdQueryAllRateLimits () * cobra.Command {
107+ cmd := & cobra.Command {
108+ Use : "list-rate-limits" ,
109+ Short : "Query all rate limits" ,
110+ Args : cobra .NoArgs ,
111+ RunE : func (cmd * cobra.Command , args []string ) error {
112+ clientCtx , err := client .GetClientQueryContext (cmd )
113+ if err != nil {
114+ return err
115+ }
116+ queryClient := types .NewQueryClient (clientCtx )
117+
118+ req := & types.QueryAllRateLimitsRequest {}
119+ res , err := queryClient .AllRateLimits (context .Background (), req )
120+ if err != nil {
121+ return err
122+ }
123+
124+ return clientCtx .PrintProto (res )
125+ },
126+ }
127+
128+ flags .AddQueryFlagsToCmd (cmd )
129+
130+ return cmd
131+ }
132+
133+ // GetCmdQueryRateLimitsByChainId return all rate limits that exist between this chain
134+ // and the specified ChainId
135+ func GetCmdQueryRateLimitsByChainId () * cobra.Command {
136+ cmd := & cobra.Command {
137+ Use : "rate-limits-by-chain [chain-id]" ,
138+ Short : "Query all rate limits associated with the channels/clients connecting to the given ChainID" ,
139+ Args : cobra .ExactArgs (1 ),
140+ RunE : func (cmd * cobra.Command , args []string ) error {
141+ chainId := args [0 ]
142+
143+ clientCtx , err := client .GetClientQueryContext (cmd )
144+ if err != nil {
145+ return err
52146 }
147+ queryClient := types .NewQueryClient (clientCtx )
53148
54- res, err := queryClient.RateLimit(cmd.Context(), req)
149+ req := & types.QueryRateLimitsByChainIdRequest {
150+ ChainId : chainId ,
151+ }
152+ res , err := queryClient .RateLimitsByChainId (context .Background (), req )
55153 if err != nil {
56154 return err
57155 }
@@ -61,14 +159,15 @@ func GetCmdQueryRateLimit() *cobra.Command {
61159 }
62160
63161 flags .AddQueryFlagsToCmd (cmd )
162+
64163 return cmd
65164}
66165
67- // GetCmdQueryParams returns the command to query the module parameters
68- func GetCmdQueryParams () *cobra.Command {
166+ // GetCmdQueryAllBlacklistedDenoms returns the command to query all blacklisted denoms
167+ func GetCmdQueryAllBlacklistedDenoms () * cobra.Command {
69168 cmd := & cobra.Command {
70- Use: "params ",
71- Short: "Query the current rate-limiting module parameters ",
169+ Use : "list-blacklisted-denoms " ,
170+ Short : "Query all blacklisted denoms " ,
72171 Args : cobra .NoArgs ,
73172 RunE : func (cmd * cobra.Command , args []string ) error {
74173 clientCtx , err := client .GetClientQueryContext (cmd )
@@ -77,7 +176,8 @@ func GetCmdQueryParams() *cobra.Command {
77176 }
78177 queryClient := types .NewQueryClient (clientCtx )
79178
80- res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
179+ req := & types.QueryAllBlacklistedDenomsRequest {}
180+ res , err := queryClient .AllBlacklistedDenoms (context .Background (), req )
81181 if err != nil {
82182 return err
83183 }
@@ -89,4 +189,30 @@ func GetCmdQueryParams() *cobra.Command {
89189 flags .AddQueryFlagsToCmd (cmd )
90190 return cmd
91191}
92- */
192+
193+ // GetCmdQueryAllWhitelistedAddresses returns the command to query all whitelisted address pairs
194+ func GetCmdQueryAllWhitelistedAddresses () * cobra.Command {
195+ cmd := & cobra.Command {
196+ Use : "list-whitelisted-addresses" ,
197+ Short : "Query all whitelisted address pairs" ,
198+ Args : cobra .NoArgs ,
199+ RunE : func (cmd * cobra.Command , args []string ) error {
200+ clientCtx , err := client .GetClientQueryContext (cmd )
201+ if err != nil {
202+ return err
203+ }
204+ queryClient := types .NewQueryClient (clientCtx )
205+
206+ req := & types.QueryAllWhitelistedAddressesRequest {}
207+ res , err := queryClient .AllWhitelistedAddresses (context .Background (), req )
208+ if err != nil {
209+ return err
210+ }
211+
212+ return clientCtx .PrintProto (res )
213+ },
214+ }
215+
216+ flags .AddQueryFlagsToCmd (cmd )
217+ return cmd
218+ }
0 commit comments