From 750eace6ceb4f3317993428694c6bfe8b0bd9c0d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 27 Dec 2017 11:40:21 -0500 Subject: [PATCH] always define contract code so ondeploy cmds work --- lib/contracts/deploy.js | 12 +++++++++++- lib/contracts/deploy_manager.js | 5 ++++- lib/core/runCode.js | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index beedfa829..be4207d42 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -61,6 +61,12 @@ class Deploy { 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()); + + // always run contractCode so other functionality like 'afterDeploy' can also work + let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); + let contractCode = codeGenerator.generateContractCode(contract); + RunCode.doEval(contractCode, self.web3); + return callback(); } else { @@ -74,9 +80,13 @@ class Deploy { self.deployTracker.save(); self.logger.contractsState(self.contractsManager.contractsState()); + // always run contractCode so other functionality like 'afterDeploy' can also work + let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); + let contractCode = codeGenerator.generateContractCode(contract); + RunCode.doEval(contractCode, self.web3); + if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); - let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); let cmds = ""; cmds += codeGenerator.generateContractCode(contract); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index b6297489a..3f9990c6b 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -117,7 +117,10 @@ class DeployManager { return callback(new Error("error running afterDeploy")); } - RunCode.doEval(onDeployCode.join(';\n'), web3); + onDeployCode.forEach((cmd) => { + self.logger.info("executing: " + cmd); + RunCode.doEval(cmd, web3); + }); callback(null, contractsManager); } diff --git a/lib/core/runCode.js b/lib/core/runCode.js index 43bf4ea89..414776374 100644 --- a/lib/core/runCode.js +++ b/lib/core/runCode.js @@ -14,6 +14,7 @@ function doEval(code, _web3) { } try { + // TODO: add trace log here return eval(code); // jshint ignore:line } catch(e) { throw new Error(e + "\n" + code);