-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simulate only flag '--dry-run' to both CLI tx commands and RESTful endpoints to trigger the simulation of unsigned transactions. * Turning --dry-run on causes the --gas flag to be ignored. The simulation will return the estimate of the gas required to actually run the transaction. * Adjustment is no longer required. It now defaults to 1.0. * In some test cases accounts retrieved from the state do not come with a PubKey. In such cases, a fake secp256k1 key is generated and gas consumption calculated accordingly. Closes: #2110
- Loading branch information
Showing
25 changed files
with
375 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
queryArgDryRun = "simulate" | ||
) | ||
|
||
// WriteErrorResponse prepares and writes a HTTP error | ||
// given a status code and an error message. | ||
func WriteErrorResponse(w *http.ResponseWriter, status int, msg string) { | ||
(*w).WriteHeader(status) | ||
(*w).Write([]byte(msg)) | ||
} | ||
|
||
// WriteGasEstimateResponse prepares and writes an HTTP | ||
// response for transactions simulations. | ||
func WriteSimulationResponse(w *http.ResponseWriter, gas int64) { | ||
(*w).WriteHeader(http.StatusOK) | ||
(*w).Write([]byte(fmt.Sprintf(`{"gas_estimate":%v}`, gas))) | ||
} | ||
|
||
// HasDryRunArg returns true if the request's URL query contains | ||
// the dry run argument and its value is set to "true". | ||
func HasDryRunArg(r *http.Request) bool { | ||
return r.URL.Query().Get(queryArgDryRun) == "true" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.