From 66e9d6afa35cf9d5155bfdee1f0471d04253926a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 27 Feb 2018 15:40:05 -0500 Subject: [PATCH] move contractsState from logger to event bus --- lib/contracts/deploy.js | 15 ++++++++------- lib/contracts/deploy_manager.js | 1 + lib/core/logger.js | 2 -- lib/dashboard/dashboard.js | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index fb0c1c65f..58f644ecf 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -11,6 +11,7 @@ class Deploy { this.web3 = options.web3; this.contractsManager = options.contractsManager; this.logger = options.logger; + this.events = options.events; this.env = options.env; this.chainConfig = options.chainConfig; this.plugins = options.plugins; @@ -46,7 +47,7 @@ class Deploy { contract.error = false; if (contract.deploy === false) { - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); return callback(); } @@ -58,7 +59,7 @@ class Deploy { self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, contract.address); self.deployTracker.save(); } - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); return callback(); } @@ -84,7 +85,7 @@ class Deploy { const self = this; self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan); contract.deployedAddress = trackedContract.address; - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); // always run contractCode so other functionality like 'afterDeploy' can also work let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); @@ -104,7 +105,7 @@ class Deploy { } self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, address); self.deployTracker.save(); - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); // always run contractCode so other functionality like 'afterDeploy' can also work let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); @@ -298,12 +299,12 @@ class Deploy { self.logger.info(contract.className.bold.cyan + " deployed at ".green + receipt.contractAddress.bold.cyan); contract.deployedAddress = receipt.contractAddress; contract.transactionHash = receipt.transactionHash; - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); return next(null, receipt.contractAddress); } - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); }).on('error', function(error) { - self.logger.contractsState(self.contractsManager.contractsState()); + self.events.emit('contractsState', self.contractsManager.contractsState()); return next(new Error("error deploying =" + contract.className + "= due to error: " + error.message)); }); } diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index d79682c25..72502bbc3 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -68,6 +68,7 @@ class DeployManager { web3: web3, contractsManager: contractsManager, logger: self.logger, + events: self.events, chainConfig: self.chainConfig, env: self.config.env, plugins: self.plugins, diff --git a/lib/core/logger.js b/lib/core/logger.js index 3877fb407..49de081e8 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -5,8 +5,6 @@ class Logger { this.logLevels = ['error', 'warn', 'info', 'debug', 'trace']; this.logLevel = options.logLevel || 'info'; this.logFunction = options.logFunction || console.log; - this.contractsState = options.contractsState || function () { - }; this.setStatus = options.setStatus || console.log; } } diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index bac332823..0c06d68fe 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -30,9 +30,10 @@ class Dashboard { function startMonitor(callback) { monitor = new Monitor({env: self.env, console: console}); self.logger.logFunction = monitor.logEntry; - self.logger.contractsState = monitor.setContracts; self.logger.setStatus = monitor.setStatus.bind(monitor); + self.events.on('contractsState', monitor.setContracts); + self.logger.info('========================'.bold.green); self.logger.info(('Welcome to Embark ' + self.version).yellow.bold); self.logger.info('========================'.bold.green);