-
Notifications
You must be signed in to change notification settings - Fork 50
/
rest.go
113 lines (95 loc) · 3.28 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Package rest defines the RESTful service for the cert module.
package rest
import (
"net/http"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov"
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
"github.com/certikfoundation/shentu/x/cert/types"
)
// RegisterRoutes registers the routes in main application.
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
RegisterTxRoutes(cliCtx, r)
RegisterQueryRoutes(cliCtx, r)
}
type proposeCertifierReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Proposer string `json:"proposer"`
Certifier string `json:"certifier"`
Alias string `json:"alias"`
Description string `json:"description"`
}
type certifyValidatorReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Certifier string `json:"certifier"`
Validator string `json:"validator"`
}
type certifyGeneralReq struct {
BaseReq rest.BaseReq `json:"base_req"`
CertificateType string `json:"certificate_type"`
ContentType string `json:"content_type"`
Content string `json:"content"`
Description string `json:"description"`
Certifier string `json:"certifier"`
}
type certifyCompilationReq struct {
BaseReq rest.BaseReq `json:"base_req"`
SourceCodeHash string `json:"source_code_hash"`
Compiler string `json:"compiler"`
BytecodeHash string `json:"bytecode_hash"`
Description string `json:"description"`
}
type certifyPlatformReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Certifier string `json:"certifier"`
Validator string `json:"validator"`
Platform string `json:"platform"`
}
type revokeCertificateReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Revoker string `json:"revoker"`
CertificateID string `json:"certificate_id"`
Description string `json:"description"`
}
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route.
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "certifier_update",
Handler: postProposalHandlerFn(cliCtx),
}
}
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req CertifierUpdateProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
from, err := sdk.AccAddressFromHex(req.BaseReq.From)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
content := types.NewCertifierUpdateProposal(
req.Title,
req.Description,
req.Certifier,
req.Alias,
from,
req.AddOrRemove,
)
msg := gov.NewMsgSubmitProposal(content, req.Deposit, from)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}