Set GasAdjustment in CLIContext when handling HTTP requests

This is to address @alexanderbez's comments
This commit is contained in:
Alessio Treglia
2018-08-31 19:04:42 +02:00
parent 599923fb99
commit 1370ca611b
10 changed files with 80 additions and 16 deletions
+15
View File
@@ -3,6 +3,7 @@ package utils
import (
"fmt"
"net/http"
"strconv"
)
const (
@@ -28,3 +29,17 @@ func WriteSimulationResponse(w *http.ResponseWriter, gas int64) {
func HasDryRunArg(r *http.Request) bool {
return r.URL.Query().Get(queryArgDryRun) == "true"
}
// ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a default
// value if the string is empty. Write
func ParseFloat64OrReturnBadRequest(w *http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool) {
if len(s) == 0 {
return defaultIfEmpty, true
}
n, err := strconv.ParseFloat(s, 64)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return n, false
}
return n, true
}
-8
View File
@@ -12,11 +12,6 @@ import (
"github.com/tendermint/tendermint/libs/common"
)
// DefaultGasAdjustment is applied to gas estimates to avoid tx
// execution failures due to state changes that might
// occur between the tx simulation and the actual run.
const DefaultGasAdjustment = 1.0
// SendTx implements a auxiliary handler that facilitates sending a series of
// messages in a signed transaction given a TxContext and a QueryContext. It
// ensures that the account exists, has a proper number and sequence set. In
@@ -91,9 +86,6 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *
}
func adjustGasEstimate(estimate int64, adjustment float64) int64 {
if adjustment == 0 {
adjustment = DefaultGasAdjustment
}
return int64(adjustment * float64(estimate))
}