mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
28 lines
1.4 KiB
JavaScript
28 lines
1.4 KiB
JavaScript
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
|
|
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')
|
|
const providerFromMiddleware = require('eth-json-rpc-middleware/providerFromMiddleware')
|
|
const createInfuraMiddleware = require('eth-json-rpc-infura')
|
|
const BlockTracker = require('eth-block-tracker')
|
|
|
|
module.exports = createInfuraClient
|
|
|
|
function createInfuraClient ({ network }) {
|
|
const infuraMiddleware = createInfuraMiddleware({ network })
|
|
const infuraProvider = providerFromMiddleware(infuraMiddleware)
|
|
const blockTracker = new BlockTracker({ provider: infuraProvider })
|
|
|
|
const networkMiddleware = mergeMiddleware([
|
|
createBlockCacheMiddleware({ blockTracker }),
|
|
createInflightMiddleware(),
|
|
createBlockReRefMiddleware({ blockTracker, provider: infuraProvider }),
|
|
createRetryOnEmptyMiddleware({ blockTracker, provider: infuraProvider }),
|
|
createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
infuraMiddleware,
|
|
])
|
|
return { networkMiddleware, blockTracker }
|
|
}
|