simplify method dealing with instanceOf

This commit is contained in:
Iuri Matias 2016-10-30 20:48:16 -04:00
parent 5c283b5232
commit 99c528c230
1 changed files with 36 additions and 33 deletions

View File

@ -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();
},