0g-chain/x/savings/client/rest/tx.go
Denali Marsh a073238f34
Savings module deposits (#1192)
* 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>
2022-03-23 15:34:23 +01:00

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)
}
}