make determine arguments async

This commit is contained in:
Iuri Matias 2018-05-21 12:29:18 -04:00 committed by Jonathan Rainville
parent c0549a6642
commit 7cebbec7b6
1 changed files with 38 additions and 26 deletions

View File

@ -17,8 +17,10 @@ class Deploy {
this.gasLimit = options.gasLimit; this.gasLimit = options.gasLimit;
} }
determineArguments(suppliedArgs, contract) { // TODO: determining the arguments could also be in a module since it's not
let realArgs = [], l, arg, contractName, referedContract; // part of ta 'normal' contract deployment
determineArguments(suppliedArgs, contract, callback) {
let realArgs = [], contractName, referedContract;
let args = suppliedArgs; let args = suppliedArgs;
@ -35,8 +37,8 @@ class Deploy {
} }
} }
for (l = 0; l < args.length; l++) { async.eachLimit(args, 1, (arg, nextEachCb) => {
arg = args[l];
if (arg[0] === "$") { if (arg[0] === "$") {
contractName = arg.substr(1); contractName = arg.substr(1);
referedContract = this.contractsManager.getContract(contractName); referedContract = this.contractsManager.getContract(contractName);
@ -56,9 +58,13 @@ class Deploy {
} else { } else {
realArgs.push(arg); realArgs.push(arg);
} }
}
return realArgs;
nextEachCb();
}, () => {
callback(realArgs);
});
} }
checkAndDeployContract(contract, params, callback) { checkAndDeployContract(contract, params, callback) {
@ -71,9 +77,11 @@ class Deploy {
} }
async.waterfall([ async.waterfall([
function determineArguments(next) { function _determineArguments(next) {
contract.realArgs = self.determineArguments(params || contract.args, contract); self.determineArguments(params || contract.args, contract, (realArgs) => {
contract.realArgs = realArgs;
next(); next();
});
}, },
function deployIt(next) { function deployIt(next) {
if (contract.address !== undefined) { if (contract.address !== undefined) {
@ -126,7 +134,10 @@ class Deploy {
contractToDeploy(contract, params, callback) { contractToDeploy(contract, params, callback) {
const self = this; const self = this;
contract.realArgs = self.determineArguments(params || contract.args, contract);
// TODO: refactor to async
self.determineArguments(params || contract.args, contract, (realArgs) => {
contract.realArgs = realArgs;
this.deployContract(contract, contract.realArgs, function (err, address) { this.deployContract(contract, contract.realArgs, function (err, address) {
if (err) { if (err) {
@ -149,6 +160,7 @@ class Deploy {
callback(); callback();
}); });
}); });
});
} }
deployContract(contract, params, callback) { deployContract(contract, params, callback) {