diff options
-rw-r--r-- | app/scripts/controllers/network/createInfuraClient.js | 15 | ||||
-rw-r--r-- | app/scripts/controllers/network/createJsonRpcClient.js | 13 | ||||
-rw-r--r-- | app/scripts/controllers/network/createLocalhostClient.js | 13 | ||||
-rw-r--r-- | package-lock.json | 6 | ||||
-rw-r--r-- | package.json | 2 |
5 files changed, 8 insertions, 41 deletions
diff --git a/app/scripts/controllers/network/createInfuraClient.js b/app/scripts/controllers/network/createInfuraClient.js index 663a2595a..6976e6022 100644 --- a/app/scripts/controllers/network/createInfuraClient.js +++ b/app/scripts/controllers/network/createInfuraClient.js @@ -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() - }) -} diff --git a/app/scripts/controllers/network/createJsonRpcClient.js b/app/scripts/controllers/network/createJsonRpcClient.js index d712ed135..b9aca0bcf 100644 --- a/app/scripts/controllers/network/createJsonRpcClient.js +++ b/app/scripts/controllers/network/createJsonRpcClient.js @@ -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() - }) -} diff --git a/app/scripts/controllers/network/createLocalhostClient.js b/app/scripts/controllers/network/createLocalhostClient.js index 990dc6a95..ae42ac48b 100644 --- a/app/scripts/controllers/network/createLocalhostClient.js +++ b/app/scripts/controllers/network/createLocalhostClient.js @@ -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() - }) -} diff --git a/package-lock.json b/package-lock.json index 56de846d4..5c8ddbdb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 94f4b1950..0332f06b8 100644 --- a/package.json +++ b/package.json @@ -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", |