forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
48 lines (38 loc) · 1 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package rest
import (
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/MonOsmosis/osmosis/v10/x/lockup/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/types/rest"
)
func registerTxHandlers(clientCtx client.Context, r *mux.Router) {
r.HandleFunc("/lockup/locktokens", newLockTokensHandlerFn(clientCtx)).Methods("POST")
}
func newLockTokensHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req LockTokensReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
duration, err := time.ParseDuration(req.Duration)
if err != nil {
return
}
msg := types.NewMsgLockTokens(
req.Owner,
duration,
req.Coins,
)
if rest.CheckBadRequestError(w, msg.ValidateBasic()) {
return
}
tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg)
}
}