From e2c2373249f21512524dc434a3e9a71e9ed53205 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 18 May 2018 15:55:34 -0400 Subject: [PATCH] accept hash of objects as second param for runcode --- lib/contracts/deploy.js | 8 ++++---- lib/contracts/deploy_manager.js | 2 +- lib/core/runCode.js | 10 +++++++--- lib/tests/test.js | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index afdd72b7..632596ba 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -131,7 +131,7 @@ class Deploy { // always run contractCode so other functionality like 'afterDeploy' can also work let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); - RunCode.doEval(contractCode, self.web3); + RunCode.doEval(contractCode, {web3: self.web3}); return callback(); } @@ -151,13 +151,13 @@ class Deploy { // always run contractCode so other functionality like 'afterDeploy' can also work let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); - RunCode.doEval(contractCode, self.web3); + RunCode.doEval(contractCode, {web3: self.web3}); if (contract.onDeploy !== undefined) { self.logger.info(__('executing onDeploy commands')); let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); - RunCode.doEval(contractCode, self.web3); + RunCode.doEval(contractCode, {web3: self.web3}); let withErrors = false; let regex = /\$\w+/g; @@ -200,7 +200,7 @@ class Deploy { for(let cmd of onDeployCode) { self.logger.info(__("executing: ") + cmd); try { - RunCode.doEval(cmd, self.web3); + RunCode.doEval(cmd, {web3: 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')); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 447a3f57..0c21e642 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -137,7 +137,7 @@ class DeployManager { for(let cmd of onDeployCode) { self.logger.info(__("executing") + ": " + cmd); try { - RunCode.doEval(cmd, web3); + RunCode.doEval(cmd, {web3: 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')); diff --git a/lib/core/runCode.js b/lib/core/runCode.js index 582238b8..9eddfd51 100644 --- a/lib/core/runCode.js +++ b/lib/core/runCode.js @@ -1,6 +1,7 @@ /*eslint no-unused-vars: off*/ let Web3 = require('web3'); let web3; +let ipfs; let __mainContext; // ====================== @@ -8,9 +9,12 @@ let __mainContext; // this should be at least moved to a different process and scope // for now it is defined here // ====================== -function doEval(code, _web3) { - if (_web3) { - web3 = _web3; +function doEval(code, opts) { + if (opts && opts.web3) { + web3 = opts.web3; + } + if (opts && opts.ipfs) { + ipfs = opts.ipfs; } try { diff --git a/lib/tests/test.js b/lib/tests/test.js index b79f81c1..defb8a6b 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -107,7 +107,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) { throw new Error(err); } self.web3.eth.defaultAccount = accounts[0]; - RunCode.doEval(result, self.web3); + RunCode.doEval(result, {web3: self.web3}); //cb(); cb(accounts); });