github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/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 13 comm "github.com/fibonacci-chain/fbc/x/common" 14 "github.com/fibonacci-chain/fbc/x/distribution/types" 15 "github.com/fibonacci-chain/fbc/x/gov" 16 govrest "github.com/fibonacci-chain/fbc/x/gov/client/rest" 17 ) 18 19 // RegisterRoutes register distribution REST routes. 20 func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) { 21 registerQueryRoutes(cliCtx, r, queryRoute) 22 registerTxRoutes(cliCtx, r, queryRoute) 23 } 24 25 // CommunityPoolSpendProposalRESTHandler returns a CommunityPoolSpendProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. 26 func CommunityPoolSpendProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler { 27 return govrest.ProposalRESTHandler{ 28 SubRoute: "community_pool_spend", 29 Handler: postCommunityPoolSpendProposalHandlerFn(cliCtx), 30 } 31 } 32 33 func postCommunityPoolSpendProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { 34 return func(w http.ResponseWriter, r *http.Request) { 35 var req CommunityPoolSpendProposalReq 36 if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { 37 return 38 } 39 40 req.BaseReq = req.BaseReq.Sanitize() 41 if !req.BaseReq.ValidateBasic(w) { 42 return 43 } 44 45 content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount) 46 47 msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) 48 if err := msg.ValidateBasic(); err != nil { 49 comm.HandleErrorMsg(w, cliCtx, comm.CodeInvalidParam, err.Error()) 50 return 51 } 52 53 utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) 54 } 55 }