Skip to content

Commit

Permalink
ics29: feat: CLI query commands for packets (#1229)
Browse files Browse the repository at this point in the history
* feat: adding query for getting incentivized packet by packet-id

* feat: add cli for getting all incentivized packets across all channels

* nits: suggestions

* Update modules/apps/29-fee/client/cli/query.go

Co-authored-by: Damian Nolan <[email protected]>

* chore: changelog

* nits: comments

Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
seantking and damiannolan authored Apr 7, 2022
1 parent 7447b60 commit 76e0c24
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 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
}

0 comments on commit 76e0c24

Please sign in to comment.