Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli for query total recv fees #1035

Merged
merged 3 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetQueryCmd() *cobra.Command {
}

queryCmd.AddCommand(
// TODO
GetCmdTotalRecvFees(),
)

return queryCmd
Expand Down
58 changes: 57 additions & 1 deletion modules/apps/29-fee/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -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
}