refactor to waterfall, in preparation to making determine arguments async
This commit is contained in:
parent
3fb2b6fa60
commit
c0549a6642
|
@ -70,38 +70,44 @@ class Deploy {
|
|||
return callback();
|
||||
}
|
||||
|
||||
contract.realArgs = self.determineArguments(params || contract.args, contract);
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
try {
|
||||
utils.toChecksumAddress(contract.address);
|
||||
} catch(e) {
|
||||
self.logger.error(__("error deploying %s", contract.className));
|
||||
self.logger.error(e.message);
|
||||
contract.error = e.message;
|
||||
self.events.emit("deploy:contract:error", contract);
|
||||
return callback(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();
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
||||
if (codeInChain !== "0x") {
|
||||
self.contractAlreadyDeployed(contract, trackedContract, callback);
|
||||
} else {
|
||||
self.contractToDeploy(contract, params, 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);
|
||||
} catch(e) {
|
||||
self.logger.error(__("error deploying %s", contract.className));
|
||||
self.logger.error(e.message);
|
||||
contract.error = e.message;
|
||||
self.events.emit("deploy:contract:error", contract);
|
||||
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 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, next);
|
||||
}
|
||||
|
||||
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
||||
if (codeInChain !== "0x") {
|
||||
self.contractAlreadyDeployed(contract, trackedContract, next);
|
||||
} else {
|
||||
self.contractToDeploy(contract, params, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
contractAlreadyDeployed(contract, trackedContract, callback) {
|
||||
|
|
Loading…
Reference in New Issue