From e69b8bab561df398e854cd627d915c3d5848d446 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 22 May 2018 15:46:02 -0400 Subject: [PATCH] conflict in en.json --- lib/cmd.js | 2 ++ lib/constants.json | 3 +- lib/core/engine.js | 75 +++++++++++++++++++++++++++++++++++++++++++++- lib/index.js | 6 ++-- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index 553103f2..78bc976b 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -94,6 +94,7 @@ class Cmd { .command('build [environment]') .option('--contracts', 'only compile contracts into Embark wrappers') .option('--logfile [logfile]', __('filename to output logs (default: none)')) + .option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc')) .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug') .option('--locale [locale]', __('language to use (default: en)')) .description(__('deploy and build dapp at ') + 'dist/ (default: development)') @@ -103,6 +104,7 @@ class Cmd { _options.logFile = _options.logfile; // fix casing _options.logLevel = _options.loglevel; // fix casing _options.onlyCompile = _options.contracts; + _options.client = _options.client || 'geth'; embark.build(_options); }); } diff --git a/lib/constants.json b/lib/constants.json index 16e13e30..c2c44c36 100644 --- a/lib/constants.json +++ b/lib/constants.json @@ -33,6 +33,7 @@ "blockchain": { "blockchainReady": "blockchainReady", "init": "init", - "initiated": "initiated" + "initiated": "initiated", + "engineReady": "engineReady" } } diff --git a/lib/core/engine.js b/lib/core/engine.js index 347aa5b4..78beadf5 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -19,6 +19,8 @@ const ProcessLauncher = require('../process/processLauncher'); const utils = require('../utils/utils'); const constants = require('../constants'); +const STARTING_BLOCKCHAIN = 'startBlockchain'; + class Engine { constructor(options) { this.env = options.env; @@ -254,7 +256,7 @@ class Engine { }); if (!options.web3) { // Web3 object might have been modified - self.events.once('engine-ready', () => { + self.onReady(() => { self.deployManager.web3 = self.web3; }); } @@ -311,6 +313,77 @@ class Engine { }); } + onReady(callback) { + if (this.isReady) { + return callback(); + } + this.events.once(constants.blockchain.engineReady, () => { + callback(); + }); + } + + checkWeb3Status(web3Endpoint, callback) { + const self = this; + const NO_NODE = 'noNode'; + const noNodeObj = {name: __("No Blockchain node found"), status: 'off'}; + async.waterfall([ + function checkCurrentProvider(next) { + if (self.web3.currentProvider === undefined) { + return next(NO_NODE); + } + next(); + }, + function pingWeb3Endpoint(next) { + // FIXME: this is needed currently because the provider (MetaMask/provider-engine) doesn't callback when there is no node + request.get(web3Endpoint, function (err, _response, _body) { + if (err) { + return next(NO_NODE); + } + next(); + }); + }, + function checkAccount(next) { + self.web3.eth.getAccounts(function(err, _accounts) { + if (err) { + return next(NO_NODE); + } + next(); + }); + }, + function getWeb3ClientVersion(next) { + // TODO: web3_clientVersion method is currently not implemented in web3.js 1.0 + self.web3._requestManager.send({method: 'web3_clientVersion', params: []}, (err, version) => { + if (err) { + return next({name: __("Ethereum node (version unknown)"), status: 'on'}); + } + if (version.indexOf("/") < 0) { + return next({name: version, status: 'on'}); + } + let nodeName = version.split("/")[0]; + let versionNumber = version.split("/")[1].split("-")[0]; + let name = nodeName + " " + versionNumber + " (Ethereum)"; + + return next({name: name, status: 'on'}); + }); + } + ], (msg) => { + if (msg === NO_NODE) { + if (self.isRunningBlockchain) { + return callback(noNodeObj); + } + // Start blockchain node ourselves + self.stopWeb3Service(); + self.startBlockchainNode(); + return callback(STARTING_BLOCKCHAIN); + } + if (!self.isReady) { + self.isReady = true; + self.events.emit(constants.blockchain.engineReady); + } + callback(msg); + }); + } + web3Service(options) { this.blockchain = new Blockchain({ contractsConfig: this.config.contractsConfig, diff --git a/lib/index.js b/lib/index.js index 7a37807f..5ad42cfd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -151,7 +151,7 @@ class Embark { engine.logger.info(__("Ready").underline); engine.events.emit("status", __("Ready").green); }); - engine.events.once('engine-ready', function () { + engine.onReady(() => { engine.deployManager.deployContracts(function (err) { engine.startService("fileWatcher"); if (options.runWebserver) { @@ -184,6 +184,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: 'embark.json', @@ -217,7 +219,7 @@ class Embark { callback(); }, function deploy(callback) { - engine.events.once('engine-ready', function () { + engine.onReady(() => { engine.deployManager.deployContracts(function (err) { callback(err); });