Commit 8a0f2259 authored by gshx's avatar gshx

Merge branch 'heco-testnet' of https://code.wuban.net.cn/liwei/multisend into heco-testnet

parents 41a66ca8 72d31252
......@@ -303,6 +303,72 @@ func (web *WebServicer) GetTxsList(w http.ResponseWriter, r *http.Request) {
}
func (web *WebServicer) Calculate(w http.ResponseWriter, r *http.Request) {
requestAmountAsStr := r.URL.Query().Get("requestAmount")
currentAmountStr := r.URL.Query().Get("currentAmount")
everyTxAmountAsStr := r.URL.Query().Get("everyTxAmount")
txNumStr := r.URL.Query().Get("txNum")
requestAmountAsInt, err := strconv.ParseInt(requestAmountAsStr, 10, 64)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
// currentAmount, err := strconv.ParseInt(currentAmountStr, 10, 64) // strconv.Atoi(currentAmountStr)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
// everyTxAmountAsInt, err := strconv.ParseInt(everyTxAmountAsStr, 10, 64) // strconv.Atoi(everyTxAmountAsStr)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
// txNum, err := strconv.ParseInt(txNumStr, 10, 64) //strconv.Atoi(txNumStr)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
requestAmount, err := decimal.NewFromString(requestAmountAsStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
currentAmount, err := decimal.NewFromString(currentAmountStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
everyTxAmount, err := decimal.NewFromString(everyTxAmountAsStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
txNum, err := decimal.NewFromString(txNumStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
res := requestAmount.Add(currentAmount).Sub(everyTxAmount.Mul(txNum))
fmt.Printf("len(resAsJson): %v \n", res.String())
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(res.String()))
}
func (web *WebServicer) WebService(config Config) error {
r := mux.NewRouter()
// Routes consist of a path and a handler function.
......@@ -312,6 +378,8 @@ func (web *WebServicer) WebService(config Config) error {
r.HandleFunc("/sender/tree/{uuid}", web.GetTreeHandler)
r.HandleFunc("/sender/txslist/{hash}", web.GetTxsList)
r.HandleFunc("/sender/txs", web.TxsHandler).Methods("POST")
r.HandleFunc("/sender/calculate", web.Calculate)
//r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(config.WebStaticDir))))
clientFactory, exists := clientFactories["ethclient"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment