diff options
Add new streaming subprovider but getting a loop
Regarding #1458
Uses a new streaming subprovider architecture on an experimental branch of StreamProvider:
https://github.com/flyswatter/web3-stream-provider/tree/StreamSubprovider
Diffstat (limited to 'app/scripts/lib/inpage-provider.js')
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index e5e398e24..88d81cca5 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -1,5 +1,6 @@ const pipe = require('pump') -const StreamProvider = require('web3-stream-provider') +const StreamSubprovider = require('web3-stream-provider/stream-subprovider') +const ProviderEngine = require('web3-provider-engine') const LocalStorageStore = require('obs-store') const ObjectMultiplex = require('./obj-multiplex') const createRandomId = require('./random-id') @@ -27,14 +28,21 @@ function MetamaskInpageProvider (connectionStream) { ) // connect to async provider - const asyncProvider = self.asyncProvider = new StreamProvider() + const engine = self.asyncProvider = new ProviderEngine() + + const stream = self.stream = new StreamSubprovider() + engine.addProvider(stream) + pipe( - asyncProvider, + stream, multiStream.createStream('provider'), - asyncProvider, + stream, (err) => logStreamDisconnectWarning('MetaMask RpcProvider', err) ) + // start polling + engine.start() + self.idMap = {} // handle sendAsync requests via asyncProvider self.sendAsync = function (payload, cb) { @@ -46,7 +54,9 @@ function MetamaskInpageProvider (connectionStream) { return message }) // forward to asyncProvider - asyncProvider.sendAsync(request, function (err, res) { + console.log('sending async to engine', request) + engine.sendAsync(request, function (err, res) { + console.log('send async returned !!', err, res) if (err) return cb(err) // transform messages to original ids eachJsonMessage(res, (message) => { |