mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
Committee module: query next proposal ID (#1019)
* next-proposal-id cli query * fix spelling in comments * next-proposal-id rest query
This commit is contained in:
parent
0ee449e5a9
commit
b9c59c728b
@ -31,6 +31,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
GetCmdQueryCommittee(queryRoute, cdc),
|
GetCmdQueryCommittee(queryRoute, cdc),
|
||||||
GetCmdQueryCommittees(queryRoute, cdc),
|
GetCmdQueryCommittees(queryRoute, cdc),
|
||||||
// proposals
|
// proposals
|
||||||
|
GetCmdQueryNextProposalID(queryRoute, cdc),
|
||||||
GetCmdQueryProposal(queryRoute, cdc),
|
GetCmdQueryProposal(queryRoute, cdc),
|
||||||
GetCmdQueryProposals(queryRoute, cdc),
|
GetCmdQueryProposals(queryRoute, cdc),
|
||||||
// votes
|
// votes
|
||||||
@ -115,6 +116,35 @@ func GetCmdQueryCommittees(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
// Proposals
|
// Proposals
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
|
// GetCmdQueryNextProposalID implements a query next proposal ID command.
|
||||||
|
func GetCmdQueryNextProposalID(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "next-proposal-id",
|
||||||
|
Short: "Query the next proposal ID",
|
||||||
|
Args: cobra.ExactArgs(0),
|
||||||
|
Example: fmt.Sprintf("%s query %s next-proposal-id", version.ClientName, types.ModuleName),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
|
// Query
|
||||||
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryNextProposalID), nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode and print results
|
||||||
|
var nextProposalID uint64
|
||||||
|
err = cdc.UnmarshalJSON(res, &nextProposalID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cliCtx.PrintOutput(nextProposalID)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// 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{
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||||
r.HandleFunc(fmt.Sprintf("/%s/committees", types.ModuleName), queryCommitteesHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/%s/committees", types.ModuleName), queryCommitteesHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc(fmt.Sprintf("/%s/committees/{%s}", types.ModuleName, RestCommitteeID), queryCommitteeHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/%s/committees/{%s}", types.ModuleName, RestCommitteeID), queryCommitteeHandlerFn(cliCtx)).Methods("GET")
|
||||||
|
r.HandleFunc(fmt.Sprintf("/%s/next-proposal-id", types.ModuleName), queryNextProposalIdHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc(fmt.Sprintf("/%s/committees/{%s}/proposals", types.ModuleName, RestCommitteeID), queryProposalsHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/%s/committees/{%s}/proposals", types.ModuleName, RestCommitteeID), queryProposalsHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc(fmt.Sprintf("/%s/proposals/{%s}", types.ModuleName, RestProposalID), queryProposalHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/%s/proposals/{%s}", types.ModuleName, RestProposalID), queryProposalHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc(fmt.Sprintf("/%s/proposals/{%s}/proposer", types.ModuleName, RestProposalID), queryProposerHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/%s/proposals/{%s}/proposer", types.ModuleName, RestProposalID), queryProposerHandlerFn(cliCtx)).Methods("GET")
|
||||||
@ -91,6 +92,27 @@ func queryCommitteeHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
// Proposals
|
// Proposals
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
|
func queryNextProposalIdHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Parse the query height
|
||||||
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query
|
||||||
|
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryNextProposalID), nil)
|
||||||
|
if err != nil {
|
||||||
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write response
|
||||||
|
cliCtx = cliCtx.WithHeight(height)
|
||||||
|
rest.PostProcessResponse(w, cliCtx, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func queryProposalsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func queryProposalsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Parse the query height
|
// Parse the query height
|
||||||
|
@ -737,7 +737,7 @@ func addressesEqual(addrs1, addrs2 []sdk.AccAddress) bool {
|
|||||||
return areEqual
|
return areEqual
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultNextProposalID is the starting poiint for proposal IDs.
|
// DefaultNextProposalID is the starting point for proposal IDs.
|
||||||
const DefaultNextProposalID uint64 = 1
|
const DefaultNextProposalID uint64 = 1
|
||||||
|
|
||||||
// GenesisState is state that must be provided at chain genesis.
|
// GenesisState is state that must be provided at chain genesis.
|
||||||
|
Loading…
Reference in New Issue
Block a user