Skip to content

Commit

Permalink
fix: fix consumer chain query CLI (#2190)
Browse files Browse the repository at this point in the history
* fix consumer chains query cli

* add consumer-chain cli command

* fix consumer chains cli bug
  • Loading branch information
sainoe authored Aug 29, 2024
1 parent 1135770 commit 1c63e3e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewQueryCmd() *cobra.Command {
cmd.AddCommand(CmdValidatorConsumerCommissionRate())
cmd.AddCommand(CmdBlocksUntilNextEpoch())
cmd.AddCommand(CmdConsumerIdFromClientId())
cmd.AddCommand(CmdConsumerChain())
return cmd
}

Expand Down Expand Up @@ -88,15 +89,15 @@ func CmdConsumerChains() *cobra.Command {

req := &types.QueryConsumerChainsRequest{}

if args[0] != "" {
if len(args) >= 1 && args[0] != "" {
phase, err := strconv.ParseInt(args[0], 10, 32)
if err != nil {
return err
}
req.Phase = types.ConsumerPhase(phase)
}

if args[1] != "" {
if len(args) == 2 && args[1] != "" {
limit, err := strconv.ParseInt(args[1], 10, 32)
if err != nil {
return err
Expand Down Expand Up @@ -553,3 +554,30 @@ func CmdConsumerIdFromClientId() *cobra.Command {

return cmd
}

func CmdConsumerChain() *cobra.Command {
cmd := &cobra.Command{
Use: "consumer-chain [consumer-id]",
Short: "Query the consumer chain associated with the consumer id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryConsumerChainRequest{ConsumerId: args[0]}
res, err := queryClient.QueryConsumerChain(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

0 comments on commit 1c63e3e

Please sign in to comment.