Merge pull request #441 from embark-framework/ipfs_object

make Ipfs object available in environment
This commit is contained in:
RJ Catalano 2018-05-21 10:31:30 -05:00 committed by GitHub
commit 6bcf03adc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 9 deletions

View File

@ -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'));

View File

@ -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'));

View File

@ -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 {

View File

@ -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)'),
'',

View File

@ -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;

View File

@ -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);
});