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 2 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(),
GetIncentivizedPacketByPacketId(),
GetAllIncentivizedPackets(),
seantking marked this conversation as resolved.
Show resolved Hide resolved
)

return queryCmd
Expand Down
88 changes: 88 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,91 @@ func GetCmdTotalTimeoutFees() *cobra.Command {

return cmd
}

// GetIncentivizedPacketByPacketId returns the unrelayed incentivized packets for a given packetID
func GetIncentivizedPacketByPacketId() *cobra.Command {
cmd := &cobra.Command{
Use: "packet-by-id [port-id] [channel-id] [sequence]",
seantking marked this conversation as resolved.
Show resolved Hide resolved
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{
seantking marked this conversation as resolved.
Show resolved Hide resolved
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)
flags.AddPaginationFlagsToCmd(cmd, "packet-by-id")
seantking marked this conversation as resolved.
Show resolved Hide resolved

return cmd
}

// GetAllIncentivizedPackets returns all of the unrelayed incentivized packets
func GetAllIncentivizedPackets() *cobra.Command {
cmd := &cobra.Command{
Use: "packets",
Short: "Query for all of the unrelayed incentivized packets across all channels.",
seantking marked this conversation as resolved.
Show resolved Hide resolved
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
}