diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-05-21 11:37:47 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-05-21 11:38:38 +0800 |
commit | c5432da567b9953c1294e0bf598a0310127bf808 (patch) | |
tree | 1efdc1efd9136654fa9d6d4129f81235c761d820 | |
parent | c7fd9f424087b20bfc356d360d2a2246ca0e5ad7 (diff) | |
download | tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar.gz tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar.bz2 tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar.lz tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar.xz tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.tar.zst tangerine-wallet-browser-c5432da567b9953c1294e0bf598a0310127bf808.zip |
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
-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) => { |