From 152dfe2815b455ef60872ae65d2d5773c9a70999 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 17:40:51 -0400 Subject: [PATCH 1/2] initialize web3 in the whisper module itself; use defined configuration --- lib/modules/whisper/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index f2d961f13..822e55875 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -1,5 +1,6 @@ let utils = require('../../utils/utils.js'); let fs = require('../../core/fs.js'); +let Web3 = require('web3'); class Whisper { @@ -8,18 +9,27 @@ class Whisper { this.events = embark.events; this.communicationConfig = embark.config.communicationConfig; this.addCheck = options.addCheck; - // TODO: this should not be needed and should be deducted from the config instead - this.web3 = options.web3; + this.web3 = new Web3(); this.embark = embark; + this.connectToProvider(); this.setServiceCheck(); this.addWhisperToEmbarkJS(); this.addSetProvider(); } + connectToProvider() { + let { host, port } = this.communicationConfig.connection; + let web3Endpoint = 'ws://' + host + ':' + port; + this.web3.setProvider(new Web3.providers.WebsocketProvider(web3Endpoint, {headers: {Origin: "http://localhost:8000"}})); + } + setServiceCheck() { const self = this; self.addCheck('Whisper', function (cb) { + if (!self.web3.currentProvider || self.web3.currentProvider.connection.readyState !== 1) { + return self.connectToProvider(); + } self.web3.shh.getVersion(function (err, version) { if (err || version == "2") { return cb({name: 'Whisper', status: 'off'}); From 2ade8cfd09d4d154eaa1f451437371c03193b73d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 1 Jun 2018 19:12:54 -0400 Subject: [PATCH 2/2] lint is king --- lib/modules/whisper/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index 822e55875..53b808711 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -19,7 +19,7 @@ class Whisper { } connectToProvider() { - let { host, port } = this.communicationConfig.connection; + let {host, port} = this.communicationConfig.connection; let web3Endpoint = 'ws://' + host + ':' + port; this.web3.setProvider(new Web3.providers.WebsocketProvider(web3Endpoint, {headers: {Origin: "http://localhost:8000"}})); }