diff --git a/x/ccv/provider/client/cli/query.go b/x/ccv/provider/client/cli/query.go index 1d6e26350b..be516d584f 100644 --- a/x/ccv/provider/client/cli/query.go +++ b/x/ccv/provider/client/cli/query.go @@ -39,6 +39,7 @@ func NewQueryCmd() *cobra.Command { cmd.AddCommand(CmdValidatorConsumerCommissionRate()) cmd.AddCommand(CmdBlocksUntilNextEpoch()) cmd.AddCommand(CmdConsumerIdFromClientId()) + cmd.AddCommand(CmdConsumerChain()) return cmd } @@ -88,7 +89,7 @@ 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 @@ -96,7 +97,7 @@ func CmdConsumerChains() *cobra.Command { 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 @@ -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 +}