mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-16 23:57:11 +00:00
make contract gas calculation automatic
This commit is contained in:
parent
7b3fefd039
commit
89c0001dcb
@ -1,7 +1,6 @@
|
||||
{
|
||||
"development": {
|
||||
"gasLimit": 500000,
|
||||
"gasPrice": 10000000000000,
|
||||
"gas": "auto",
|
||||
"contracts": {
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"default": {
|
||||
"gasLimit": 500000,
|
||||
"gasPrice": 10000000000000,
|
||||
"gas": "auto",
|
||||
"contracts": {
|
||||
"SimpleStorage": {
|
||||
"args": [
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"development": {
|
||||
"gasLimit": 500000,
|
||||
"gasPrice": 10000000000000,
|
||||
"gas": "auto",
|
||||
"contracts": {
|
||||
"SimpleStorage": {
|
||||
"args": [
|
||||
|
@ -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);";
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user