-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_distr_proposal.go
112 lines (91 loc) · 3.85 KB
/
rest_distr_proposal.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
package rest
import (
"net/http"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/context"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types/rest"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/auth/client/utils"
comm "github.com/furyaxyz/fuxchain/x/common"
"github.com/furyaxyz/fuxchain/x/distribution/types"
"github.com/furyaxyz/fuxchain/x/gov"
govrest "github.com/furyaxyz/fuxchain/x/gov/client/rest"
)
// ChangeDistributionTypeProposalRESTHandler returns a ChangeDistributionTypeProposal that exposes the change distribution type REST handler with a given sub-route.
func ChangeDistributionTypeProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "change_distribution_type",
Handler: postChangeDistributionTypeProposalHandlerFn(cliCtx),
}
}
func postChangeDistributionTypeProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req ChangeDistributionTypeProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
content := types.NewChangeDistributionTypeProposal(req.Title, req.Description, req.Type)
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
if err := msg.ValidateBasic(); err != nil {
comm.HandleErrorMsg(w, cliCtx, comm.CodeInvalidParam, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
// WithdrawRewardEnabledProposalRESTHandler returns a WithdrawRewardEnabledProposal that exposes the set withdraw reward enabled proposal REST handler with a given sub-route.
func WithdrawRewardEnabledProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "withdraw_reward_enabled",
Handler: postWithdrawRewardEnabledProposalHandlerFn(cliCtx),
}
}
func postWithdrawRewardEnabledProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req WithdrawRewardEnabledProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
content := types.NewWithdrawRewardEnabledProposal(req.Title, req.Description, req.Enabled)
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
if err := msg.ValidateBasic(); err != nil {
comm.HandleErrorMsg(w, cliCtx, comm.CodeInvalidParam, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
// RewardTruncatePrecisionProposalRESTHandler returns a RewardTruncatePrecisionProposal
//that exposes the reward truncate precision proposal REST handler with a given sub-route.
func RewardTruncatePrecisionProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "reward_truncate_precision",
Handler: postRewardTruncatePrecisionProposalHandlerFn(cliCtx),
}
}
func postRewardTruncatePrecisionProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req RewardTruncatePrecisionProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
content := types.NewRewardTruncatePrecisionProposal(req.Title, req.Description, req.Precision)
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
if err := msg.ValidateBasic(); err != nil {
comm.HandleErrorMsg(w, cliCtx, comm.CodeInvalidParam, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}