diff --git a/CHANGELOG.md b/CHANGELOG.md index a393565403b..80905a6931e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`. ### Features +* (modules/apps/29-fee) [\#1229](https://github.com/cosmos/ibc-go/pull/1229) Adding CLI commands for getting all unrelayed incentivized packets and packet by packet-id. ### Bug Fixes diff --git a/modules/apps/29-fee/client/cli/cli.go b/modules/apps/29-fee/client/cli/cli.go index 292f1d7b3d8..5a53914bc58 100644 --- a/modules/apps/29-fee/client/cli/cli.go +++ b/modules/apps/29-fee/client/cli/cli.go @@ -18,6 +18,8 @@ func GetQueryCmd() *cobra.Command { GetCmdTotalRecvFees(), GetCmdTotalAckFees(), GetCmdTotalTimeoutFees(), + GetCmdIncentivizedPacket(), + GetCmdIncentivizedPackets(), ) return queryCmd diff --git a/modules/apps/29-fee/client/cli/query.go b/modules/apps/29-fee/client/cli/query.go index 95bb0959ba7..e16cc842360 100644 --- a/modules/apps/29-fee/client/cli/query.go +++ b/modules/apps/29-fee/client/cli/query.go @@ -149,3 +149,90 @@ func GetCmdTotalTimeoutFees() *cobra.Command { return cmd } + +// GetCmdIncentivizedPacket returns the unrelayed incentivized packet for a given packetID +func GetCmdIncentivizedPacket() *cobra.Command { + cmd := &cobra.Command{ + Use: "packet [port-id] [channel-id] [sequence]", + Short: "Query for an unrelayed incentivized packet by port-id, channel-id and packet sequence.", + Long: "Query for an unrelayed incentivized packet by port-id, channel-id and packet sequence.", + Args: cobra.ExactArgs(3), + Example: fmt.Sprintf("%s query ibc-fee packet-by-id", version.AppName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + seq, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return err + } + + packetID := channeltypes.PacketId{ + PortId: args[0], + ChannelId: args[1], + Sequence: seq, + } + + req := &types.QueryIncentivizedPacketRequest{ + PacketId: packetID, + QueryHeight: uint64(clientCtx.Height), + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.IncentivizedPacket(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdIncentivizedPackets returns all of the unrelayed incentivized packets +func GetCmdIncentivizedPackets() *cobra.Command { + cmd := &cobra.Command{ + Use: "packets", + Short: "Query for all of the unrelayed incentivized packets and associated fees across all channels.", + Long: "Query for all of the unrelayed incentivized packets and associated fees across all channels.", + Args: cobra.NoArgs, + Example: fmt.Sprintf("%s query ibc-fee packets", version.AppName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + req := &types.QueryIncentivizedPacketsRequest{ + Pagination: pageReq, + QueryHeight: uint64(clientCtx.Height), + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.IncentivizedPackets(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "packets") + + return cmd +}