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) => {
next(); contract.realArgs = realArgs;
next();
});
}, },
function deployIt(next) { function deployIt(next) {
if (contract.address !== undefined) { if (contract.address !== undefined) {
@ -126,27 +134,31 @@ class Deploy {
contractToDeploy(contract, params, callback) { contractToDeploy(contract, params, callback) {
const self = this; const self = this;
contract.realArgs = self.determineArguments(params || contract.args, contract);
this.deployContract(contract, contract.realArgs, function (err, address) { // TODO: refactor to async
if (err) { self.determineArguments(params || contract.args, contract, (realArgs) => {
self.events.emit("deploy:contract:error", contract); contract.realArgs = realArgs;
return callback(new Error(err));
}
contract.address = address;
self.events.emit("deploy:contract:deployed", contract);
// always run contractCode so other functionality like 'afterDeploy' can also work this.deployContract(contract, contract.realArgs, function (err, address) {
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); if (err) {
let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); self.events.emit("deploy:contract:error", contract);
RunCode.doEval(contractCode, {web3: self.web3}); return callback(new Error(err));
}
contract.address = address;
self.events.emit("deploy:contract:deployed", contract);
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); // always run contractCode so other functionality like 'afterDeploy' can also work
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit);
RunCode.doEval(contractCode, {web3: self.web3});
async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
plugin.call(plugin, contract, nextEach);
}, () => { async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) {
callback(); plugin.call(plugin, contract, nextEach);
}, () => {
callback();
});
}); });
}); });
} }