mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-01-12 08:15:18 +00:00
a073238f34
* module files * proto types * types and generated proto types * keeper * client scaffold * add savings module to app * remove placeholder types file * implement rest and add to module * update proto types * validation for supported denoms * generate updates proto types * update comments * update comments * remove unused imports from proto files * regenerate proto files * update proto types * client * deposit type and generated proto types * deposit keeper methods + tests * update savings module file * update app.go + test common * remove abci * remove refs to other modules * remove endblocker call * genesis init test for module account * update genesis test with params * add get/set params test * fix up keeper test * use params getter * simplify if/else statement * fix: add msgServer to keeper * fix: register deposit message * update deposit test * wrap invalid deposit denom error msg Co-authored-by: karzak <kjydavis3@gmail.com>
39 lines
1001 B
Go
39 lines
1001 B
Go
package rest
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/kava-labs/kava/x/savings/types"
|
|
)
|
|
|
|
func registerTxRoutes(cliCtx client.Context, r *mux.Router) {
|
|
r.HandleFunc(fmt.Sprintf("/%s/deposit", types.ModuleName), postDepositHandlerFn(cliCtx)).Methods("POST")
|
|
}
|
|
|
|
func postDepositHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
// Decode POST request body
|
|
var req PostCreateDepositReq
|
|
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
|
|
return
|
|
}
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
return
|
|
}
|
|
|
|
msg := types.NewMsgDeposit(req.From, req.Amount)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, &msg)
|
|
}
|
|
}
|