diff --git a/modules/apps/29-fee/client/cli/cli.go b/modules/apps/29-fee/client/cli/cli.go index abb1d40c31b..a8caf155310 100644 --- a/modules/apps/29-fee/client/cli/cli.go +++ b/modules/apps/29-fee/client/cli/cli.go @@ -15,7 +15,7 @@ func GetQueryCmd() *cobra.Command { } queryCmd.AddCommand( - // TODO + GetCmdTotalRecvFees(), ) return queryCmd diff --git a/modules/apps/29-fee/client/cli/query.go b/modules/apps/29-fee/client/cli/query.go index e8878f3e042..1413ae001cb 100644 --- a/modules/apps/29-fee/client/cli/query.go +++ b/modules/apps/29-fee/client/cli/query.go @@ -1,3 +1,59 @@ package cli -// TODO +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + "github.com/spf13/cobra" +) + +// GetCmdTotalRecvFees returns the command handler for the Query/TotalRecvFees rpc. +func GetCmdTotalRecvFees() *cobra.Command { + cmd := &cobra.Command{ + Use: "total-recv-fees [port-id] [channel-id] [sequence]", + Short: "Query the total receive fees for a packet", + Long: "Query the total receive fees for a packet", + Args: cobra.ExactArgs(3), + Example: fmt.Sprintf("%s query ibc-fee transfer channel-5 100", version.AppName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + portID, channelID := args[0], args[1] + seq, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return err + } + + packetID := channeltypes.NewPacketId(channelID, portID, seq) + + if err := packetID.Validate(); err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryTotalRecvFeesRequest{ + PacketId: packetID, + } + + res, err := queryClient.TotalRecvFees(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +}