mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
|
package rest
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||
|
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
||
|
"github.com/gorilla/mux"
|
||
|
"github.com/kava-labs/kava/x/incentive/types"
|
||
|
)
|
||
|
|
||
|
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||
|
r.HandleFunc("/incentive/claim", postClaimHandlerFn(cliCtx)).Methods("POST")
|
||
|
|
||
|
}
|
||
|
|
||
|
func postClaimHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
var requestBody types.PostClaimReq
|
||
|
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &requestBody) {
|
||
|
return
|
||
|
}
|
||
|
requestBody.BaseReq = requestBody.BaseReq.Sanitize()
|
||
|
if !requestBody.BaseReq.ValidateBasic(w) {
|
||
|
return
|
||
|
}
|
||
|
msg := types.NewMsgClaimReward(requestBody.Sender, requestBody.Denom)
|
||
|
if err := msg.ValidateBasic(); err != nil {
|
||
|
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||
|
return
|
||
|
}
|
||
|
utils.WriteGenerateStdTxResponse(w, cliCtx, requestBody.BaseReq, []sdk.Msg{msg})
|
||
|
}
|
||
|
}
|