In case of ws, use the connected attribute
Instead of relying on non reliable source, directly check the ws status
This commit is contained in:
parent
47dcb1552c
commit
27973461b1
|
@ -130,7 +130,7 @@ class BlockchainConnector {
|
||||||
this.events.request("services:register", 'Ethereum', function (cb) {
|
this.events.request("services:register", 'Ethereum', function (cb) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function checkNodeConnection(next) {
|
function checkNodeConnection(next) {
|
||||||
if (!self.web3.currentProvider) {
|
if (!self.provider || !self.provider.connected()) {
|
||||||
return next(NO_NODE, {name: "No Blockchain node found", status: 'off'});
|
return next(NO_NODE, {name: "No Blockchain node found", status: 'off'});
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -26,8 +26,8 @@ class Provider {
|
||||||
// The best choice is to use void origin, BUT Geth rejects void origin, so to keep both clients happy we can use http://embark
|
// The best choice is to use void origin, BUT Geth rejects void origin, so to keep both clients happy we can use http://embark
|
||||||
self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "http://embark"}});
|
self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "http://embark"}});
|
||||||
|
|
||||||
self.provider.on('error', e => self.logger.error('Websocket Error', e));
|
self.provider.on('error', () => self.logger.error('Websocket Error'));
|
||||||
self.provider.on('end', e => self.logger.error('Websocket connection ended', e));
|
self.provider.on('end', () => self.logger.error('Websocket connection ended'));
|
||||||
} else {
|
} else {
|
||||||
return callback(__("contracts config error: unknown deployment type %s", this.type));
|
return callback(__("contracts config error: unknown deployment type %s", this.type));
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,16 @@ class Provider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connected() {
|
||||||
|
if (this.type === 'rpc') {
|
||||||
|
return !!this.provider;
|
||||||
|
} else if (this.type === 'ws') {
|
||||||
|
return this.provider && this.provider.connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if (this.provider && this.provider.removeAllListeners) {
|
if (this.provider && this.provider.removeAllListeners) {
|
||||||
this.provider.removeAllListeners('connect');
|
this.provider.removeAllListeners('connect');
|
||||||
|
@ -79,8 +89,9 @@ class Provider {
|
||||||
this.provider.removeAllListeners('end');
|
this.provider.removeAllListeners('end');
|
||||||
this.provider.removeAllListeners('data');
|
this.provider.removeAllListeners('data');
|
||||||
this.provider.responseCallbacks = {};
|
this.provider.responseCallbacks = {};
|
||||||
this.provider = null;
|
|
||||||
}
|
}
|
||||||
|
this.provider = null;
|
||||||
|
this.web3.setProvider(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
fundAccounts(callback) {
|
fundAccounts(callback) {
|
||||||
|
|
Loading…
Reference in New Issue