mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
network - import createBlockTrackerInspectorMiddleware and rearrange cache middleware order
This commit is contained in:
parent
c86f935889
commit
6a2649a90f
@ -3,6 +3,7 @@ const createAsyncMiddleware = require('json-rpc-engine/src/createAsyncMiddleware
|
||||
const createBlockReEmitMiddleware = require('eth-json-rpc-middleware/block-reemit')
|
||||
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')
|
||||
@ -15,23 +16,11 @@ function createInfuraClient ({ network }) {
|
||||
const blockTracker = new BlockTracker({ provider: blockProvider })
|
||||
|
||||
const networkMiddleware = mergeMiddleware([
|
||||
createBlockReEmitMiddleware({ blockTracker, provider: blockProvider }),
|
||||
createBlockCacheMiddleware({ blockTracker }),
|
||||
createInflightMiddleware(),
|
||||
createBlockReEmitMiddleware({ blockTracker, provider: blockProvider }),
|
||||
createBlockTrackerInspectorMiddleware({ blockTracker }),
|
||||
infuraMiddleware,
|
||||
])
|
||||
return { networkMiddleware, blockTracker }
|
||||
}
|
||||
|
||||
// inspect if response contains a block ref higher than our latest block
|
||||
const futureBlockRefRequests = ['eth_getTransactionByHash', 'eth_getTransactionReceipt']
|
||||
function createBlockTrackerInspectorMiddleware ({ blockTracker }) {
|
||||
return createAsyncMiddleware(async (req, res, next) => {
|
||||
if (!futureBlockRefRequests.includes(req.method)) return next()
|
||||
await next()
|
||||
const blockNumber = Number.parseInt(res.result.blockNumber, 16)
|
||||
const currentBlockNumber = Number.parseInt(blockTracker.getCurrentBlock(), 16)
|
||||
if (blockNumber > currentBlockNumber) await blockTracker.checkForLatestBlock()
|
||||
})
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ const createFetchMiddleware = require('eth-json-rpc-middleware/fetch')
|
||||
const createBlockRefMiddleware = require('eth-json-rpc-middleware/block-ref')
|
||||
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 BlockTracker = require('eth-block-tracker')
|
||||
|
||||
@ -23,15 +24,3 @@ function createJsonRpcClient ({ rpcUrl }) {
|
||||
])
|
||||
return { networkMiddleware, blockTracker }
|
||||
}
|
||||
|
||||
// inspect if response contains a block ref higher than our latest block
|
||||
const futureBlockRefRequests = ['eth_getTransactionByHash', 'eth_getTransactionReceipt']
|
||||
function createBlockTrackerInspectorMiddleware ({ blockTracker }) {
|
||||
return createAsyncMiddleware(async (req, res, next) => {
|
||||
if (!futureBlockRefRequests.includes(req.method)) return next()
|
||||
await next()
|
||||
const blockNumber = Number.parseInt(res.result.blockNumber, 16)
|
||||
const currentBlockNumber = Number.parseInt(blockTracker.getCurrentBlock(), 16)
|
||||
if (blockNumber > currentBlockNumber) await blockTracker.checkForLatestBlock()
|
||||
})
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
|
||||
const createAsyncMiddleware = require('json-rpc-engine/src/createAsyncMiddleware')
|
||||
const createFetchMiddleware = require('eth-json-rpc-middleware/fetch')
|
||||
const createBlockRefMiddleware = require('eth-json-rpc-middleware/block-ref')
|
||||
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
|
||||
const providerFromMiddleware = require('eth-json-rpc-middleware/providerFromMiddleware')
|
||||
const BlockTracker = require('eth-block-tracker')
|
||||
|
||||
@ -19,15 +20,3 @@ function createLocalhostClient () {
|
||||
])
|
||||
return { networkMiddleware, blockTracker }
|
||||
}
|
||||
|
||||
// inspect if response contains a block ref higher than our latest block
|
||||
const futureBlockRefRequests = ['eth_getTransactionByHash', 'eth_getTransactionReceipt']
|
||||
function createBlockTrackerInspectorMiddleware ({ blockTracker }) {
|
||||
return createAsyncMiddleware(async (req, res, next) => {
|
||||
if (!futureBlockRefRequests.includes(req.method)) return next()
|
||||
await next()
|
||||
const blockNumber = Number.parseInt(res.result.blockNumber, 16)
|
||||
const currentBlockNumber = Number.parseInt(blockTracker.getCurrentBlock(), 16)
|
||||
if (blockNumber > currentBlockNumber) await blockTracker.checkForLatestBlock()
|
||||
})
|
||||
}
|
||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -8217,9 +8217,9 @@
|
||||
}
|
||||
},
|
||||
"eth-json-rpc-middleware": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-2.3.0.tgz",
|
||||
"integrity": "sha512-pMG8pDbmipPIellAoAz494ShJ/vLiCy0QOOLXPv2IwTtrdnpr04Zj9NTVxPhg6F+c87cyiUgHi6zOgoZQKvaGQ==",
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-2.4.0.tgz",
|
||||
"integrity": "sha512-KUxyz7pr6MZmFlsym8EObWwrFHVxRCLHGfl8H2V7D4ZjK0yhoPaA94jSXAumUbfx2AmyYEtG9j2xmU1P83m7OQ==",
|
||||
"requires": {
|
||||
"async": "^2.5.0",
|
||||
"clone": "^2.1.1",
|
||||
|
@ -99,7 +99,7 @@
|
||||
"eth-hd-keyring": "^1.2.1",
|
||||
"eth-json-rpc-filters": "^2.1.1",
|
||||
"eth-json-rpc-infura": "^3.0.0",
|
||||
"eth-json-rpc-middleware": "^2.3.0",
|
||||
"eth-json-rpc-middleware": "^2.4.0",
|
||||
"eth-keyring-controller": "^3.1.4",
|
||||
"eth-phishing-detect": "^1.1.4",
|
||||
"eth-query": "^2.1.2",
|
||||
|
Loading…
Reference in New Issue
Block a user