diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index be408f65..14b1cb85 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -130,7 +130,7 @@ class BlockchainConnector { this.events.request("services:register", 'Ethereum', function (cb) { async.waterfall([ function checkNodeConnection(next) { - if (!self.web3.currentProvider) { + if (!self.provider || !self.provider.connected()) { return next(NO_NODE, {name: "No Blockchain node found", status: 'off'}); } next(); diff --git a/lib/modules/blockchain_connector/provider.js b/lib/modules/blockchain_connector/provider.js index 6a01056f..e4fd81ca 100644 --- a/lib/modules/blockchain_connector/provider.js +++ b/lib/modules/blockchain_connector/provider.js @@ -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 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('end', e => self.logger.error('Websocket connection ended', e)); + self.provider.on('error', () => self.logger.error('Websocket Error')); + self.provider.on('end', () => self.logger.error('Websocket connection ended')); } else { 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() { if (this.provider && this.provider.removeAllListeners) { this.provider.removeAllListeners('connect'); @@ -79,8 +89,9 @@ class Provider { this.provider.removeAllListeners('end'); this.provider.removeAllListeners('data'); this.provider.responseCallbacks = {}; - this.provider = null; } + this.provider = null; + this.web3.setProvider(null); } fundAccounts(callback) {