From 99c528c23061689b5ec106e3896c1f6d34496d4f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 30 Oct 2016 20:48:16 -0400 Subject: [PATCH] simplify method dealing with instanceOf --- lib/contracts.js | 69 +++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/contracts.js b/lib/contracts.js index 0c6485715..c97d43c14 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -80,48 +80,51 @@ 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; for(className in self.contracts) { contract = self.contracts[className]; - // if deploy intention is not specified default is true - if (contract.deploy === undefined) { - contract.deploy = true; + if (contract.instanceOf === undefined) { continue; } + + parentContractName = contract.instanceOf; + parentContract = self.contracts[parentContractName]; + + if (parentContract === className) { + self.logger.error(className + ": instanceOf is set to itself"); + continue; } - if (contract.instanceOf !== undefined) { - parentContractName = contract.instanceOf; - parentContract = self.contracts[parentContractName]; - - if (parentContract === className) { - self.logger.error(className + ": instanceOf is set to itself"); - continue; - } - - if (parentContract === undefined) { - slef.logger.error(className + ": couldn't find instanceOf contract " + parentContractName); - continue; - } - - if (parentContract.args && parentContract.args.length > 0 && contract.args === []) { - contract.args = parentContract.args; - } - - if (contract.code !== undefined) { - self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName); - } - - contract.code = parentContract.code; - contract.runtimeBytecode = parentContract.runtimeBytecode; - contract.gasEstimates = parentContract.gasEstimates; - contract.functionHashes = parentContract.functionHashes; - contract.abiDefinition = parentContract.abiDefinition; - - contract.gas = contract.gas || parentContract.gas; - contract.gasPrice = contract.gasPrice || parentContract.gasPrice; + if (parentContract === undefined) { + self.logger.error(className + ": couldn't find instanceOf contract " + parentContractName); + continue; } + + if (parentContract.args && parentContract.args.length > 0 && contract.args === []) { + contract.args = parentContract.args; + } + + if (contract.code !== undefined) { + self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName); + } + + contract.code = parentContract.code; + contract.runtimeBytecode = parentContract.runtimeBytecode; + contract.gasEstimates = parentContract.gasEstimates; + contract.functionHashes = parentContract.functionHashes; + contract.abiDefinition = parentContract.abiDefinition; + + contract.gas = contract.gas || parentContract.gas; + contract.gasPrice = contract.gasPrice || parentContract.gasPrice; + } callback(); },