aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-10-08 23:55:07 +0800
committerkumavis <aaron@kumavis.me>2018-10-08 23:55:07 +0800
commit354f8c0d7de8ff2611988f9839c2072295c955ae (patch)
treeda69526eebd007857b6efedb5c0a3dc165318ad0 /app
parentc500ef4a587c4d3eebbc1e392227aabbbf4f2b2e (diff)
downloadtangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.gz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.bz2
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.lz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.xz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.zst
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.zip
provider - enable subscription support (newHeads, logs)
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/network/createInfuraClient.js10
-rw-r--r--app/scripts/metamask-controller.js20
2 files changed, 21 insertions, 9 deletions
diff --git a/app/scripts/controllers/network/createInfuraClient.js b/app/scripts/controllers/network/createInfuraClient.js
index 41af4d9f9..326bcb355 100644
--- a/app/scripts/controllers/network/createInfuraClient.js
+++ b/app/scripts/controllers/network/createInfuraClient.js
@@ -1,5 +1,6 @@
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
-const createBlockReEmitMiddleware = require('eth-json-rpc-middleware/block-reemit')
+const createBlockReRefMiddleware = require('eth-json-rpc-middleware/block-ref')
+const createRetryOnEmptyMiddleware = require('eth-json-rpc-middleware/retryOnEmpty')
const createBlockCacheMiddleware = require('eth-json-rpc-middleware/block-cache')
const createInflightMiddleware = require('eth-json-rpc-middleware/inflight-cache')
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
@@ -11,13 +12,14 @@ module.exports = createInfuraClient
function createInfuraClient ({ network }) {
const infuraMiddleware = createInfuraMiddleware({ network })
- const blockProvider = providerFromMiddleware(infuraMiddleware)
- const blockTracker = new BlockTracker({ provider: blockProvider })
+ const infuraProvider = providerFromMiddleware(infuraMiddleware)
+ const blockTracker = new BlockTracker({ provider: infuraProvider })
const networkMiddleware = mergeMiddleware([
createBlockCacheMiddleware({ blockTracker }),
createInflightMiddleware(),
- createBlockReEmitMiddleware({ blockTracker, provider: blockProvider }),
+ createBlockReRefMiddleware({ blockTracker, provider: infuraProvider }),
+ createRetryOnEmptyMiddleware({ blockTracker, provider: infuraProvider }),
createBlockTrackerInspectorMiddleware({ blockTracker }),
infuraMiddleware,
])
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 34ca80dd7..a59be7744 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -15,6 +15,7 @@ const RpcEngine = require('json-rpc-engine')
const debounce = require('debounce')
const createEngineStream = require('json-rpc-middleware-stream/engineStream')
const createFilterMiddleware = require('eth-json-rpc-filters')
+const createSubscriptionManager = require('eth-json-rpc-filters/subscriptionManager')
const createOriginMiddleware = require('./lib/createOriginMiddleware')
const createLoggerMiddleware = require('./lib/createLoggerMiddleware')
const createProviderMiddleware = require('./lib/createProviderMiddleware')
@@ -1246,24 +1247,33 @@ module.exports = class MetamaskController extends EventEmitter {
setupProviderConnection (outStream, origin) {
// setup json rpc engine stack
const engine = new RpcEngine()
+ const provider = this.provider
+ const blockTracker = this.blockTracker
// create filter polyfill middleware
- const filterMiddleware = createFilterMiddleware({
- provider: this.provider,
- blockTracker: this.blockTracker,
- })
+ const filterMiddleware = createFilterMiddleware({ provider, blockTracker })
+ // create subscription polyfill middleware
+ const subscriptionManager = createSubscriptionManager({ provider, blockTracker })
+ subscriptionManager.events.on('notification', (message) => engine.emit('notification', message))
+ // metadata
engine.push(createOriginMiddleware({ origin }))
engine.push(createLoggerMiddleware({ origin }))
+ // filter and subscription polyfills
engine.push(filterMiddleware)
+ engine.push(subscriptionManager.middleware)
+ // watch asset
engine.push(this.preferencesController.requestWatchAsset.bind(this.preferencesController))
+ // sign typed data middleware
engine.push(this.createTypedDataMiddleware('eth_signTypedData', 'V1').bind(this))
engine.push(this.createTypedDataMiddleware('eth_signTypedData_v1', 'V1').bind(this))
engine.push(this.createTypedDataMiddleware('eth_signTypedData_v3', 'V3', true).bind(this))
- engine.push(createProviderMiddleware({ provider: this.provider }))
+ // forward to metamask primary provider
+ engine.push(createProviderMiddleware({ provider }))
// setup connection
const providerStream = createEngineStream({ engine })
+
pump(
outStream,
providerStream,