github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/distribution/client/rest/rest.go (about) 1 package rest 2 3 import ( 4 "net/http" 5 6 "github.com/gorilla/mux" 7 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 9 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/rest" 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils" 12 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/distribution/types" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/gov" 14 govrest "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/gov/client/rest" 15 ) 16 17 // RegisterRoutes register distribution REST routes. 18 func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) { 19 registerQueryRoutes(cliCtx, r, queryRoute) 20 registerTxRoutes(cliCtx, r, queryRoute) 21 } 22 23 // ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. 24 func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler { 25 return govrest.ProposalRESTHandler{ 26 SubRoute: "community_pool_spend", 27 Handler: postProposalHandlerFn(cliCtx), 28 } 29 } 30 31 func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { 32 return func(w http.ResponseWriter, r *http.Request) { 33 var req CommunityPoolSpendProposalReq 34 if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { 35 return 36 } 37 38 req.BaseReq = req.BaseReq.Sanitize() 39 if !req.BaseReq.ValidateBasic(w) { 40 return 41 } 42 43 content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount) 44 45 msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) 46 if err := msg.ValidateBasic(); err != nil { 47 rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) 48 return 49 } 50 51 utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) 52 } 53 }