refactor to waterfall, in preparation to making determine arguments async

This commit is contained in:
Iuri Matias 2018-05-20 20:59:55 -04:00 committed by Jonathan Rainville
parent 3fb2b6fa60
commit c0549a6642
1 changed files with 37 additions and 31 deletions

View File

@ -70,8 +70,12 @@ class Deploy {
return callback();
}
async.waterfall([
function determineArguments(next) {
contract.realArgs = self.determineArguments(params || contract.args, contract);
next();
},
function deployIt(next) {
if (contract.address !== undefined) {
try {
utils.toChecksumAddress(contract.address);
@ -80,29 +84,31 @@ class Deploy {
self.logger.error(e.message);
contract.error = e.message;
self.events.emit("deploy:contract:error", contract);
return callback(e.message);
return next(e.message);
}
contract.deployedAddress = contract.address;
self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + contract.address.bold.cyan);
self.events.emit("deploy:contract:deployed", contract);
return callback();
return next();
}
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
if (!trackedContract) {
return self.contractToDeploy(contract, params, callback);
return self.contractToDeploy(contract, params, next);
}
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
if (codeInChain !== "0x") {
self.contractAlreadyDeployed(contract, trackedContract, callback);
self.contractAlreadyDeployed(contract, trackedContract, next);
} else {
self.contractToDeploy(contract, params, callback);
self.contractToDeploy(contract, params, next);
}
});
});
}
], callback);
}
contractAlreadyDeployed(contract, trackedContract, callback) {
const self = this;