From 88bdd662dec2c9bedc021db7be11d8fad6d0b825 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 30 Oct 2016 19:38:40 -0400 Subject: [PATCH] refactor determining method arguments --- lib/deploy.js | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index 4b43bcd6..cfbba629 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -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) {