mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
add query committee cmd
This commit is contained in:
parent
5c280696fb
commit
733711c88c
@ -17,27 +17,69 @@ import (
|
|||||||
|
|
||||||
// GetQueryCmd returns the cli query commands for this module
|
// GetQueryCmd returns the cli query commands for this module
|
||||||
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
// Group gov queries under a subcommand
|
queryCmd := &cobra.Command{
|
||||||
govQueryCmd := &cobra.Command{
|
|
||||||
Use: types.ModuleName,
|
Use: types.ModuleName,
|
||||||
Short: "Querying commands for the governance module",
|
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
SuggestionsMinimumDistance: 2,
|
SuggestionsMinimumDistance: 2,
|
||||||
RunE: client.ValidateCmd,
|
RunE: client.ValidateCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
govQueryCmd.AddCommand(client.GetCommands(
|
queryCmd.AddCommand(client.GetCommands(
|
||||||
|
// committees
|
||||||
|
GetCmdQueryCommittee(queryRoute, cdc),
|
||||||
GetCmdQueryCommittees(queryRoute, cdc),
|
GetCmdQueryCommittees(queryRoute, cdc),
|
||||||
|
// proposals
|
||||||
GetCmdQueryProposal(queryRoute, cdc),
|
GetCmdQueryProposal(queryRoute, cdc),
|
||||||
GetCmdQueryProposals(queryRoute, cdc),
|
GetCmdQueryProposals(queryRoute, cdc),
|
||||||
|
// votes
|
||||||
GetCmdQueryVotes(queryRoute, cdc),
|
GetCmdQueryVotes(queryRoute, cdc),
|
||||||
|
// other
|
||||||
GetCmdQueryProposer(queryRoute, cdc),
|
GetCmdQueryProposer(queryRoute, cdc),
|
||||||
GetCmdQueryTally(queryRoute, cdc))...)
|
GetCmdQueryTally(queryRoute, cdc))...)
|
||||||
|
|
||||||
return govQueryCmd
|
return queryCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------
|
||||||
|
// Committees
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
|
// GetCmdQueryCommittee implements a query committee command.
|
||||||
|
func GetCmdQueryCommittee(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "committee [committee-id]",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Short: "Query details of a single committee",
|
||||||
|
Example: fmt.Sprintf("%s query %s committee 1", version.ClientName, types.ModuleName),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
|
// Prepare params for querier
|
||||||
|
committeeID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("committee-id %s not a valid uint", args[0])
|
||||||
|
}
|
||||||
|
bz, err := cdc.MarshalJSON(types.NewQueryCommitteeParams(committeeID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query
|
||||||
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryCommittee), bz)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode and print result
|
||||||
|
committee := types.Committee{}
|
||||||
|
if err = cdc.UnmarshalJSON(res, &committee); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cliCtx.PrintOutput(committee)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCmdQueryCommittees implements a query committees command.
|
// GetCmdQueryCommittees implements a query committees command.
|
||||||
@ -67,6 +109,10 @@ func GetCmdQueryCommittees(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------
|
||||||
|
// Proposals
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
// GetCmdQueryProposal implements the query proposal command.
|
// GetCmdQueryProposal implements the query proposal command.
|
||||||
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
@ -82,7 +128,7 @@ func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("proposal-id %s not a valid uint", args[0])
|
return fmt.Errorf("proposal-id %s not a valid uint", args[0])
|
||||||
}
|
}
|
||||||
bz, err := cdc.MarshalJSON(types.NewQueryCommitteeParams(proposalID))
|
bz, err := cdc.MarshalJSON(types.NewQueryProposalParams(proposalID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -122,7 +168,7 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query
|
// Query
|
||||||
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz)
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryProposals), bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -139,6 +185,10 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------
|
||||||
|
// Votes
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
// GetCmdQueryVotes implements the command to query for proposal votes.
|
// GetCmdQueryVotes implements the command to query for proposal votes.
|
||||||
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
@ -176,6 +226,10 @@ func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------
|
||||||
|
// Other
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "tally [proposal-id]",
|
Use: "tally [proposal-id]",
|
||||||
|
@ -190,7 +190,6 @@ func queryProposerHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write response
|
// Write response
|
||||||
cliCtx = cliCtx.WithHeight(height)
|
|
||||||
rest.PostProcessResponse(w, cliCtx, res)
|
rest.PostProcessResponse(w, cliCtx, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user