diff --git a/x/committee/client/cli/query.go b/x/committee/client/cli/query.go index 2fee1497..2368dccb 100644 --- a/x/committee/client/cli/query.go +++ b/x/committee/client/cli/query.go @@ -31,6 +31,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { GetCmdQueryCommittee(queryRoute, cdc), GetCmdQueryCommittees(queryRoute, cdc), // proposals + GetCmdQueryNextProposalID(queryRoute, cdc), GetCmdQueryProposal(queryRoute, cdc), GetCmdQueryProposals(queryRoute, cdc), // votes @@ -115,6 +116,35 @@ func GetCmdQueryCommittees(queryRoute string, cdc *codec.Codec) *cobra.Command { // 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. func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ diff --git a/x/committee/client/rest/query.go b/x/committee/client/rest/query.go index cf182065..29310942 100644 --- a/x/committee/client/rest/query.go +++ b/x/committee/client/rest/query.go @@ -17,6 +17,7 @@ import ( 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/{%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/proposals/{%s}", types.ModuleName, RestProposalID), queryProposalHandlerFn(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 // ------------------------------------------ +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 { return func(w http.ResponseWriter, r *http.Request) { // Parse the query height diff --git a/x/committee/legacy/v0_11/types.go b/x/committee/legacy/v0_11/types.go index c8808f3a..9c38de8b 100644 --- a/x/committee/legacy/v0_11/types.go +++ b/x/committee/legacy/v0_11/types.go @@ -737,7 +737,7 @@ func addressesEqual(addrs1, addrs2 []sdk.AccAddress) bool { return areEqual } -// DefaultNextProposalID is the starting poiint for proposal IDs. +// DefaultNextProposalID is the starting point for proposal IDs. const DefaultNextProposalID uint64 = 1 // GenesisState is state that must be provided at chain genesis.