move contractsState emit to contracts

This commit is contained in:
Iuri Matias 2018-05-20 20:26:15 -04:00 committed by Jonathan Rainville
parent 250e0b8798
commit 98c5b2dd06
2 changed files with 13 additions and 8 deletions

View File

@ -33,6 +33,18 @@ class ContractsManager {
self.events.setCommandHandler("contracts:contract", (contractName, cb) => { self.events.setCommandHandler("contracts:contract", (contractName, cb) => {
cb(self.getContract(contractName)); cb(self.getContract(contractName));
}); });
self.events.on("deploy:contract:error", (_contract) => {
self.events.emit('contractsState', self.contractsState());
});
self.events.on("deploy:contract:deployed", (_contract) => {
self.events.emit('contractsState', self.contractsState());
});
self.events.on("deploy:contract:undeployed", (_contract) => {
self.events.emit('contractsState', self.contractsState());
});
} }
build(done) { build(done) {

View File

@ -13,8 +13,6 @@ class Deploy {
this.contractsManager = options.contractsManager; this.contractsManager = options.contractsManager;
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.env = options.env;
this.chainConfig = options.chainConfig;
this.plugins = options.plugins; this.plugins = options.plugins;
this.gasLimit = options.gasLimit; this.gasLimit = options.gasLimit;
} }
@ -68,7 +66,7 @@ class Deploy {
contract.error = false; contract.error = false;
if (contract.deploy === false) { if (contract.deploy === false) {
self.events.emit('contractsState', self.contractsManager.contractsState()); self.events.emit("deploy:contract:undeployed", contract);
return callback(); return callback();
} }
@ -82,13 +80,11 @@ class Deploy {
self.logger.error(e.message); self.logger.error(e.message);
contract.error = e.message; contract.error = e.message;
self.events.emit("deploy:contract:error", contract); self.events.emit("deploy:contract:error", contract);
self.events.emit('contractsState', self.contractsManager.contractsState());
return callback(e.message); return callback(e.message);
} }
contract.deployedAddress = contract.address; contract.deployedAddress = contract.address;
self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + contract.address.bold.cyan); self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + contract.address.bold.cyan);
self.events.emit("deploy:contract:deployed", contract); self.events.emit("deploy:contract:deployed", contract);
self.events.emit('contractsState', self.contractsManager.contractsState());
return callback(); return callback();
} }
@ -113,7 +109,6 @@ class Deploy {
self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + trackedContract.address.bold.cyan); self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + trackedContract.address.bold.cyan);
contract.deployedAddress = trackedContract.address; contract.deployedAddress = trackedContract.address;
self.events.emit("deploy:contract:deployed", contract); self.events.emit("deploy:contract:deployed", contract);
self.events.emit('contractsState', self.contractsManager.contractsState());
// always run contractCode so other functionality like 'afterDeploy' can also work // always run contractCode so other functionality like 'afterDeploy' can also work
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
@ -130,12 +125,10 @@ class Deploy {
this.deployContract(contract, contract.realArgs, function (err, address) { this.deployContract(contract, contract.realArgs, function (err, address) {
if (err) { if (err) {
self.events.emit("deploy:contract:error", contract); self.events.emit("deploy:contract:error", contract);
self.events.emit('contractsState', self.contractsManager.contractsState());
return callback(new Error(err)); return callback(new Error(err));
} }
contract.address = address; contract.address = address;
self.events.emit("deploy:contract:deployed", contract); self.events.emit("deploy:contract:deployed", contract);
self.events.emit('contractsState', self.contractsManager.contractsState());
// always run contractCode so other functionality like 'afterDeploy' can also work // always run contractCode so other functionality like 'afterDeploy' can also work
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});