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": { "development": {
"gasLimit": 500000, "gas": "auto",
"gasPrice": 10000000000000,
"contracts": { "contracts": {
} }
} }

View File

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

View File

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

View File

@ -26,9 +26,10 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
var contract = this.contractsManager.contracts[className]; var contract = this.contractsManager.contracts[className];
var abi = JSON.stringify(contract.abiDefinition); var abi = JSON.stringify(contract.abiDefinition);
var gasEstimates = JSON.stringify(contract.gasEstimates);
if (useEmbarkJS) { 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 { } else {
result += "\n" + className + "Abi = " + abi + ";"; result += "\n" + className + "Abi = " + abi + ";";
result += "\n" + className + "Contract = web3.eth.contract(" + className + "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 contract = this.compiledContracts[className];
var contractConfig = this.contractsConfig[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; contract.gasPrice = this.contractsConfig.gasPrice;
if (contractConfig === undefined) { if (contractConfig === undefined) {

View File

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