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