2020-01-09 04:34:58 +01:00
|
|
|
import mergeMiddleware from 'json-rpc-engine/src/mergeMiddleware'
|
|
|
|
import createFetchMiddleware from 'eth-json-rpc-middleware/fetch'
|
|
|
|
import createBlockRefRewriteMiddleware from 'eth-json-rpc-middleware/block-ref-rewrite'
|
|
|
|
import createBlockCacheMiddleware from 'eth-json-rpc-middleware/block-cache'
|
|
|
|
import createInflightMiddleware from 'eth-json-rpc-middleware/inflight-cache'
|
|
|
|
import createBlockTrackerInspectorMiddleware from 'eth-json-rpc-middleware/block-tracker-inspector'
|
|
|
|
import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware'
|
|
|
|
import BlockTracker from 'eth-block-tracker'
|
2018-05-17 05:46:34 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export default createJsonRpcClient
|
2018-05-17 05:46:34 +02:00
|
|
|
|
2019-05-03 19:32:05 +02:00
|
|
|
function createJsonRpcClient ({ rpcUrl }) {
|
2018-05-17 05:46:34 +02:00
|
|
|
const fetchMiddleware = createFetchMiddleware({ rpcUrl })
|
|
|
|
const blockProvider = providerFromMiddleware(fetchMiddleware)
|
2019-05-03 19:32:05 +02:00
|
|
|
const blockTracker = new BlockTracker({ provider: blockProvider })
|
2018-05-17 05:46:34 +02:00
|
|
|
|
|
|
|
const networkMiddleware = mergeMiddleware([
|
2018-10-08 18:39:18 +02:00
|
|
|
createBlockRefRewriteMiddleware({ blockTracker }),
|
2018-05-17 05:46:34 +02:00
|
|
|
createBlockCacheMiddleware({ blockTracker }),
|
|
|
|
createInflightMiddleware(),
|
|
|
|
createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
|
|
fetchMiddleware,
|
|
|
|
])
|
|
|
|
return { networkMiddleware, blockTracker }
|
|
|
|
}
|