github.com/cosmos/cosmos-sdk@v0.50.10/client/rpc/validators.go (about)

     1  package rpc
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/cosmos/cosmos-sdk/client"
     9  	"github.com/cosmos/cosmos-sdk/client/flags"
    10  	"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
    11  	"github.com/cosmos/cosmos-sdk/types/query"
    12  )
    13  
    14  // ValidatorCommand returns the validator set for a given height
    15  func ValidatorCommand() *cobra.Command {
    16  	cmd := &cobra.Command{
    17  		Use:     "comet-validator-set [height]",
    18  		Aliases: []string{"cometbft-validator-set", "tendermint-validator-set"},
    19  		Short:   "Get the full CometBFT validator set at given height",
    20  		Args:    cobra.MaximumNArgs(1),
    21  		RunE: func(cmd *cobra.Command, args []string) error {
    22  			clientCtx, err := client.GetClientQueryContext(cmd)
    23  			if err != nil {
    24  				return err
    25  			}
    26  
    27  			var height *int64
    28  
    29  			// optional height
    30  			if len(args) > 0 {
    31  				val, err := strconv.ParseInt(args[0], 10, 64)
    32  				if err != nil {
    33  					return err
    34  				}
    35  
    36  				if val > 0 {
    37  					height = &val
    38  				}
    39  			}
    40  
    41  			page, _ := cmd.Flags().GetInt(flags.FlagPage)
    42  			limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
    43  
    44  			response, err := cmtservice.ValidatorsOutput(cmd.Context(), clientCtx, height, page, limit)
    45  			if err != nil {
    46  				return err
    47  			}
    48  
    49  			return clientCtx.PrintProto(response)
    50  		},
    51  	}
    52  
    53  	cmd.Flags().String(flags.FlagNode, "tcp://localhost:26657", "<host>:<port> to CometBFT RPC interface for this chain")
    54  	cmd.Flags().StringP(flags.FlagOutput, "o", "text", "Output format (text|json)")
    55  	cmd.Flags().Int(flags.FlagPage, query.DefaultPage, "Query a specific page of paginated results")
    56  	cmd.Flags().Int(flags.FlagLimit, 100, "Query number of results returned per page")
    57  
    58  	return cmd
    59  }