diff --git a/packages/embark-ipfs/src/index.js b/packages/embark-ipfs/src/index.js index 3c4d468ef..32a4f507b 100644 --- a/packages/embark-ipfs/src/index.js +++ b/packages/embark-ipfs/src/index.js @@ -124,11 +124,13 @@ class IPFS { // TODO: should be done in embarkjs-ipfs // TODO: check config, etc.. registerAndSetIpfs() { + // TODO: this should be at the start const code = ` const __embarkIPFS = require('embarkjs-ipfs'); EmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS); `; + // TODO: this should be done when a connection is detected this.events.request('runcode:eval', code, (err) => { let providerCode = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this.embark.config.storageConfig.dappConnection || [])}, {web3});`; this.events.request('runcode:eval', providerCode, (err) => { diff --git a/packages/embark-storage/src/index.js b/packages/embark-storage/src/index.js index 87cf82da1..37c34e062 100644 --- a/packages/embark-storage/src/index.js +++ b/packages/embark-storage/src/index.js @@ -4,31 +4,30 @@ import * as async from 'async'; class Storage { constructor(embark, options){ this.embark = embark; + this.embarkConfig = embark.config.embarkConfig; + this.events = this.embark.events; + this.storageConfig = embark.config.storageConfig; this.plugins = options.plugins; - this.ready = false; + let plugin = this.plugins.createPlugin('storageplugin', {}); - this.embark.events.setCommandHandler("module:storage:onReady", (cb) => { - if (this.ready) { - return cb(); - } - this.embark.events.once("module:storage:ready", cb); - }); + // this.handleUploadCommand(); + // this.addSetProviders(() => {}); + plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this)); - this.embark.events.setCommandHandler("module:storageJS:reset", (cb) => { - if (!this.isEnabled()) { - return cb(); - } - this.ready = false; - this.addSetProviders(cb); - }); + // TODO: register xyz (e.g ipfs) to check for dappConnectionConfig + } - if (!this.isEnabled()) { - this.ready = true; - return; - } + addArtifactFile(_params, cb) { + let config = { + dappConnection: this.storageConfig.dappConnection + }; - this.handleUploadCommand(); - this.addSetProviders(() => {}); + this.events.request("pipeline:register", { + path: [this.embarkConfig.generationDir, 'config'], + file: 'communication.json', + format: 'json', + content: config + }, cb); } isEnabled() { diff --git a/packages/embark-whisper/src/index.js b/packages/embark-whisper/src/index.js index 0414f37af..46f2ea666 100644 --- a/packages/embark-whisper/src/index.js +++ b/packages/embark-whisper/src/index.js @@ -13,11 +13,13 @@ class Whisper { this.events = embark.events; this.fs = embark.fs; this.communicationConfig = embark.config.communicationConfig; + this.embarkConfig = embark.config.embarkConfig; this.web3 = new Web3(); this.embark = embark; this.web3Ready = false; this.webSocketsChannels = {}; this.modulesPath = dappPath(embark.config.embarkConfig.generationDir, constants.dappArtifacts.symlinkDir); + this.plugins = options.plugins; if (embark.currentContext.includes('test') && options.node &&options.node === 'vm') { this.logger.info(__('Whisper disabled in the tests')); @@ -48,6 +50,9 @@ class Whisper { this.registerAndSetWhisper(); }); + let plugin = this.plugins.createPlugin('whisperplugin', {}); + plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this)); + // =============================== // this.connectToProvider(); @@ -73,6 +78,21 @@ class Whisper { // this.events.request('processes:launch', 'whisper'); } + // TODO: should load the latest config + addArtifactFile(_params, cb) { + let config = { + // TODO: for consistency we should change this to be dappConnection or connection + connection: this.communicationConfig.connection + }; + + this.events.request("pipeline:register", { + path: [this.embarkConfig.generationDir, 'config'], + file: 'storage.json', + format: 'json', + content: config + }, cb); + } + connectToProvider() { let {host, port} = this.communicationConfig.connection; let web3Endpoint = 'ws://' + host + ':' + port; diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 652346e79..a52f9d762 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -277,9 +277,9 @@ class Engine { } storageService(_options) { + this.registerModulePackage('embark-storage', {plugins: this.plugins}); this.registerModulePackage('embark-ipfs'); // this.registerModulePackage('embark-swarm'); - // this.registerModulePackage('embark-storage', {plugins: this.plugins}); // this.events.setCommandHandler("module:storage:reset", (cb) => { // async.parallel([ @@ -298,6 +298,7 @@ class Engine { web3Service(options) { this.registerModulePackage('embark-web3'); + this.registerModule('blockchain', { plugins: this.plugins }); this.registerModulePackage('embark-blockchain-process', { client: this.client, @@ -314,7 +315,7 @@ class Engine { wait: options.wait }); - this.registerModulePackage('embark-whisper'); + this.registerModulePackage('embark-whisper', { plugins: this.plugins }); this.registerModule('web3', { plugins: this.plugins }); } diff --git a/packages/embark/src/lib/modules/blockchain/index.js b/packages/embark/src/lib/modules/blockchain/index.js new file mode 100644 index 000000000..4a7b005a4 --- /dev/null +++ b/packages/embark/src/lib/modules/blockchain/index.js @@ -0,0 +1,36 @@ + +class Blockchain { + + constructor(embark, options) { + this.embarkConfig = embark.config.embarkConfig; + this.logger = embark.logger; + this.events = embark.events; + this.blockchainConfig = embark.config.blockchainConfig; + this.contractConfig = embark.config.contractConfig; + this.plugins = options.plugins; + let plugin = this.plugins.createPlugin('web3plugin', {}); + + plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this)); + } + + addArtifactFile(_params, cb) { + this.events.request("config:contractsConfig", (contractsConfig) => { + let config = { + dappConnection: contractsConfig.dappConnection, + dappAutoEnable: contractsConfig.dappAutoEnable, + warnIfMetamask: this.blockchainConfig.isDev, + blockchainClient: this.blockchainConfig.client + }; + + this.events.request("pipeline:register", { + path: [this.embarkConfig.generationDir, 'config'], + file: 'blockchain.json', + format: 'json', + content: config + }, cb); + }); + } + +} + +module.exports = Blockchain;