Skip to content

Commit 99c528c

Browse files
committed
simplify method dealing with instanceOf
1 parent 5c283b5 commit 99c528c

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

lib/contracts.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,48 +80,51 @@ ContractsManager.prototype.build = function(done) {
8080
}
8181
callback();
8282
},
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+
},
8390
function dealWithSpecialConfigs(callback) {
8491
var className, contract, parentContractName, parentContract;
8592

8693
for(className in self.contracts) {
8794
contract = self.contracts[className];
8895

89-
// if deploy intention is not specified default is true
90-
if (contract.deploy === undefined) {
91-
contract.deploy = true;
92-
}
96+
if (contract.instanceOf === undefined) { continue; }
9397

94-
if (contract.instanceOf !== undefined) {
95-
parentContractName = contract.instanceOf;
96-
parentContract = self.contracts[parentContractName];
98+
parentContractName = contract.instanceOf;
99+
parentContract = self.contracts[parentContractName];
97100

98-
if (parentContract === className) {
99-
self.logger.error(className + ": instanceOf is set to itself");
100-
continue;
101-
}
101+
if (parentContract === className) {
102+
self.logger.error(className + ": instanceOf is set to itself");
103+
continue;
104+
}
102105

103-
if (parentContract === undefined) {
104-
slef.logger.error(className + ": couldn't find instanceOf contract " + parentContractName);
105-
continue;
106-
}
106+
if (parentContract === undefined) {
107+
self.logger.error(className + ": couldn't find instanceOf contract " + parentContractName);
108+
continue;
109+
}
107110

108-
if (parentContract.args && parentContract.args.length > 0 && contract.args === []) {
109-
contract.args = parentContract.args;
110-
}
111+
if (parentContract.args && parentContract.args.length > 0 && contract.args === []) {
112+
contract.args = parentContract.args;
113+
}
111114

112-
if (contract.code !== undefined) {
113-
self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName);
114-
}
115+
if (contract.code !== undefined) {
116+
self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName);
117+
}
115118

116-
contract.code = parentContract.code;
117-
contract.runtimeBytecode = parentContract.runtimeBytecode;
118-
contract.gasEstimates = parentContract.gasEstimates;
119-
contract.functionHashes = parentContract.functionHashes;
120-
contract.abiDefinition = parentContract.abiDefinition;
119+
contract.code = parentContract.code;
120+
contract.runtimeBytecode = parentContract.runtimeBytecode;
121+
contract.gasEstimates = parentContract.gasEstimates;
122+
contract.functionHashes = parentContract.functionHashes;
123+
contract.abiDefinition = parentContract.abiDefinition;
124+
125+
contract.gas = contract.gas || parentContract.gas;
126+
contract.gasPrice = contract.gasPrice || parentContract.gasPrice;
121127

122-
contract.gas = contract.gas || parentContract.gas;
123-
contract.gasPrice = contract.gasPrice || parentContract.gasPrice;
124-
}
125128
}
126129
callback();
127130
},

0 commit comments

Comments
 (0)