diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index afdd72b7a..632596ba7 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 447a3f57f..0c21e642c 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 582238b88..9eddfd515 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/dashboard/console.js b/lib/dashboard/console.js index edd3feff3..c78a97821 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -22,6 +22,7 @@ class Console { 'versions - ' + __('display versions in use for libraries and tools like web3 and solc'), // TODO: only if the blockchain is actually active! // will need to pass te current embark state here + 'ipfs - ' + __('instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)'), 'web3 - ' + __('instantiated web3.js object configured to the current environment'), 'quit - ' + __('to immediatly exit (alias: exit)'), '', diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index d5a310708..9f8507e25 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -1,6 +1,8 @@ let UploadIPFS = require('./upload.js'); let utils = require('../../utils/utils.js'); let fs = require('../../core/fs.js'); +let RunCode = require('../../core/runCode.js'); +let IpfsApi = require('ipfs-api'); class IPFS { @@ -18,6 +20,7 @@ class IPFS { this.setServiceCheck(); this.addIPFSToEmbarkJS(); this.addSetProvider(); + this.addIpfsObjectToConsole(); } commandlineDeploy() { @@ -111,6 +114,12 @@ class IPFS { this.embark.addProviderInit('storage', code, shouldInit); } + + addIpfsObjectToConsole() { + let ipfs = IpfsApi(this.storageConfig.host, this.storageConfig.port); + RunCode.doEval("", {ipfs: ipfs}); + } + } module.exports = IPFS; diff --git a/lib/tests/test.js b/lib/tests/test.js index 04877a8fa..1dd2967ea 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -104,7 +104,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); });