make contract gas calculation automatic

This commit is contained in:
Iuri Matias 2016-09-23 02:33:38 -07:00
parent 7b3fefd039
commit 89c0001dcb
6 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,6 @@
{
"development": {
"gasLimit": 500000,
"gasPrice": 10000000000000,
"gas": "auto",
"contracts": {
}
}

View File

@ -1,7 +1,6 @@
{
"default": {
"gasLimit": 500000,
"gasPrice": 10000000000000,
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [

View File

@ -1,7 +1,6 @@
{
"development": {
"gasLimit": 500000,
"gasPrice": 10000000000000,
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [

View File

@ -26,9 +26,10 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
var contract = this.contractsManager.contracts[className];
var abi = JSON.stringify(contract.abiDefinition);
var gasEstimates = JSON.stringify(contract.gasEstimates);
if (useEmbarkJS) {
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "'});";
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});";
} else {
result += "\n" + className + "Abi = " + abi + ";";
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";

View File

@ -21,7 +21,13 @@ ContractsManager.prototype.build = function() {
var contract = this.compiledContracts[className];
var contractConfig = this.contractsConfig[className];
contract.gasLimit = this.contractsConfig.gasLimit;
if (this.contractsConfig.gas === 'auto') {
var maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
var adjustedGas = Math.round(maxGas * 1.01);
contract.gas = adjustedGas;
} else {
contract.gas = this.contractsConfig.gas;
}
contract.gasPrice = this.contractsConfig.gasPrice;
if (contractConfig === undefined) {

View File

@ -16,7 +16,7 @@ Deploy.prototype.deployContract = function(contract, params, callback) {
contractParams.push({
from: this.web3.eth.coinbase,
data: contract.code,
gas: contract.gasLimit,
gas: contract.gas,
gasPrice: contract.gasPrice
});