From 98c5b2dd0662cba3ad22cc6a5e6d856b6c1d883e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 20 May 2018 20:26:15 -0400 Subject: [PATCH] move contractsState emit to contracts --- lib/contracts/contracts.js | 12 ++++++++++++ lib/contracts/deploy.js | 9 +-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 52f49d36d..d55ae0f99 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -33,6 +33,18 @@ class ContractsManager { self.events.setCommandHandler("contracts:contract", (contractName, cb) => { 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) { diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index f42514d50..ae86d9ac5 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -13,8 +13,6 @@ class Deploy { this.contractsManager = options.contractsManager; this.logger = options.logger; this.events = options.events; - this.env = options.env; - this.chainConfig = options.chainConfig; this.plugins = options.plugins; this.gasLimit = options.gasLimit; } @@ -68,7 +66,7 @@ class Deploy { contract.error = false; if (contract.deploy === false) { - self.events.emit('contractsState', self.contractsManager.contractsState()); + self.events.emit("deploy:contract:undeployed", contract); return callback(); } @@ -82,13 +80,11 @@ class Deploy { self.logger.error(e.message); contract.error = e.message; self.events.emit("deploy:contract:error", contract); - self.events.emit('contractsState', self.contractsManager.contractsState()); 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); - self.events.emit('contractsState', self.contractsManager.contractsState()); return callback(); } @@ -113,7 +109,6 @@ class Deploy { self.logger.info(contract.className.bold.cyan + __(" already deployed at ").green + trackedContract.address.bold.cyan); contract.deployedAddress = trackedContract.address; 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 let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); @@ -130,12 +125,10 @@ class Deploy { this.deployContract(contract, contract.realArgs, function (err, address) { if (err) { self.events.emit("deploy:contract:error", contract); - self.events.emit('contractsState', self.contractsManager.contractsState()); return callback(new Error(err)); } contract.address = address; 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 let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});