1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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
This commit is contained in:
Dan Finlay 2017-05-20 20:37:47 -07:00
parent c7fd9f4240
commit c5432da567

View File

@ -1,5 +1,6 @@
const pipe = require('pump') 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 LocalStorageStore = require('obs-store')
const ObjectMultiplex = require('./obj-multiplex') const ObjectMultiplex = require('./obj-multiplex')
const createRandomId = require('./random-id') const createRandomId = require('./random-id')
@ -27,14 +28,21 @@ function MetamaskInpageProvider (connectionStream) {
) )
// connect to async provider // 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( pipe(
asyncProvider, stream,
multiStream.createStream('provider'), multiStream.createStream('provider'),
asyncProvider, stream,
(err) => logStreamDisconnectWarning('MetaMask RpcProvider', err) (err) => logStreamDisconnectWarning('MetaMask RpcProvider', err)
) )
// start polling
engine.start()
self.idMap = {} self.idMap = {}
// handle sendAsync requests via asyncProvider // handle sendAsync requests via asyncProvider
self.sendAsync = function (payload, cb) { self.sendAsync = function (payload, cb) {
@ -46,7 +54,9 @@ function MetamaskInpageProvider (connectionStream) {
return message return message
}) })
// forward to asyncProvider // 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) if (err) return cb(err)
// transform messages to original ids // transform messages to original ids
eachJsonMessage(res, (message) => { eachJsonMessage(res, (message) => {