From 3fcc36a7a16e9bf41b1a1ebb0c0e7414cccadf77 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 18 May 2018 15:48:28 -0400 Subject: [PATCH] launch blockchain in separate process works but still cant getAccounts --- lib/cmd.js | 3 +++ lib/cmds/blockchain/blockchainProcess.js | 25 ++++++++++++++++++++++++ lib/core/engine.js | 25 +++++++++++++++++++++++- lib/index.js | 2 ++ lib/process/processLauncher.js | 9 +++++++-- 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 lib/cmds/blockchain/blockchainProcess.js diff --git a/lib/cmd.js b/lib/cmd.js index 081f3d89..553103f2 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -111,6 +111,7 @@ class Cmd { program .command('run [environment]') .option('-p, --port [port]', __('port to run the dev webserver (default: %s)', '8000')) + .option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc')) .option('-b, --host [host]', __('host to run the dev webserver (default: %s)', 'localhost')) .option('--noserver', __('disable the development webserver')) .option('--nodashboard', __('simple mode, disables the dashboard')) @@ -125,6 +126,8 @@ class Cmd { env: env || 'development', serverPort: options.port, serverHost: options.host, + client: options.client || 'geth', + locale: options.locale, runWebserver: !options.noserver, useDashboard: !options.nodashboard, logFile: options.logfile, diff --git a/lib/cmds/blockchain/blockchainProcess.js b/lib/cmds/blockchain/blockchainProcess.js new file mode 100644 index 00000000..f299afe7 --- /dev/null +++ b/lib/cmds/blockchain/blockchainProcess.js @@ -0,0 +1,25 @@ +const ProcessWrapper = require('../../process/processWrapper'); +const BlockchainClient = require('./blockchain'); +const i18n = require('../../i18n/i18n.js'); + +class BlockchainProcess extends ProcessWrapper { + constructor(options) { + super(); + this.blockchainConfig = options.blockchainConfig; + this.client = options.client; + this.env = options.env; + this.isDev = options.isDev; + + i18n.setOrDetectLocale(options.locale); + + this.blockchain = BlockchainClient(this.blockchainConfig, this.client, this.env, this.isDev); + this.blockchain.run(); + } +} + +process.on('message', (msg) => { + if (msg.action === 'init') { + const blockchainProcess = new BlockchainProcess(msg.options); + return process.send({result: 'initiated'}); + } +}); diff --git a/lib/core/engine.js b/lib/core/engine.js index a30c2e70..cfe5a758 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -14,12 +14,16 @@ const Watch = require('../pipeline/watch.js'); const LibraryManager = require('../versions/library_manager.js'); const CodeRunner = require('../coderunner/codeRunner.js'); const request = require('request'); -//const Provider = require('../contracts/provider'); + +const ProcessLauncher = require('../process/processLauncher'); +const utils = require('../utils/utils'); class Engine { constructor(options) { this.env = options.env; this.isDev = options.isDev; + this.client = options.client; + this.locale = options.locale; this.embarkConfig = options.embarkConfig; this.interceptLogs = options.interceptLogs; this.version = options.version; @@ -319,6 +323,25 @@ class Engine { }); } + startBlockchainNode() { + this.blockchainProcess = new ProcessLauncher({ + modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'), + logger: this.logger, + events: this.events, + normalizeInput: this.normalizeInput, + silent: true + }); + this.blockchainProcess.send({ + action: 'init', options: { + blockchainConfig: this.config.blockchainConfig, + client: this.client, + env: this.env, + isDev: this.isDev, + locale: this.locale + } + }); + } + libraryManagerService(_options) { this.libraryManager = new LibraryManager({ plugins: this.plugins, diff --git a/lib/index.js b/lib/index.js index 5e235dca..1b286df7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -86,6 +86,8 @@ class Embark { let engine = new Engine({ env: options.env, + client: options.client, + locale: options.locale, isDev: this.isDev(options.env), version: this.version, embarkConfig: options.embarkConfig || 'embark.json', diff --git a/lib/process/processLauncher.js b/lib/process/processLauncher.js index 18f6e68e..2c1a4d09 100644 --- a/lib/process/processLauncher.js +++ b/lib/process/processLauncher.js @@ -18,6 +18,7 @@ class ProcessLauncher { this.logger = options.logger; this.normalizeInput = options.normalizeInput; this.events = options.events; + this.silent = options.silent; this.subscriptions = {}; this._subscribeToMessages(); @@ -31,14 +32,18 @@ class ProcessLauncher { return self._handleLog(msg); } if (msg.event) { - return this._handleEvent(msg); + return self._handleEvent(msg); } - this._checkSubscriptions(msg); + self._checkSubscriptions(msg); }); } // Translates logs from the child process to the logger _handleLog(msg) { + if (this.silent) { + return; + } + console.log('Not silent????', this.silent); if (this.logger[msg.type]) { return this.logger[msg.type](this.normalizeInput(msg.message)); }