detect no node using request
This commit is contained in:
parent
d1c3f36d02
commit
aea270af02
|
@ -1,4 +1,5 @@
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
|
const Provider = require('./provider.js');
|
||||||
|
|
||||||
class Blockchain {
|
class Blockchain {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -10,6 +11,8 @@ class Blockchain {
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
this.addCheck = options.addCheck;
|
this.addCheck = options.addCheck;
|
||||||
|
|
||||||
|
this.isWeb3Started = false;
|
||||||
|
|
||||||
if (!this.web3) {
|
if (!this.web3) {
|
||||||
this.initWeb3();
|
this.initWeb3();
|
||||||
}
|
}
|
||||||
|
@ -19,10 +22,25 @@ class Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
initWeb3() {
|
initWeb3() {
|
||||||
|
const self = this;
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
if (this.contractsConfig.deployment.type === "rpc") {
|
if (this.contractsConfig.deployment.type === "rpc") {
|
||||||
let web3Endpoint = 'http://' + this.contractsConfig.deployment.host + ':' + this.contractsConfig.deployment.port;
|
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint));
|
this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint));
|
||||||
|
|
||||||
|
let provider;
|
||||||
|
let web3Endpoint = 'http://' + this.contractsConfig.deployment.host + ':' + this.contractsConfig.deployment.port;
|
||||||
|
const providerOptions = {
|
||||||
|
web3: this.web3,
|
||||||
|
accountsConfig: this.contractsConfig.deployment.accounts,
|
||||||
|
logger: this.logger,
|
||||||
|
isDev: this.isDev,
|
||||||
|
web3Endpoint
|
||||||
|
};
|
||||||
|
provider = new Provider(providerOptions);
|
||||||
|
|
||||||
|
provider.startWeb3Provider(() => {
|
||||||
|
self.isWeb3Started = true;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error("contracts config error: unknown deployment type " + this.contractsConfig.deployment.type);
|
throw new Error("contracts config error: unknown deployment type " + this.contractsConfig.deployment.type);
|
||||||
}
|
}
|
||||||
|
@ -133,13 +151,22 @@ class Blockchain {
|
||||||
return cb(Error("error connecting to blockchain node"));
|
return cb(Error("error connecting to blockchain node"));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.getAccounts(function(err, _accounts) {
|
// TODO: refactor this
|
||||||
|
request.get(web3Endpoint, function (err, _response, _body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.error(("Couldn't connect to an Ethereum node are you sure it's on?").red);
|
self.logger.error(("Couldn't connect to an Ethereum node are you sure it's on?").red);
|
||||||
self.logger.info("make sure you have an Ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
self.logger.info("make sure you have an Ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
||||||
return cb(Error("error connecting to blockchain node"));
|
return cb(Error("error connecting to blockchain node"));
|
||||||
}
|
}
|
||||||
return cb();
|
|
||||||
|
self.getAccounts(function(err, _accounts) {
|
||||||
|
if (err) {
|
||||||
|
self.logger.error(("Couldn't connect to an Ethereum node are you sure it's on?").red);
|
||||||
|
self.logger.info("make sure you have an Ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
||||||
|
return cb(Error("error connecting to blockchain node"));
|
||||||
|
}
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ const Pipeline = require('../pipeline/pipeline.js');
|
||||||
const Watch = require('../pipeline/watch.js');
|
const Watch = require('../pipeline/watch.js');
|
||||||
const LibraryManager = require('../versions/library_manager.js');
|
const LibraryManager = require('../versions/library_manager.js');
|
||||||
const CodeRunner = require('../coderunner/codeRunner.js');
|
const CodeRunner = require('../coderunner/codeRunner.js');
|
||||||
|
const request = require('request');
|
||||||
|
//const Provider = require('../contracts/provider');
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -304,6 +306,7 @@ class Engine {
|
||||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||||
events: this.events,
|
events: this.events,
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
|
isDev: this.isDev,
|
||||||
web3: options.web3
|
web3: options.web3
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue