2018-06-21 17:19:14 -07:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-02-14 08:53:36 -08:00
|
|
|
"github.com/gorilla/mux"
|
2019-02-04 07:48:26 -08:00
|
|
|
|
2018-06-21 17:19:14 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-02-14 08:53:36 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
2018-06-21 17:19:14 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// REST Variable names
|
|
|
|
// nolint
|
|
|
|
const (
|
2018-11-13 15:45:37 -08:00
|
|
|
RestParamsType = "type"
|
|
|
|
RestProposalID = "proposal-id"
|
2018-11-21 15:53:33 -08:00
|
|
|
RestDepositor = "depositor"
|
2018-07-17 13:59:06 -07:00
|
|
|
RestVoter = "voter"
|
|
|
|
RestProposalStatus = "status"
|
2018-11-06 23:33:18 -08:00
|
|
|
RestNumLimit = "limit"
|
2018-06-21 17:19:14 -07:00
|
|
|
)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
// ProposalRESTHandler defines a REST handler implemented in another module. The
|
|
|
|
// sub-route is mounted on the governance REST handler.
|
|
|
|
type ProposalRESTHandler struct {
|
|
|
|
SubRoute string
|
|
|
|
Handler func(http.ResponseWriter, *http.Request)
|
|
|
|
}
|
|
|
|
|
2018-06-21 17:19:14 -07:00
|
|
|
// RegisterRoutes - Central function to define routes that get registered by the main application
|
2019-06-06 08:43:15 -07:00
|
|
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, phs []ProposalRESTHandler) {
|
2019-08-08 12:51:18 -07:00
|
|
|
registerQueryRoutes(cliCtx, r)
|
|
|
|
registerTxRoutes(cliCtx, r, phs)
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 08:53:36 -08:00
|
|
|
// PostProposalReq defines the properties of a proposal request's body.
|
|
|
|
type PostProposalReq struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
|
|
|
|
Title string `json:"title" yaml:"title"` // Title of the proposal
|
|
|
|
Description string `json:"description" yaml:"description"` // Description of the proposal
|
2019-11-08 06:40:56 -08:00
|
|
|
ProposalType string `json:"proposal_type" yaml:"proposal_type"` // Type of proposal. Initial set {PlainTextProposal }
|
2019-07-05 16:25:56 -07:00
|
|
|
Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"` // Address of the proposer
|
|
|
|
InitialDeposit sdk.Coins `json:"initial_deposit" yaml:"initial_deposit"` // Coins to add to the proposal's deposit
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 08:53:36 -08:00
|
|
|
// DepositReq defines the properties of a deposit request's body.
|
|
|
|
type DepositReq struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
|
|
|
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"` // Address of the depositor
|
|
|
|
Amount sdk.Coins `json:"amount" yaml:"amount"` // Coins to add to the proposal's deposit
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 08:53:36 -08:00
|
|
|
// VoteReq defines the properties of a vote request's body.
|
|
|
|
type VoteReq struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
|
|
|
|
Voter sdk.AccAddress `json:"voter" yaml:"voter"` // address of the voter
|
|
|
|
Option string `json:"option" yaml:"option"` // option from OptionSet chosen by the voter
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|