/
tx.go
48 lines (38 loc) · 1.47 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 (
"fmt"
"net/http"
"time"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/coinexchain/cosmos-utils/client/restutil"
)
// sendRequestHandlerFn - http request handler to send coins to a address.
func sendTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
checker := func(cdc *codec.Codec, cliCtx context.CLIContext, req restutil.RestReq) error {
currentTime := time.Now().Unix()
unlockTime := req.(*sendReq).UnlockTime
if unlockTime < 0 {
return fmt.Errorf("invalid unlock time: %d", unlockTime)
}
if unlockTime > 0 && unlockTime < currentTime {
return fmt.Errorf("unlock time should be later than the current time")
}
return nil
}
return restutil.NewRestHandlerBuilder(cdc, cliCtx, new(sendReq)).Build(checker)
}
func sendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(memoReq))
}
func sendSupervisedTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
checker := func(cdc *codec.Codec, cliCtx context.CLIContext, req restutil.RestReq) error {
currentTime := time.Now().Unix()
unlockTime := req.(*sendSupervisedReq).UnlockTime
if unlockTime < currentTime {
return fmt.Errorf("unlock time should be later than the current time")
}
return nil
}
return restutil.NewRestHandlerBuilder(cdc, cliCtx, new(sendSupervisedReq)).Build(checker)
}