diff --git a/node_modules/hardhat/internal/hardhat-network/jsonrpc/client.js b/node_modules/hardhat/internal/hardhat-network/jsonrpc/client.js index 8f78e83..77721e6 100644 --- a/node_modules/hardhat/internal/hardhat-network/jsonrpc/client.js +++ b/node_modules/hardhat/internal/hardhat-network/jsonrpc/client.js @@ -1,14 +1,14 @@ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { +var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { + Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); +}) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { +}) : function (o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { @@ -141,6 +141,60 @@ class JsonRpcClient { reward: (0, io_ts_1.optional)(t.array(t.array(base_types_1.rpcQuantity))), }), (res) => res.oldestBlock + BigInt(res.baseFeePerGas.length)); } + _patchRawResult(method, rawResult) { + /** + * Patch the raw results returned by _send or _sendBatch to fix RSK/Hardhat compatibility issues. + */ + if ( + method.startsWith('eth_getBlock') && + rawResult && + rawResult.transactions && rawResult.transactions.length + ) { + /* + * Calling a forked node (hardhat node --fork MY_RSK_NODE_RPC_URL) fails with: + * eth_call + * Invalid JSON-RPC response's result. + * Errors: Invalid value null supplied to : RpcBlockWithTransactions | null/transactions: + * RpcTransaction Array/0: RpcTransaction/v: QUANTITY, Invalid value null supplied to : + * RpcBlockWithTransactions | null/transactions: RpcTransaction Array/0: RpcTransaction/r: + * QUANTITY, Invalid value null supplied to : RpcBlockWithTransactions | null/transactions: + * RpcTransaction Array/0: RpcTransaction/s: QUANTITY + * + * This patch is based on: + * https://gist.github.com/0x0scion/0422f9135bc37642ba36d55b59e8b424 + * + * More reading: + * https://github.com/NomicFoundation/hardhat/issues/2395 + * https://github.com/NomicFoundation/hardhat/pull/2313/files + * https://github.com/NomicFoundation/hardhat/issues/2106 + */ + rawResult.transactions.forEach((t) => { + // Accesslist is sometimes missing, for other networks and maybe for RSK too + if (!t.accessList) t.accessList = []; + // Some RSK txs have null vrs + // from: '0x0000000000000000000000000000000000000000', + // to: '0x0000000000000000000000000000000001000008', + // gas: '0x0', + // gasPrice: '0x0', + // value: '0x0', + // input: '0x', + // v: null, + // r: null, + // s: null + if (!t.v) t.v = '0x0'; + if (!t.r) t.r = '0x0'; + if (!t.s) t.s = '0x0'; + }); + } else if (method === 'eth_getStorageAt') { + /* + * This fixes the error in eth_getStorageAt that says 0x0 is an invalid value for DATA + */ + if (rawResult === '0x0') { + rawResult = '0x0000000000000000000000000000000000000000000000000000000000000000'; + } + } + return rawResult; + } async getLatestBlockNumber() { return this._perform("eth_blockNumber", [], base_types_1.rpcQuantity, (blockNumber) => blockNumber); } @@ -157,7 +211,8 @@ class JsonRpcClient { return diskCachedResult; } } - const rawResult = await this._send(method, params); + let rawResult = await this._send(method, params); + rawResult = this._patchRawResult(method, rawResult); const decodedResult = (0, decodeJsonRpcResponse_1.decodeJsonRpcResponse)(rawResult, tType); const blockNumber = getMaxAffectedBlockNumber(decodedResult); if (this._canBeCached(blockNumber)) { @@ -186,7 +241,13 @@ class JsonRpcClient { } } const rawResults = await this._sendBatch(batch); - const decodedResults = rawResults.map((result, i) => (0, decodeJsonRpcResponse_1.decodeJsonRpcResponse)(result, batch[i].tType)); + const decodedResults = rawResults.map((result, i) => { + result = this._patchRawResult(batch[i].method, result); + return (0, decodeJsonRpcResponse_1.decodeJsonRpcResponse)( + result, + batch[i].tType + ); + }); const blockNumber = getMaxAffectedBlockNumber(decodedResults); if (this._canBeCached(blockNumber)) { this._storeInCache(cacheKey, decodedResults);