-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
101 lines (83 loc) · 4.43 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package rest
import (
"fmt"
"net/http"
"github.com/coinexchain/cosmos-utils/client/restutil"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/coinexchain/cet-sdk/modules/asset/internal/types"
)
const (
symbol = "symbol"
)
// registerTXRoutes -
func registerTXRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
r.HandleFunc("/asset/tokens", issueRequestHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/ownerships", transferOwnerRequestHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/mints", mintTokenHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/burns", burnTokenHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/forbids", forbidTokenHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/unforbids", unForbidTokenHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/forbidden/whitelist", addWhitelistHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/unforbidden/whitelist", removeWhitelistHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/forbidden/addresses", forbidAddrHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/unforbidden/addresses", unForbidAddrHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/asset/tokens/{symbol}/infos", modifyTokenInfoHandlerFn(cdc, cliCtx)).Methods("POST")
}
// issueRequestHandlerFn - http request handler to issue new token.
func issueRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
checker := func(cdc *codec.Codec, cliCtx context.CLIContext, req restutil.RestReq) error {
symbol := req.(*issueReq).Symbol
bz, err := cdc.MarshalJSON(types.NewQueryAssetParams(symbol))
if err != nil {
return err
}
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryToken)
if res, _, _ := cliCtx.QueryWithData(route, bz); res != nil {
return types.ErrDuplicateTokenSymbol(symbol)
}
return nil
}
return restutil.NewRestHandlerBuilder(cdc, cliCtx, new(issueReq)).Build(checker)
}
// transferOwnershipRequestHandlerFn - http request handler to transfer token owner ship.
func transferOwnerRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(transferOwnerReq))
}
// mintTokenHandlerFn - http request handler to mint token.
func mintTokenHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(mintTokenReq))
}
// burnTokenHandlerFn - http request handler to burn token.
func burnTokenHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(burnTokenReq))
}
// forbidTokenHandlerFn - http request handler to forbid token.
func forbidTokenHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(forbidTokenReq))
}
// unForbidTokenHandlerFn - http request handler to unforbid token.
func unForbidTokenHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(unForbidTokenReq))
}
// addWhitelistHandlerFn - http request handler to add whitelist.
func addWhitelistHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(addWhiteListReq))
}
// removeWhitelistHandlerFn - http request handler to add whitelist.
func removeWhitelistHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(removeWhiteListReq))
}
// forbidAddrHandlerFn - http request handler to forbid addresses.
func forbidAddrHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(forbidAddrReq))
}
// unForbidAddrHandlerFn - http request handler to unforbid addresses.
func unForbidAddrHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(unforbidAddrReq))
}
// modifyTokenInfoHandlerFn - http request handler to modify token url.
func modifyTokenInfoHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return restutil.NewRestHandler(cdc, cliCtx, new(modifyTokenInfoReq))
}