github.com/lino-network/lino@v0.6.11/x/validator/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 6 "github.com/cosmos/cosmos-sdk/client" 7 "github.com/cosmos/cosmos-sdk/codec" 8 "github.com/spf13/cobra" 9 10 linotypes "github.com/lino-network/lino/types" 11 "github.com/lino-network/lino/utils" 12 types "github.com/lino-network/lino/x/validator" 13 model "github.com/lino-network/lino/x/validator/model" 14 ) 15 16 func GetQueryCmd(cdc *codec.Codec) *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: types.ModuleName, 19 Short: "Querying commands for the validator module", 20 DisableFlagParsing: true, 21 SuggestionsMinimumDistance: 2, 22 RunE: client.ValidateCmd, 23 } 24 cmd.AddCommand(client.GetCommands( 25 getCmdShow(cdc), 26 getCmdList(cdc), 27 getCmdVoteInfo(cdc), 28 )...) 29 return cmd 30 } 31 32 // GetCmdShow - 33 func getCmdShow(cdc *codec.Codec) *cobra.Command { 34 return &cobra.Command{ 35 Use: "show", 36 Short: "show <username>", 37 Args: cobra.ExactArgs(1), 38 RunE: func(cmd *cobra.Command, args []string) error { 39 user := linotypes.AccountKey(args[0]) 40 uri := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryValidator, user) 41 rst := model.Validator{} 42 return utils.CLIQueryJSONPrint(cdc, uri, nil, 43 func() interface{} { return &rst }) 44 }, 45 } 46 } 47 48 // GetCmdList - 49 func getCmdList(cdc *codec.Codec) *cobra.Command { 50 return &cobra.Command{ 51 Use: "list", 52 Short: "list all validators", 53 Args: cobra.ExactArgs(0), 54 RunE: func(cmd *cobra.Command, args []string) error { 55 uri := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorList) 56 rst := model.ValidatorList{} 57 return utils.CLIQueryJSONPrint(cdc, uri, nil, 58 func() interface{} { return &rst }) 59 }, 60 } 61 } 62 63 // GetCmdVoteInfo 64 func getCmdVoteInfo(cdc *codec.Codec) *cobra.Command { 65 return &cobra.Command{ 66 Use: "voteinfo", 67 Short: "voteinfo <username>", 68 Args: cobra.ExactArgs(1), 69 RunE: func(cmd *cobra.Command, args []string) error { 70 user := linotypes.AccountKey(args[0]) 71 uri := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryElectionVoteList, user) 72 rst := model.ElectionVoteList{} 73 return utils.CLIQueryJSONPrint(cdc, uri, nil, 74 func() interface{} { return &rst }) 75 }, 76 } 77 }