move contractsState from logger to event bus

This commit is contained in:
Iuri Matias 2018-02-27 15:40:05 -05:00
parent 96df409229
commit 66e9d6afa3
4 changed files with 11 additions and 10 deletions

View File

@ -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));
});
}

View File

@ -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,

View File

@ -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;
}
}

View File

@ -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);