From ab5d3722b9f61ee035d8b921b48712fee017d685 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 28 Dec 2017 08:27:20 -0500 Subject: [PATCH] fix issue where contract was being deployed everytime when gas config was set; catch errors on individual onDeploy cmds --- lib/contracts/deploy.js | 26 +++++++++++++++++--------- lib/contracts/deploy_tracker.js | 1 - 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index be4207d4..85e1b466 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -44,10 +44,9 @@ class Deploy { return callback(); } + realArgs = self.determineArguments(params || contract.args); + if (contract.address !== undefined) { - - realArgs = self.determineArguments(params || contract.args); - contract.deployedAddress = contract.address; self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, contract.address); self.deployTracker.save(); @@ -55,7 +54,7 @@ class Deploy { return callback(); } - let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args); + let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, realArgs); if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") { self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan); @@ -88,8 +87,8 @@ class Deploy { if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); - let cmds = ""; - cmds += codeGenerator.generateContractCode(contract); + let contractCode = codeGenerator.generateContractCode(contract); + RunCode.doEval(contractCode, self.web3); let withErrors = false; let regex = /\$\w+/g; @@ -128,9 +127,18 @@ class Deploy { return callback(new Error("error running onDeploy")); } - cmds += onDeployCode.join(';\n'); - - RunCode.doEval(cmds, self.web3); + // TODO: convert to for to avoid repeated callback + for(let cmd of onDeployCode) { + self.logger.info("executing: " + cmd); + try { + RunCode.doEval(cmd, self.web3); + } catch(e) { + if (e.message.indexOf("invalid opcode") >= 0) { + self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation'); + } + return callback(new Error(e)); + } + } } callback(); diff --git a/lib/contracts/deploy_tracker.js b/lib/contracts/deploy_tracker.js index 38874c11..96426502 100644 --- a/lib/contracts/deploy_tracker.js +++ b/lib/contracts/deploy_tracker.js @@ -59,4 +59,3 @@ class DeployTracker { } module.exports = DeployTracker; -