diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index be4207d42..85e1b466d 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 38874c115..96426502d 100644 --- a/lib/contracts/deploy_tracker.js +++ b/lib/contracts/deploy_tracker.js @@ -59,4 +59,3 @@ class DeployTracker { } module.exports = DeployTracker; -