diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 494b34a20..0f3c50b16 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -21,10 +21,8 @@ class Deploy { // part of ta 'normal' contract deployment determineArguments(suppliedArgs, contract, callback) { const self = this; - let realArgs = [], contractName, referedContract; let args = suppliedArgs; - if (!Array.isArray(args)) { args = []; let abi = contract.abiDefinition.find((abi) => abi.type === 'constructor'); @@ -38,35 +36,37 @@ class Deploy { } } + let realArgs = []; async.eachLimit(args, 1, (arg, nextEachCb) => { - if (arg[0] === "$") { - contractName = arg.substr(1); + let contractName = arg.substr(1); self.events.request('contracts:contract', contractName, (referedContract) => { realArgs.push(referedContract.deployedAddress); nextEachCb(); }); } else if (Array.isArray(arg)) { let subRealArgs = []; - // todo: convert to async each - for (let sub_arg of arg) { + + async.eachLimit(arg, 1, (sub_arg, nextSubEachCb) => { if (sub_arg[0] === "$") { - contractName = sub_arg.substr(1); - referedContract = this.contractsManager.getContract(contractName); - subRealArgs.push(referedContract.deployedAddress); + let contractName = sub_arg.substr(1); + + self.events.request('contracts:contract', contractName, (referedContract) => { + subRealArgs.push(referedContract.deployedAddress); + nextSubEachCb(); + }); } else { subRealArgs.push(sub_arg); + nextSubEachCb(); } - } - // todo: put this in the final callback - realArgs.push(subRealArgs); - nextEachCb(); + }, () => { + realArgs.push(subRealArgs); + nextEachCb(); + }); } else { realArgs.push(arg); nextEachCb(); } - - }, () => { callback(realArgs); });