refactor determining method arguments

This commit is contained in:
Iuri Matias 2016-10-30 19:38:40 -04:00
parent df7ff3916f
commit 88bdd662de
1 changed files with 17 additions and 28 deletions

View File

@ -15,6 +15,21 @@ var Deploy = function(options) {
});
};
Deploy.prototype.determineArguments = function(suppliedArgs) {
var realArgs = [], l, arg, contractName, referedContract;
for (l = 0; l < suppliedArgs.length; l++) {
arg = suppliedArgs[l];
if (arg[0] === "$") {
contractName = arg.substr(1);
referedContract = this.contractsManager.getContract(contractName);
realArgs.push(referedContract.deployedAddress);
} else {
realArgs.push(arg);
}
}
};
Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
var self = this;
var suppliedArgs;
@ -32,20 +47,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
if (contract.address !== undefined) {
// determine arguments
suppliedArgs = (params || contract.args);
realArgs = [];
for (l = 0; l < suppliedArgs.length; l++) {
arg = suppliedArgs[l];
if (arg[0] === "$") {
contractName = arg.substr(1);
referedContract = this.contractsManager.getContract(contractName);
realArgs.push(referedContract.deployedAddress);
} else {
realArgs.push(arg);
}
}
realArgs = self.determineArguments(params || contract.args);
contract.deployedAddress = contract.address;
self.deployTracker.trackContract(contract.className, contract.code, realArgs, contract.address);
@ -63,20 +65,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
return callback();
} else {
// determine arguments
suppliedArgs = (params || contract.args);
realArgs = [];
for (l = 0; l < suppliedArgs.length; l++) {
arg = suppliedArgs[l];
if (arg[0] === "$") {
contractName = arg.substr(1);
referedContract = this.contractsManager.getContract(contractName);
realArgs.push(referedContract.deployedAddress);
} else {
realArgs.push(arg);
}
}
realArgs = self.determineArguments(params || contract.args);
this.deployContract(contract, realArgs, function(err, address) {
if (err) {