2018-05-17 05:46:34 +02:00
|
|
|
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
|
2018-10-08 17:55:07 +02:00
|
|
|
const createBlockReRefMiddleware = require('eth-json-rpc-middleware/block-ref')
|
|
|
|
const createRetryOnEmptyMiddleware = require('eth-json-rpc-middleware/retryOnEmpty')
|
2018-05-17 06:08:19 +02:00
|
|
|
const createBlockCacheMiddleware = require('eth-json-rpc-middleware/block-cache')
|
2018-05-17 07:46:11 +02:00
|
|
|
const createInflightMiddleware = require('eth-json-rpc-middleware/inflight-cache')
|
2018-06-12 20:12:32 +02:00
|
|
|
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
|
2018-05-17 06:08:19 +02:00
|
|
|
const providerFromMiddleware = require('eth-json-rpc-middleware/providerFromMiddleware')
|
|
|
|
const createInfuraMiddleware = require('eth-json-rpc-infura')
|
2018-05-17 05:46:34 +02:00
|
|
|
const BlockTracker = require('eth-block-tracker')
|
|
|
|
|
|
|
|
module.exports = createInfuraClient
|
|
|
|
|
2018-05-17 06:08:19 +02:00
|
|
|
function createInfuraClient ({ network }) {
|
2018-05-17 05:46:34 +02:00
|
|
|
const infuraMiddleware = createInfuraMiddleware({ network })
|
2018-10-08 17:55:07 +02:00
|
|
|
const infuraProvider = providerFromMiddleware(infuraMiddleware)
|
|
|
|
const blockTracker = new BlockTracker({ provider: infuraProvider })
|
2018-05-17 05:46:34 +02:00
|
|
|
|
|
|
|
const networkMiddleware = mergeMiddleware([
|
|
|
|
createBlockCacheMiddleware({ blockTracker }),
|
|
|
|
createInflightMiddleware(),
|
2018-10-08 17:55:07 +02:00
|
|
|
createBlockReRefMiddleware({ blockTracker, provider: infuraProvider }),
|
|
|
|
createRetryOnEmptyMiddleware({ blockTracker, provider: infuraProvider }),
|
2018-05-17 05:46:34 +02:00
|
|
|
createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
|
|
infuraMiddleware,
|
|
|
|
])
|
|
|
|
return { networkMiddleware, blockTracker }
|
|
|
|
}
|