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);
next();
function _determineArguments(next) {
self.determineArguments(params || contract.args, contract, (realArgs) => {
contract.realArgs = realArgs;
next();
});
},
function deployIt(next) {
if (contract.address !== undefined) {
@ -126,27 +134,31 @@ class Deploy {
contractToDeploy(contract, params, callback) {
const self = this;
contract.realArgs = self.determineArguments(params || contract.args, contract);
this.deployContract(contract, contract.realArgs, function (err, address) {
if (err) {
self.events.emit("deploy:contract:error", contract);
return callback(new Error(err));
}
contract.address = address;
self.events.emit("deploy:contract:deployed", contract);
// TODO: refactor to async
self.determineArguments(params || contract.args, contract, (realArgs) => {
contract.realArgs = realArgs;
// 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});
this.deployContract(contract, contract.realArgs, function (err, address) {
if (err) {
self.events.emit("deploy:contract:error", contract);
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) {
plugin.call(plugin, contract, nextEach);
}, () => {
callback();
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) {
plugin.call(plugin, contract, nextEach);
}, () => {
callback();
});
});
});
}