/
tx.go
157 lines (153 loc) · 4.27 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package rest
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/gorilla/mux"
)
func registerTxRoutes(cliCtx client.Context, r *mux.Router) {
//r.HandleFunc("/wasm/code", storeCodeHandlerFn(cliCtx)).Methods("POST")
//r.HandleFunc("/wasm/code/{codeId}", instantiateContractHandlerFn(cliCtx)).Methods("POST")
//r.HandleFunc("/wasm/contract/{contractAddr}", executeContractHandlerFn(cliCtx)).Methods("POST")
}
// limit max bytes read to prevent gzip bombs
// const maxSize = 400 * 1024
//type storeCodeReq struct {
// BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
// WasmBytes []byte `json:"wasm_bytes"`
//}
//
//type instantiateContractReq struct {
// BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
// Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
// InitMsg []byte `json:"init_msg" yaml:"init_msg"`
//}
//
//type executeContractReq struct {
// BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
// ExecMsg []byte `json:"exec_msg" yaml:"exec_msg"`
// Amount sdk.Coins `json:"coins" yaml:"coins"`
//}
//
//func storeCodeHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// var req storeCodeReq
// if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
// return
// }
//
// req.BaseReq = req.BaseReq.Sanitize()
// if !req.BaseReq.ValidateBasic(w) {
// return
// }
//
// var err error
// wasm := req.WasmBytes
// if len(wasm) > maxSize {
// rest.WriteErrorResponse(w, http.StatusBadRequest, "Binary size exceeds maximum limit")
// return
// }
//
// // gzip the wasm file
// if wasmUtils.IsWasm(wasm) {
// wasm, err = wasmUtils.GzipIt(wasm)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
// } else if !wasmUtils.IsGzip(wasm) {
// rest.WriteErrorResponse(w, http.StatusBadRequest, "Invalid input file, use wasm binary or zip")
// return
// }
//
// fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
// // build and sign the transaction, then broadcast to Tendermint
// msg := types.MsgStoreCode{
// Sender: fromAddr,
// WASMByteCode: wasm,
// }
//
// err = msg.ValidateBasic()
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
//
// utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
// }
//}
//
//func instantiateContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// var req instantiateContractReq
// if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
// return
// }
// vars := mux.Vars(r)
// codeId := vars["codeId"]
//
// req.BaseReq = req.BaseReq.Sanitize()
// if !req.BaseReq.ValidateBasic(w) {
// return
// }
//
// // get the id of the code to instantiate
// codeID, err := strconv.ParseUint(codeId, 10, 64)
// if err != nil {
// return
// }
//
// msg := types.MsgInstantiateContract{
// Sender: cliCtx.GetFromAddress(),
// Code: codeID,
// InitFunds: req.Deposit,
// InitMsg: req.InitMsg,
// }
//
// err = msg.ValidateBasic()
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
//
// utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
// }
//}
//
//func executeContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// var req executeContractReq
// if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
// return
// }
// vars := mux.Vars(r)
// contractAddr := vars["contractAddr"]
//
// req.BaseReq = req.BaseReq.Sanitize()
// if !req.BaseReq.ValidateBasic(w) {
// return
// }
//
// contractAddress, err := sdk.AccAddressFromBech32(contractAddr)
// if err != nil {
// return
// }
//
// msg := types.MsgExecuteContract{
// Sender: cliCtx.GetFromAddress(),
// Contract: contractAddress,
// Msg: req.ExecMsg,
// SentFunds: req.Amount,
// }
//
// err = msg.ValidateBasic()
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
//
// utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
// }
//}