enable node=embark

This commit is contained in:
Jonathan Rainville 2018-08-23 12:54:43 -04:00
parent 3f561f5257
commit 86f1cf51d2
6 changed files with 36 additions and 6 deletions

View File

@ -213,7 +213,8 @@ class Engine {
web3Service(options) {
this.registerModule('blockchain_process', {
locale: this.locale,
isDev: this.isDev
isDev: this.isDev,
ipc: this.ipc
});
this.registerModule('blockchain_connector', {

View File

@ -13,6 +13,7 @@ class BlockchainModule {
this.embark = embark;
this.locale = options.locale;
this.isDev = options.isDev;
this.ipc = options.ipc;
this.registerBlockchainProcess();
}
@ -25,6 +26,11 @@ class BlockchainModule {
self.startBlockchainNode(cb);
});
});
if (!this.ipc.isServer()) return;
self.ipc.on('blockchain:node', (_message, cb) => {
cb(null, utils.buildUrlFromConfig(self.contractsConfig.deployment));
});
}
assertNodeConnection(noLogs, cb) {
@ -47,7 +53,7 @@ class BlockchainModule {
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
return next();
}
const {host, port, type, protocol} = self.contractsConfig.deployment;
const {host, port, type, protocol} = self.contractsConfig.deployment;
utils.pingEndpoint(host, port, type, protocol, self.blockchainConfig.wsOrigins.split(',')[0], next);
}
], function (err) {

View File

@ -21,6 +21,10 @@ class SolcW {
return self.load_compiler_internally(done);
}
if (self.ipc.connected) {
self.compilerLoaded = true;
return done();
}
self.ipc.connect((err) => {
if (err) {
return self.load_compiler_internally(done);

View File

@ -136,7 +136,7 @@ class Pipeline {
], function (err, contentFile) {
if (err) {
self.logger.error(err);
self.logger.error(err.message || err);
return fileCb(err);
}

View File

@ -139,6 +139,20 @@ class Test {
this.initDeployServices();
this.engine.startService("codeGenerator");
if (this.options.node === 'embark') {
return this.engine.ipc.connect((err) => {
if (err) {
return this.engine.logger.error(err.message || err);
}
this.engine.ipc.request('blockchain:node', {}, (err, node) => {
if (err) {
return this.engine.logger.error(err.message || err);
}
this.options.node = node;
callback();
});
});
}
callback();
}

View File

@ -340,13 +340,18 @@ function normalizeInput(input) {
* The URL host, required.
* @param {string} port
* The URL port, default to empty string.
* @param {string} [type]
* Type of connection
* @returns {string} the constructued URL, with defaults
*/
function buildUrl(protocol, host, port) {
function buildUrl(protocol, host, port, type) {
if (!host) throw new Error('utils.buildUrl: parameter \'host\' is required');
if (port) port = ':' + port;
else port = '';
return `${protocol || 'http'}://${host}${port}`;
if (!protocol) {
protocol = type === 'ws' ? 'ws' : 'http';
}
return `${protocol}://${host}${port}`;
}
/**
@ -361,7 +366,7 @@ function buildUrl(protocol, host, port) {
function buildUrlFromConfig(configObj) {
if (!configObj) throw new Error('[utils.buildUrlFromConfig]: config object must cannot be null');
if (!configObj.host) throw new Error('[utils.buildUrlFromConfig]: object must contain a \'host\' property');
return this.buildUrl(configObj.protocol, canonicalHost(configObj.host), configObj.port);
return this.buildUrl(configObj.protocol, canonicalHost(configObj.host), configObj.port, configObj.type);
}
function deconstructUrl(endpoint) {