Skip to content

Commit 52244cc

Browse files
committed
move gas adjust to its own method
1 parent 99c528c commit 52244cc

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

lib/contracts.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ var async = require('async');
44

55
// TODO: create a contract object
66

7+
var adjustGas = function(contract) {
8+
var maxGas, adjustedGas;
9+
if (contract.gas === 'auto') {
10+
if (contract.deploy) {
11+
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
12+
} else {
13+
maxGas = 500000;
14+
}
15+
// TODO: put a check so it doesn't go over the block limit
16+
adjustedGas = Math.round(maxGas * 1.40);
17+
contract.gas = adjustedGas;
18+
}
19+
};
20+
721
var ContractsManager = function(options) {
822
this.contractFiles = options.contractFiles;
923
this.contractsConfig = options.contractsConfig;
@@ -42,9 +56,16 @@ ContractsManager.prototype.build = function(done) {
4256
}
4357
callback();
4458
},
59+
function setDeployIntention(callback) {
60+
var className, contract;
61+
for(className in self.contracts) {
62+
contract = self.contracts[className];
63+
contract.deploy = (contract.deploy === undefined) || contract.deploy;
64+
}
65+
callback();
66+
},
4567
function prepareContractsFromCompilation(callback) {
4668
var className, compiledContract, contractConfig, contract;
47-
var maxGas, adjustedGas;
4869
for(className in self.compiledContracts) {
4970
compiledContract = self.compiledContracts[className];
5071
contractConfig = self.contractsConfig.contracts[className];
@@ -56,22 +77,10 @@ ContractsManager.prototype.build = function(done) {
5677
contract.gasEstimates = compiledContract.gasEstimates;
5778
contract.functionHashes = compiledContract.functionHashes;
5879
contract.abiDefinition = compiledContract.abiDefinition;
59-
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas;
6080

61-
if (contract.deploy === undefined) {
62-
contract.deploy = true;
63-
}
81+
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas;
82+
contract.gas = adjustGas(contract);
6483

65-
if (contract.gas === 'auto') {
66-
if (contract.deploy) {
67-
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
68-
} else {
69-
maxGas = 500000;
70-
}
71-
// TODO: put a check so it doesn't go over the block limit
72-
adjustedGas = Math.round(maxGas * 1.40);
73-
contract.gas = adjustedGas;
74-
}
7584
contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice;
7685
contract.type = 'file';
7786
contract.className = className;
@@ -80,13 +89,6 @@ ContractsManager.prototype.build = function(done) {
8089
}
8190
callback();
8291
},
83-
function setDeployIntention(callback) {
84-
var className, contract;
85-
for(className in self.contracts) {
86-
contract = self.contracts[className];
87-
contract.deploy = (contract.deploy === undefined) || contract.deploy;
88-
}
89-
},
9092
function dealWithSpecialConfigs(callback) {
9193
var className, contract, parentContractName, parentContract;
9294

0 commit comments

Comments
 (0)