|
|
@ -1,5 +1,7 @@ |
|
|
|
const pipe = require('pump') |
|
|
|
const pipe = require('pump') |
|
|
|
const StreamProvider = require('web3-stream-provider') |
|
|
|
const ProviderEngine = require('web3-provider-engine') |
|
|
|
|
|
|
|
const FilterSubprovider = require('web3-provider-engine/subproviders/filters') |
|
|
|
|
|
|
|
const StreamSubprovider = require('web3-provider-engine/subproviders/stream') |
|
|
|
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 +29,24 @@ function MetamaskInpageProvider (connectionStream) { |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// connect to async provider
|
|
|
|
// connect to async provider
|
|
|
|
const asyncProvider = self.asyncProvider = new StreamProvider() |
|
|
|
const engine = new ProviderEngine() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filterSubprovider = new FilterSubprovider() |
|
|
|
|
|
|
|
engine.addProvider(filterSubprovider) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const streamSubprovider = new StreamSubprovider() |
|
|
|
|
|
|
|
engine.addProvider(streamSubprovider) |
|
|
|
|
|
|
|
|
|
|
|
pipe( |
|
|
|
pipe( |
|
|
|
asyncProvider, |
|
|
|
streamSubprovider, |
|
|
|
multiStream.createStream('provider'), |
|
|
|
multiStream.createStream('provider'), |
|
|
|
asyncProvider, |
|
|
|
streamSubprovider, |
|
|
|
(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 +58,7 @@ function MetamaskInpageProvider (connectionStream) { |
|
|
|
return message |
|
|
|
return message |
|
|
|
}) |
|
|
|
}) |
|
|
|
// forward to asyncProvider
|
|
|
|
// forward to asyncProvider
|
|
|
|
asyncProvider.sendAsync(request, function (err, res) { |
|
|
|
engine.sendAsync(request, function (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) => { |
|
|
|