diff --git a/lib/modules/deployment/index.js b/lib/modules/deployment/index.js index 1ea9064f8..ebdd97eb9 100644 --- a/lib/modules/deployment/index.js +++ b/lib/modules/deployment/index.js @@ -49,53 +49,58 @@ class DeployManager { } self.logger.info(__("deploying contracts")); - self.events.emit("deploy:beforeAll"); - - const contractDeploys = {}; - const errors = []; - contracts.forEach(contract => { - function deploy(result, callback) { - if (typeof result === 'function') { - callback = result; - } - contract._gasLimit = self.gasLimit; - self.events.request('deploy:contract', contract, (err) => { - if (err) { - contract.error = err.message || err; - self.logger.error(err.message || err); - errors.push(err); + async.waterfall([ + function (next) { + self.plugins.emitAndRunActionsForEvent("deploy:beforeAll", next); + }, + function () { + const contractDeploys = {}; + const errors = []; + contracts.forEach(contract => { + function deploy(result, callback) { + if (typeof result === 'function') { + callback = result; + } + contract._gasLimit = self.gasLimit; + self.events.request('deploy:contract', contract, (err) => { + if (err) { + contract.error = err.message || err; + self.logger.error(err.message || err); + errors.push(err); + } + callback(); + }); } - callback(); + + const className = contract.className; + if (!contractDependencies[className] || contractDependencies[className].length === 0) { + contractDeploys[className] = deploy; + return; + } + contractDeploys[className] = cloneDeep(contractDependencies[className]); + contractDeploys[className].push(deploy); }); - } - const className = contract.className; - if (!contractDependencies[className] || contractDependencies[className].length === 0) { - contractDeploys[className] = deploy; - return; + try { + async.auto(contractDeploys, function(_err, _results) { + if (errors.length) { + _err = __("Error deploying contracts. Please fix errors to continue."); + self.logger.error(_err); + return done(_err); + } + if (contracts.length === 0) { + self.logger.info(__("no contracts found")); + return done(); + } + self.logger.info(__("finished deploying contracts")); + done(err); + }); + } catch (e) { + self.logger.error(e.message || e); + done(__('Error deploying')); + } } - contractDeploys[className] = cloneDeep(contractDependencies[className]); - contractDeploys[className].push(deploy); - }); - - try { - async.auto(contractDeploys, function(_err, _results) { - if (errors.length) { - _err = __("Error deploying contracts. Please fix errors to continue."); - self.logger.error(_err); - return done(_err); - } - if (contracts.length === 0) { - self.logger.info(__("no contracts found")); - return done(); - } - self.logger.info(__("finished deploying contracts")); - done(err); - }); - } catch (e) { - self.logger.error(e.message || e); - done(__('Error deploying')); - } + ]); }); }); } diff --git a/lib/modules/deploytracker/index.js b/lib/modules/deploytracker/index.js index 54b17aed7..274e9f098 100644 --- a/lib/modules/deploytracker/index.js +++ b/lib/modules/deploytracker/index.js @@ -19,7 +19,7 @@ class DeployTracker { registerEvents() { const self = this; - this.events.on("deploy:beforeAll", this.setCurrentChain.bind(this)); + this.embark.registerActionForEvent("deploy:beforeAll", this.setCurrentChain.bind(this)); this.events.on("deploy:contract:deployed", (contract) => { self.trackContract(contract.className, contract.realRuntimeBytecode, contract.realArgs, contract.deployedAddress); @@ -43,15 +43,12 @@ class DeployTracker { }); } - // TODO: just an event might not be enought to the async nature - // it needs to be a plugin api before deploy, that makes the deployment wait - setCurrentChain() { + setCurrentChain(cb) { const self = this; if (this.chainConfig === false) { this.currentChain = {contracts: []}; - //return cb(); + return cb(); } - this.events.request("blockchain:block:byNumber", 0, function(_err, block) { let chainId = block.hash; @@ -62,7 +59,7 @@ class DeployTracker { self.currentChain = self.chainConfig[chainId]; self.currentChain.name = self.env; - //cb(); + cb(); }); }