move gas adjust to its own method
This commit is contained in:
parent
99c528c230
commit
52244cca8e
|
@ -4,6 +4,20 @@ var async = require('async');
|
|||
|
||||
// TODO: create a contract object
|
||||
|
||||
var adjustGas = function(contract) {
|
||||
var maxGas, adjustedGas;
|
||||
if (contract.gas === 'auto') {
|
||||
if (contract.deploy) {
|
||||
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
|
||||
} else {
|
||||
maxGas = 500000;
|
||||
}
|
||||
// TODO: put a check so it doesn't go over the block limit
|
||||
adjustedGas = Math.round(maxGas * 1.40);
|
||||
contract.gas = adjustedGas;
|
||||
}
|
||||
};
|
||||
|
||||
var ContractsManager = function(options) {
|
||||
this.contractFiles = options.contractFiles;
|
||||
this.contractsConfig = options.contractsConfig;
|
||||
|
@ -42,9 +56,16 @@ ContractsManager.prototype.build = function(done) {
|
|||
}
|
||||
callback();
|
||||
},
|
||||
function setDeployIntention(callback) {
|
||||
var className, contract;
|
||||
for(className in self.contracts) {
|
||||
contract = self.contracts[className];
|
||||
contract.deploy = (contract.deploy === undefined) || contract.deploy;
|
||||
}
|
||||
callback();
|
||||
},
|
||||
function prepareContractsFromCompilation(callback) {
|
||||
var className, compiledContract, contractConfig, contract;
|
||||
var maxGas, adjustedGas;
|
||||
for(className in self.compiledContracts) {
|
||||
compiledContract = self.compiledContracts[className];
|
||||
contractConfig = self.contractsConfig.contracts[className];
|
||||
|
@ -56,22 +77,10 @@ ContractsManager.prototype.build = function(done) {
|
|||
contract.gasEstimates = compiledContract.gasEstimates;
|
||||
contract.functionHashes = compiledContract.functionHashes;
|
||||
contract.abiDefinition = compiledContract.abiDefinition;
|
||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas;
|
||||
|
||||
if (contract.deploy === undefined) {
|
||||
contract.deploy = true;
|
||||
}
|
||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas;
|
||||
contract.gas = adjustGas(contract);
|
||||
|
||||
if (contract.gas === 'auto') {
|
||||
if (contract.deploy) {
|
||||
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
|
||||
} else {
|
||||
maxGas = 500000;
|
||||
}
|
||||
// TODO: put a check so it doesn't go over the block limit
|
||||
adjustedGas = Math.round(maxGas * 1.40);
|
||||
contract.gas = adjustedGas;
|
||||
}
|
||||
contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice;
|
||||
contract.type = 'file';
|
||||
contract.className = className;
|
||||
|
@ -80,13 +89,6 @@ ContractsManager.prototype.build = function(done) {
|
|||
}
|
||||
callback();
|
||||
},
|
||||
function setDeployIntention(callback) {
|
||||
var className, contract;
|
||||
for(className in self.contracts) {
|
||||
contract = self.contracts[className];
|
||||
contract.deploy = (contract.deploy === undefined) || contract.deploy;
|
||||
}
|
||||
},
|
||||
function dealWithSpecialConfigs(callback) {
|
||||
var className, contract, parentContractName, parentContract;
|
||||
|
||||
|
|
Loading…
Reference in New Issue