-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
71 lines (59 loc) · 2.12 KB
/
rest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package rest
import (
"net/http"
sdk "github.com/cosmos/cosmos-sdk/types"
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/fibonacci-chain/core/x/mint/types"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/client/tx"
typesrest "github.com/cosmos/cosmos-sdk/types/rest"
)
// RegisterRoutes registers minting module REST handlers on the provided router.
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) {
r := clientrest.WithHTTPDeprecationHeaders(rtr)
registerQueryRoutes(clientCtx, r)
}
// PlanRequest defines a proposal for a new upgrade plan.
type UpdateMinterRequest struct {
BaseReq typesrest.BaseReq `json:"base_req" yaml:"base_req"`
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
Minter types.Minter `json:"minter" yaml:"minter"`
}
func UpdateResourceDependencyProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "update_minter",
Handler: newUpdateMinterPostHandler(clientCtx),
}
}
func newUpdateMinterPostHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req UpdateMinterRequest
if !typesrest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
if typesrest.CheckBadRequestError(w, err) {
return
}
content := types.NewUpdateMinterProposalHandler(
req.Title, req.Description, req.Minter,
)
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, fromAddr)
if typesrest.CheckBadRequestError(w, err) {
return
}
if typesrest.CheckBadRequestError(w, msg.ValidateBasic()) {
return
}
tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg)
}
}