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

ics29: feat: CLI query commands for packets #1229

Merged
merged 6 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func GetQueryCmd() *cobra.Command {
GetCmdTotalRecvFees(),
GetCmdTotalAckFees(),
GetCmdTotalTimeoutFees(),
GetCmdIncentivizedPacket(),
GetCmdIncentivizedPackets(),
)

return queryCmd
Expand Down
87 changes: 87 additions & 0 deletions modules/apps/29-fee/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,90 @@ func GetCmdTotalTimeoutFees() *cobra.Command {

return cmd
}

// GetCmdIncentivizedPacket returns the unrelayed incentivized packets for a given packetID
seantking marked this conversation as resolved.
Show resolved Hide resolved
func GetCmdIncentivizedPacket() *cobra.Command {
cmd := &cobra.Command{
Use: "packet [port-id] [channel-id] [sequence]",
Short: "Query for an incentivized packet by packet-id.",
seantking marked this conversation as resolved.
Show resolved Hide resolved
seantking marked this conversation as resolved.
Show resolved Hide resolved
Long: "Query for an incentivized packet packet-id. A packet-id is made up of 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 across all channels.",
seantking marked this conversation as resolved.
Show resolved Hide resolved
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
}