github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/29-fee/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 "strconv" 6 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 10 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/version" 12 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags" 15 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 16 interfacetypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types" 17 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/29-fee/types" 18 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 19 "github.com/spf13/cobra" 20 ) 21 22 // GetCmdIncentivizedPacket returns the unrelayed incentivized packet for a given packetID 23 func GetCmdIncentivizedPacket(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 24 cmd := &cobra.Command{ 25 Use: "packet [port-id] [channel-id] [sequence]", 26 Short: "Query for an unrelayed incentivized packet by port-id, channel-id and packet sequence.", 27 Long: "Query for an unrelayed incentivized packet by port-id, channel-id and packet sequence.", 28 Args: cobra.ExactArgs(3), 29 Example: fmt.Sprintf("%s query ibc-fee packet", version.ServerName), 30 RunE: func(cmd *cobra.Command, args []string) error { 31 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 32 33 portID, channelID := args[0], args[1] 34 seq, err := strconv.ParseUint(args[2], 10, 64) 35 if err != nil { 36 return err 37 } 38 39 packetID := channeltypes.NewPacketId(portID, channelID, seq) 40 41 if err := packetID.Validate(); err != nil { 42 return err 43 } 44 45 req := &types.QueryIncentivizedPacketRequest{ 46 PacketId: packetID, 47 QueryHeight: uint64(clientCtx.Height), 48 } 49 50 queryClient := types.NewQueryClient(clientCtx) 51 52 res, err := queryClient.IncentivizedPacket(cmd.Context(), req) 53 if err != nil { 54 return err 55 } 56 57 return clientCtx.PrintProto(res) 58 }, 59 } 60 61 flags.AddQueryFlagsToCmd(cmd) 62 63 return cmd 64 } 65 66 // GetCmdIncentivizedPackets returns all of the unrelayed incentivized packets 67 func GetCmdIncentivizedPackets(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 68 cmd := &cobra.Command{ 69 Use: "packets", 70 Short: "Query for all of the unrelayed incentivized packets and associated fees across all channels.", 71 Long: "Query for all of the unrelayed incentivized packets and associated fees across all channels.", 72 Args: cobra.NoArgs, 73 Example: fmt.Sprintf("%s query ibc-fee packets", version.ServerName), 74 RunE: func(cmd *cobra.Command, args []string) error { 75 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 76 77 pageReq, err := client.ReadPageRequest(cmd.Flags()) 78 if err != nil { 79 return err 80 } 81 82 req := &types.QueryIncentivizedPacketsRequest{ 83 Pagination: pageReq, 84 QueryHeight: uint64(clientCtx.Height), 85 } 86 87 queryClient := types.NewQueryClient(clientCtx) 88 89 res, err := queryClient.IncentivizedPackets(cmd.Context(), req) 90 if err != nil { 91 return err 92 } 93 94 return clientCtx.PrintProto(res) 95 }, 96 } 97 98 flags.AddQueryFlagsToCmd(cmd) 99 flags.AddPaginationFlagsToCmd(cmd, "packets") 100 101 return cmd 102 } 103 104 // GetCmdTotalRecvFees returns the command handler for the Query/TotalRecvFees rpc. 105 func GetCmdTotalRecvFees(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 106 cmd := &cobra.Command{ 107 Use: "total-recv-fees [port-id] [channel-id] [sequence]", 108 Short: "Query the total receive fees for a packet", 109 Long: "Query the total receive fees for a packet", 110 Args: cobra.ExactArgs(3), 111 Example: fmt.Sprintf("%s query ibc-fee total-recv-fees transfer channel-5 100", version.ServerName), 112 RunE: func(cmd *cobra.Command, args []string) error { 113 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 114 115 portID, channelID := args[0], args[1] 116 seq, err := strconv.ParseUint(args[2], 10, 64) 117 if err != nil { 118 return err 119 } 120 121 packetID := channeltypes.NewPacketId(portID, channelID, seq) 122 123 if err := packetID.Validate(); err != nil { 124 return err 125 } 126 127 queryClient := types.NewQueryClient(clientCtx) 128 129 req := &types.QueryTotalRecvFeesRequest{ 130 PacketId: packetID, 131 } 132 133 res, err := queryClient.TotalRecvFees(cmd.Context(), req) 134 if err != nil { 135 return err 136 } 137 138 return clientCtx.PrintProto(res) 139 }, 140 } 141 142 flags.AddQueryFlagsToCmd(cmd) 143 144 return cmd 145 } 146 147 // GetCmdTotalAckFees returns the command handler for the Query/TotalAckFees rpc. 148 func GetCmdTotalAckFees(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 149 cmd := &cobra.Command{ 150 Use: "total-ack-fees [port-id] [channel-id] [sequence]", 151 Short: "Query the total acknowledgement fees for a packet", 152 Long: "Query the total acknowledgement fees for a packet", 153 Args: cobra.ExactArgs(3), 154 Example: fmt.Sprintf("%s query ibc-fee total-ack-fees transfer channel-5 100", version.ServerName), 155 RunE: func(cmd *cobra.Command, args []string) error { 156 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 157 158 portID, channelID := args[0], args[1] 159 seq, err := strconv.ParseUint(args[2], 10, 64) 160 if err != nil { 161 return err 162 } 163 164 packetID := channeltypes.NewPacketId(portID, channelID, seq) 165 166 if err := packetID.Validate(); err != nil { 167 return err 168 } 169 170 queryClient := types.NewQueryClient(clientCtx) 171 172 req := &types.QueryTotalAckFeesRequest{ 173 PacketId: packetID, 174 } 175 176 res, err := queryClient.TotalAckFees(cmd.Context(), req) 177 if err != nil { 178 return err 179 } 180 181 return clientCtx.PrintProto(res) 182 }, 183 } 184 185 flags.AddQueryFlagsToCmd(cmd) 186 187 return cmd 188 } 189 190 // GetCmdTotalTimeoutFees returns the command handler for the Query/TotalTimeoutFees rpc. 191 func GetCmdTotalTimeoutFees(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 192 cmd := &cobra.Command{ 193 Use: "total-timeout-fees [port-id] [channel-id] [sequence]", 194 Short: "Query the total timeout fees for a packet", 195 Long: "Query the total timeout fees for a packet", 196 Args: cobra.ExactArgs(3), 197 Example: fmt.Sprintf("%s query ibc-fee total-timeout-fees transfer channel-5 100", version.ServerName), 198 RunE: func(cmd *cobra.Command, args []string) error { 199 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 200 201 portID, channelID := args[0], args[1] 202 seq, err := strconv.ParseUint(args[2], 10, 64) 203 if err != nil { 204 return err 205 } 206 207 packetID := channeltypes.NewPacketId(portID, channelID, seq) 208 209 if err := packetID.Validate(); err != nil { 210 return err 211 } 212 213 queryClient := types.NewQueryClient(clientCtx) 214 215 req := &types.QueryTotalTimeoutFeesRequest{ 216 PacketId: packetID, 217 } 218 219 res, err := queryClient.TotalTimeoutFees(cmd.Context(), req) 220 if err != nil { 221 return err 222 } 223 224 return clientCtx.PrintProto(res) 225 }, 226 } 227 228 flags.AddQueryFlagsToCmd(cmd) 229 230 return cmd 231 } 232 233 // GetCmdPayee returns the command handler for the Query/Payee rpc. 234 func GetCmdPayee(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 235 cmd := &cobra.Command{ 236 Use: "payee [channel-id] [relayer]", 237 Short: "Query the relayer payee address on a given channel", 238 Long: "Query the relayer payee address on a given channel", 239 Args: cobra.ExactArgs(2), 240 Example: fmt.Sprintf("%s query ibc-fee payee channel-5 cosmos1layxcsmyye0dc0har9sdfzwckaz8sjwlfsj8zs", version.ServerName), 241 RunE: func(cmd *cobra.Command, args []string) error { 242 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 243 244 if _, err := sdk.AccAddressFromBech32(args[1]); err != nil { 245 return err 246 } 247 248 queryClient := types.NewQueryClient(clientCtx) 249 250 req := &types.QueryPayeeRequest{ 251 ChannelId: args[0], 252 Relayer: args[1], 253 } 254 255 res, err := queryClient.Payee(cmd.Context(), req) 256 if err != nil { 257 return err 258 } 259 260 return clientCtx.PrintProto(res) 261 }, 262 } 263 264 flags.AddQueryFlagsToCmd(cmd) 265 266 return cmd 267 } 268 269 // GetCmdCounterpartyPayee returns the command handler for the Query/CounterpartyPayee rpc. 270 func GetCmdCounterpartyPayee(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 271 cmd := &cobra.Command{ 272 Use: "counterparty-payee [channel-id] [relayer]", 273 Short: "Query the relayer counterparty payee on a given channel", 274 Long: "Query the relayer counterparty payee on a given channel", 275 Args: cobra.ExactArgs(2), 276 Example: fmt.Sprintf("%s query ibc-fee counterparty-payee channel-5 cosmos1layxcsmyye0dc0har9sdfzwckaz8sjwlfsj8zs", version.ServerName), 277 RunE: func(cmd *cobra.Command, args []string) error { 278 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 279 280 if _, err := sdk.AccAddressFromBech32(args[1]); err != nil { 281 return err 282 } 283 284 queryClient := types.NewQueryClient(clientCtx) 285 286 req := &types.QueryCounterpartyPayeeRequest{ 287 ChannelId: args[0], 288 Relayer: args[1], 289 } 290 291 res, err := queryClient.CounterpartyPayee(cmd.Context(), req) 292 if err != nil { 293 return err 294 } 295 296 return clientCtx.PrintProto(res) 297 }, 298 } 299 300 flags.AddQueryFlagsToCmd(cmd) 301 302 return cmd 303 } 304 305 // GetCmdFeeEnabledChannels returns the command handler for the Query/FeeEnabledChannels rpc. 306 func GetCmdFeeEnabledChannels(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 307 cmd := &cobra.Command{ 308 Use: "channels", 309 Short: "Query the ibc-fee enabled channels", 310 Long: "Query the ibc-fee enabled channels", 311 Args: cobra.NoArgs, 312 Example: fmt.Sprintf("%s query ibc-fee channels", version.ServerName), 313 RunE: func(cmd *cobra.Command, args []string) error { 314 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 315 316 pageReq, err := client.ReadPageRequest(cmd.Flags()) 317 if err != nil { 318 return err 319 } 320 321 req := &types.QueryFeeEnabledChannelsRequest{ 322 Pagination: pageReq, 323 QueryHeight: uint64(clientCtx.Height), 324 } 325 326 queryClient := types.NewQueryClient(clientCtx) 327 328 res, err := queryClient.FeeEnabledChannels(cmd.Context(), req) 329 if err != nil { 330 return err 331 } 332 333 return clientCtx.PrintProto(res) 334 }, 335 } 336 337 flags.AddQueryFlagsToCmd(cmd) 338 flags.AddPaginationFlagsToCmd(cmd, "channels") 339 340 return cmd 341 } 342 343 // GetCmdFeeEnabledChannel returns the command handler for the Query/FeeEnabledChannel rpc. 344 func GetCmdFeeEnabledChannel(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 345 cmd := &cobra.Command{ 346 Use: "channel [port-id] [channel-id]", 347 Short: "Query the ibc-fee enabled status of a channel", 348 Long: "Query the ibc-fee enabled status of a channel", 349 Args: cobra.ExactArgs(2), 350 Example: fmt.Sprintf("%s query ibc-fee channel transfer channel-6", version.ServerName), 351 RunE: func(cmd *cobra.Command, args []string) error { 352 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 353 354 req := &types.QueryFeeEnabledChannelRequest{ 355 PortId: args[0], 356 ChannelId: args[1], 357 } 358 359 queryClient := types.NewQueryClient(clientCtx) 360 361 res, err := queryClient.FeeEnabledChannel(cmd.Context(), req) 362 if err != nil { 363 return err 364 } 365 366 return clientCtx.PrintProto(res) 367 }, 368 } 369 370 flags.AddQueryFlagsToCmd(cmd) 371 372 return cmd 373 } 374 375 // GetCmdIncentivizedPacketsForChannel returns all of the unrelayed incentivized packets on a given channel 376 func GetCmdIncentivizedPacketsForChannel(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 377 cmd := &cobra.Command{ 378 Use: "packets-for-channel [port-id] [channel-id]", 379 Short: "Query for all of the unrelayed incentivized packets on a given channel", 380 Long: "Query for all of the unrelayed incentivized packets on a given channel. These are packets that have not yet been relayed.", 381 Args: cobra.ExactArgs(2), 382 Example: fmt.Sprintf("%s query ibc-fee packets-for-channel", version.ServerName), 383 RunE: func(cmd *cobra.Command, args []string) error { 384 clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg) 385 pageReq, err := client.ReadPageRequest(cmd.Flags()) 386 if err != nil { 387 return err 388 } 389 390 req := &types.QueryIncentivizedPacketsForChannelRequest{ 391 Pagination: pageReq, 392 PortId: args[0], 393 ChannelId: args[1], 394 QueryHeight: uint64(clientCtx.Height), 395 } 396 397 queryClient := types.NewQueryClient(clientCtx) 398 399 res, err := queryClient.IncentivizedPacketsForChannel(cmd.Context(), req) 400 if err != nil { 401 return err 402 } 403 404 return clientCtx.PrintProto(res) 405 }, 406 } 407 408 flags.AddQueryFlagsToCmd(cmd) 409 flags.AddPaginationFlagsToCmd(cmd, "packets-for-channel") 410 411 return cmd 412 }