github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/params/client/rest/upgrade_proposal.go (about) 1 package rest 2 3 import ( 4 "net/http" 5 6 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/rest" 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils" 10 "github.com/fibonacci-chain/fbc/x/gov" 11 govrest "github.com/fibonacci-chain/fbc/x/gov/client/rest" 12 "github.com/fibonacci-chain/fbc/x/params/types" 13 ) 14 15 // UpgradeProposalReq defines a upgrade proposal request body 16 type UpgradeProposalReq struct { 17 BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` 18 Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"` 19 20 Title string `json:"title" yaml:"title"` 21 Description string `json:"description" yaml:"description"` 22 Deposit sdk.SysCoins `json:"deposit" yaml:"deposit"` 23 24 Name string `json:"name" yaml:"name"` 25 ExpectHeight uint64 `json:"expectHeight" yaml:"expectHeight"` 26 Config string `json:"config,omitempty" yaml:"config,omitempty"` 27 } 28 29 func ProposalUpgradeRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler { 30 return govrest.ProposalRESTHandler{ 31 SubRoute: "upgrade", 32 Handler: postUpgradeProposalHandlerFn(cliCtx), 33 } 34 } 35 36 func postUpgradeProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { 37 return func(w http.ResponseWriter, r *http.Request) { 38 var req UpgradeProposalReq 39 if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { 40 return 41 } 42 43 req.BaseReq = req.BaseReq.Sanitize() 44 if !req.BaseReq.ValidateBasic(w) { 45 return 46 } 47 48 content := types.NewUpgradeProposal(req.Title, req.Description, req.Name, req.ExpectHeight, req.Config) 49 50 msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) 51 if err := msg.ValidateBasic(); err != nil { 52 rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) 53 return 54 } 55 56 utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) 57 } 58 }