hardhat 2.22.2 → 2.23.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin-tasks/compile.js +2 -2
- package/builtin-tasks/compile.js.map +1 -1
- package/common/napi-rs.d.ts +2 -0
- package/common/napi-rs.d.ts.map +1 -0
- package/common/napi-rs.js +19 -0
- package/common/napi-rs.js.map +1 -0
- package/internal/core/errors-list.js +1 -1
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/params/argumentTypes.d.ts +6 -0
- package/internal/core/params/argumentTypes.d.ts.map +1 -1
- package/internal/core/params/argumentTypes.js +40 -1
- package/internal/core/params/argumentTypes.js.map +1 -1
- package/internal/core/tasks/task-definitions.d.ts +2 -2
- package/internal/core/tasks/task-definitions.js +2 -2
- package/internal/hardhat-network/provider/BlockchainBase.d.ts +29 -0
- package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -0
- package/internal/hardhat-network/provider/BlockchainBase.js +144 -0
- package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -0
- package/internal/hardhat-network/provider/BlockchainData.d.ts +58 -0
- package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -0
- package/internal/hardhat-network/provider/BlockchainData.js +178 -0
- package/internal/hardhat-network/provider/BlockchainData.js.map +1 -0
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +24 -0
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -0
- package/internal/hardhat-network/provider/HardhatBlockchain.js +73 -0
- package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -0
- package/internal/hardhat-network/provider/PoolState.d.ts +26 -0
- package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -0
- package/internal/hardhat-network/provider/PoolState.js +41 -0
- package/internal/hardhat-network/provider/PoolState.js.map +1 -0
- package/internal/hardhat-network/provider/TransactionQueue.d.ts +32 -0
- package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -0
- package/internal/hardhat-network/provider/TransactionQueue.js +130 -0
- package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -0
- package/internal/hardhat-network/provider/TxPool.d.ts +83 -0
- package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -0
- package/internal/hardhat-network/provider/TxPool.js +470 -0
- package/internal/hardhat-network/provider/TxPool.js.map +1 -0
- package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts +2 -0
- package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts.map +1 -0
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js +15 -0
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -0
- package/internal/hardhat-network/provider/filter.d.ts +29 -0
- package/internal/hardhat-network/provider/filter.d.ts.map +1 -0
- package/internal/hardhat-network/provider/filter.js +97 -0
- package/internal/hardhat-network/provider/filter.js.map +1 -0
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +33 -0
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -0
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +272 -0
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -0
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +51 -0
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -0
- package/internal/hardhat-network/provider/fork/ForkStateManager.js +300 -0
- package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -0
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +4 -0
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -0
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js +32 -0
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -0
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +10 -0
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -0
- package/internal/hardhat-network/provider/fork/rpcToTxData.js +29 -0
- package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -0
- package/internal/hardhat-network/provider/modules/base.d.ts +17 -0
- package/internal/hardhat-network/provider/modules/base.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/base.js +127 -0
- package/internal/hardhat-network/provider/modules/base.js.map +1 -0
- package/internal/hardhat-network/provider/modules/debug.d.ts +12 -0
- package/internal/hardhat-network/provider/modules/debug.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/debug.js +52 -0
- package/internal/hardhat-network/provider/modules/debug.js.map +1 -0
- package/internal/hardhat-network/provider/modules/eth.d.ts +107 -0
- package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/eth.js +1034 -0
- package/internal/hardhat-network/provider/modules/eth.js.map +1 -0
- package/internal/hardhat-network/provider/modules/evm.d.ts +32 -0
- package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/evm.js +180 -0
- package/internal/hardhat-network/provider/modules/evm.js.map +1 -0
- package/internal/hardhat-network/provider/modules/hardhat.d.ts +54 -0
- package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/hardhat.js +309 -0
- package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -0
- package/internal/hardhat-network/provider/modules/net.d.ts +13 -0
- package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/net.js +47 -0
- package/internal/hardhat-network/provider/modules/net.js.map +1 -0
- package/internal/hardhat-network/provider/modules/personal.d.ts +9 -0
- package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/personal.js +31 -0
- package/internal/hardhat-network/provider/modules/personal.js.map +1 -0
- package/internal/hardhat-network/provider/modules/web3.d.ts +11 -0
- package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/web3.js +38 -0
- package/internal/hardhat-network/provider/modules/web3.js.map +1 -0
- package/internal/hardhat-network/provider/node.d.ts +197 -0
- package/internal/hardhat-network/provider/node.d.ts.map +1 -0
- package/internal/hardhat-network/provider/node.js +1866 -0
- package/internal/hardhat-network/provider/node.js.map +1 -0
- package/internal/hardhat-network/provider/provider.d.ts +1 -1
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +34 -27
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +29 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +137 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +27 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +137 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +33 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +141 -0
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +30 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +97 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +30 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +98 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +40 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +91 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +32 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +87 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -0
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +17 -0
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -0
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js +3 -0
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.js +4 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +7 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +31 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -0
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +4 -0
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/makeStateTrie.js +20 -0
- package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +8 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +37 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -0
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +12 -0
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +62 -0
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -0
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +3 -0
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/txMapToArray.js +12 -0
- package/internal/hardhat-network/provider/utils/txMapToArray.js.map +1 -0
- package/internal/hardhat-network/provider/vm/exit.d.ts +1 -1
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.js +4 -0
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +46 -0
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -0
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +421 -0
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -0
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
- package/internal/solidity/parse.d.ts.map +1 -1
- package/internal/solidity/parse.js +5 -15
- package/internal/solidity/parse.js.map +1 -1
- package/package.json +8 -8
- package/recommended-gitignore.txt +3 -0
- package/src/builtin-tasks/compile.ts +2 -2
- package/src/common/napi-rs.ts +15 -0
- package/src/internal/core/errors-list.ts +1 -1
- package/src/internal/core/params/argumentTypes.ts +44 -0
- package/src/internal/core/tasks/task-definitions.ts +2 -2
- package/src/internal/hardhat-network/provider/provider.ts +52 -38
- package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +14 -1
- package/src/internal/hardhat-network/provider/vm/exit.ts +15 -1
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +1 -1
- package/src/internal/solidity/parse.ts +7 -16
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.EthModule = void 0;
|
|
30
|
+
const ethereumjs_tx_1 = require("@nomicfoundation/ethereumjs-tx");
|
|
31
|
+
const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
|
|
32
|
+
const t = __importStar(require("io-ts"));
|
|
33
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
34
|
+
const base_types_1 = require("../../../core/jsonrpc/types/base-types");
|
|
35
|
+
const blockTag_1 = require("../../../core/jsonrpc/types/input/blockTag");
|
|
36
|
+
const callRequest_1 = require("../../../core/jsonrpc/types/input/callRequest");
|
|
37
|
+
const filterRequest_1 = require("../../../core/jsonrpc/types/input/filterRequest");
|
|
38
|
+
const subscribeRequest_1 = require("../../../core/jsonrpc/types/input/subscribeRequest");
|
|
39
|
+
const transactionRequest_1 = require("../../../core/jsonrpc/types/input/transactionRequest");
|
|
40
|
+
const validation_1 = require("../../../core/jsonrpc/types/input/validation");
|
|
41
|
+
const errors_1 = require("../../../core/providers/errors");
|
|
42
|
+
const filter_1 = require("../filter");
|
|
43
|
+
const output_1 = require("../output");
|
|
44
|
+
const assertions_1 = require("../utils/assertions");
|
|
45
|
+
const io_ts_1 = require("../../../util/io-ts");
|
|
46
|
+
const BigIntUtils = __importStar(require("../../../util/bigint"));
|
|
47
|
+
const hardforks_1 = require("../../../util/hardforks");
|
|
48
|
+
const base_1 = require("./base");
|
|
49
|
+
const EIP1559_MIN_HARDFORK = hardforks_1.HardforkName.LONDON;
|
|
50
|
+
const ACCESS_LIST_MIN_HARDFORK = hardforks_1.HardforkName.BERLIN;
|
|
51
|
+
const EIP155_MIN_HARDFORK = hardforks_1.HardforkName.SPURIOUS_DRAGON;
|
|
52
|
+
const EIP3860_MIN_HARDFORK = hardforks_1.HardforkName.SHANGHAI;
|
|
53
|
+
/* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
|
|
54
|
+
class EthModule extends base_1.Base {
|
|
55
|
+
constructor(_common, _node, _throwOnTransactionFailures, _throwOnCallFailures, _logger, _experimentalHardhatNetworkMessageTraceHooks = []) {
|
|
56
|
+
super(_node);
|
|
57
|
+
this._common = _common;
|
|
58
|
+
this._throwOnTransactionFailures = _throwOnTransactionFailures;
|
|
59
|
+
this._throwOnCallFailures = _throwOnCallFailures;
|
|
60
|
+
this._logger = _logger;
|
|
61
|
+
this._experimentalHardhatNetworkMessageTraceHooks = _experimentalHardhatNetworkMessageTraceHooks;
|
|
62
|
+
}
|
|
63
|
+
async processRequest(method, params = []) {
|
|
64
|
+
switch (method) {
|
|
65
|
+
case "eth_accounts":
|
|
66
|
+
return this._accountsAction(...this._accountsParams(params));
|
|
67
|
+
case "eth_blockNumber":
|
|
68
|
+
return this._blockNumberAction(...this._blockNumberParams(params));
|
|
69
|
+
case "eth_call":
|
|
70
|
+
return this._callAction(...this._callParams(params));
|
|
71
|
+
case "eth_chainId":
|
|
72
|
+
return this._chainIdAction(...this._chainIdParams(params));
|
|
73
|
+
case "eth_coinbase":
|
|
74
|
+
return this._coinbaseAction(...this._coinbaseParams(params));
|
|
75
|
+
case "eth_compileLLL":
|
|
76
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
77
|
+
case "eth_compileSerpent":
|
|
78
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
79
|
+
case "eth_compileSolidity":
|
|
80
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
81
|
+
case "eth_estimateGas":
|
|
82
|
+
return this._estimateGasAction(...this._estimateGasParams(params));
|
|
83
|
+
case "eth_gasPrice":
|
|
84
|
+
return this._gasPriceAction(...this._gasPriceParams(params));
|
|
85
|
+
case "eth_getBalance":
|
|
86
|
+
return this._getBalanceAction(...this._getBalanceParams(params));
|
|
87
|
+
case "eth_getBlockByHash":
|
|
88
|
+
return this._getBlockByHashAction(...this._getBlockByHashParams(params));
|
|
89
|
+
case "eth_getBlockByNumber":
|
|
90
|
+
return this._getBlockByNumberAction(...this._getBlockByNumberParams(params));
|
|
91
|
+
case "eth_getBlockTransactionCountByHash":
|
|
92
|
+
return this._getBlockTransactionCountByHashAction(...this._getBlockTransactionCountByHashParams(params));
|
|
93
|
+
case "eth_getBlockTransactionCountByNumber":
|
|
94
|
+
return this._getBlockTransactionCountByNumberAction(...this._getBlockTransactionCountByNumberParams(params));
|
|
95
|
+
case "eth_getCode":
|
|
96
|
+
return this._getCodeAction(...this._getCodeParams(params));
|
|
97
|
+
case "eth_getCompilers":
|
|
98
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
99
|
+
case "eth_getFilterChanges":
|
|
100
|
+
return this._getFilterChangesAction(...this._getFilterChangesParams(params));
|
|
101
|
+
case "eth_getFilterLogs":
|
|
102
|
+
return this._getFilterLogsAction(...this._getFilterLogsParams(params));
|
|
103
|
+
case "eth_getLogs":
|
|
104
|
+
return this._getLogsAction(...this._getLogsParams(params));
|
|
105
|
+
case "eth_getProof":
|
|
106
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
107
|
+
case "eth_getStorageAt":
|
|
108
|
+
return this._getStorageAtAction(...this._getStorageAtParams(params));
|
|
109
|
+
case "eth_getTransactionByBlockHashAndIndex":
|
|
110
|
+
return this._getTransactionByBlockHashAndIndexAction(...this._getTransactionByBlockHashAndIndexParams(params));
|
|
111
|
+
case "eth_getTransactionByBlockNumberAndIndex":
|
|
112
|
+
return this._getTransactionByBlockNumberAndIndexAction(...this._getTransactionByBlockNumberAndIndexParams(params));
|
|
113
|
+
case "eth_getTransactionByHash":
|
|
114
|
+
return this._getTransactionByHashAction(...this._getTransactionByHashParams(params));
|
|
115
|
+
case "eth_getTransactionCount":
|
|
116
|
+
return this._getTransactionCountAction(...this._getTransactionCountParams(params));
|
|
117
|
+
case "eth_getTransactionReceipt":
|
|
118
|
+
return this._getTransactionReceiptAction(...this._getTransactionReceiptParams(params));
|
|
119
|
+
case "eth_getUncleByBlockHashAndIndex":
|
|
120
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
121
|
+
case "eth_getUncleByBlockNumberAndIndex":
|
|
122
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
123
|
+
case "eth_getUncleCountByBlockHash":
|
|
124
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
125
|
+
case "eth_getUncleCountByBlockNumber":
|
|
126
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
127
|
+
case "eth_getWork":
|
|
128
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
129
|
+
case "eth_hashrate":
|
|
130
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
131
|
+
case "eth_mining":
|
|
132
|
+
return this._miningAction(...this._miningParams(params));
|
|
133
|
+
case "eth_newBlockFilter":
|
|
134
|
+
return this._newBlockFilterAction(...this._newBlockFilterParams(params));
|
|
135
|
+
case "eth_newFilter":
|
|
136
|
+
return this._newFilterAction(...this._newFilterParams(params));
|
|
137
|
+
case "eth_newPendingTransactionFilter":
|
|
138
|
+
return this._newPendingTransactionAction(...this._newPendingTransactionParams(params));
|
|
139
|
+
case "eth_pendingTransactions":
|
|
140
|
+
return this._pendingTransactionsAction(...this._pendingTransactionsParams(params));
|
|
141
|
+
case "eth_protocolVersion":
|
|
142
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
143
|
+
case "eth_sendRawTransaction":
|
|
144
|
+
return this._sendRawTransactionAction(...this._sendRawTransactionParams(params));
|
|
145
|
+
case "eth_sendTransaction":
|
|
146
|
+
return this._sendTransactionAction(...this._sendTransactionParams(params));
|
|
147
|
+
case "eth_sign":
|
|
148
|
+
return this._signAction(...this._signParams(params));
|
|
149
|
+
case "eth_signTransaction":
|
|
150
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
151
|
+
case "eth_signTypedData":
|
|
152
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
153
|
+
case "eth_signTypedData_v3":
|
|
154
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
155
|
+
// TODO: we're currently mimicking the MetaMask implementation here.
|
|
156
|
+
// The EIP 712 is still a draft. It doesn't actually distinguish different versions
|
|
157
|
+
// of the eth_signTypedData API.
|
|
158
|
+
// Also, note that go-ethereum implemented this in a clef JSON-RPC API: account_signTypedData.
|
|
159
|
+
case "eth_signTypedData_v4":
|
|
160
|
+
return this._signTypedDataV4Action(...this._signTypedDataV4Params(params));
|
|
161
|
+
case "eth_submitHashrate":
|
|
162
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
163
|
+
case "eth_submitWork":
|
|
164
|
+
throw new errors_1.MethodNotSupportedError(method);
|
|
165
|
+
case "eth_subscribe":
|
|
166
|
+
return this._subscribeAction(...this._subscribeParams(params));
|
|
167
|
+
case "eth_syncing":
|
|
168
|
+
return this._syncingAction(...this._syncingParams(params));
|
|
169
|
+
case "eth_uninstallFilter":
|
|
170
|
+
return this._uninstallFilterAction(...this._uninstallFilterParams(params));
|
|
171
|
+
case "eth_unsubscribe":
|
|
172
|
+
return this._unsubscribeAction(...this._unsubscribeParams(params));
|
|
173
|
+
case "eth_feeHistory":
|
|
174
|
+
return this._feeHistoryAction(...this._feeHistoryParams(params));
|
|
175
|
+
}
|
|
176
|
+
throw new errors_1.MethodNotFoundError(`Method ${method} not found`);
|
|
177
|
+
}
|
|
178
|
+
// eth_accounts
|
|
179
|
+
_accountsParams(params) {
|
|
180
|
+
return (0, validation_1.validateParams)(params);
|
|
181
|
+
}
|
|
182
|
+
async _accountsAction() {
|
|
183
|
+
return this._node.getLocalAccountAddresses();
|
|
184
|
+
}
|
|
185
|
+
// eth_blockNumber
|
|
186
|
+
_blockNumberParams(params) {
|
|
187
|
+
return (0, validation_1.validateParams)(params);
|
|
188
|
+
}
|
|
189
|
+
async _blockNumberAction() {
|
|
190
|
+
const blockNumber = this._node.getLatestBlockNumber();
|
|
191
|
+
return (0, base_types_1.numberToRpcQuantity)(blockNumber);
|
|
192
|
+
}
|
|
193
|
+
// eth_call
|
|
194
|
+
_callParams(params) {
|
|
195
|
+
return (0, validation_1.validateParams)(params, callRequest_1.rpcCallRequest, blockTag_1.optionalRpcNewBlockTag, callRequest_1.optionalStateOverrideSet);
|
|
196
|
+
}
|
|
197
|
+
async _callAction(rpcCall, blockTag, stateOverrideSet) {
|
|
198
|
+
this._validateTransactionAndCallRequest(rpcCall);
|
|
199
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag);
|
|
200
|
+
const callParams = await this.rpcCallRequestToNodeCallParams(rpcCall);
|
|
201
|
+
const { result: returnData, trace, error, consoleLogMessages, } = await this._node.runCall(callParams, blockNumberOrPending, stateOverrideSet);
|
|
202
|
+
const code = await this._node.getCodeFromTrace(trace, blockNumberOrPending);
|
|
203
|
+
this._logger.logCallTrace(callParams, code, trace, consoleLogMessages, error);
|
|
204
|
+
await this._runHardhatNetworkMessageTraceHooks(trace, true);
|
|
205
|
+
if (error !== undefined && this._throwOnCallFailures) {
|
|
206
|
+
const callReturnData = trace?.returnData.toString("hex") ?? "";
|
|
207
|
+
error.data = `0x${callReturnData}`;
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
return (0, base_types_1.bufferToRpcData)(returnData.value);
|
|
211
|
+
}
|
|
212
|
+
// eth_chainId
|
|
213
|
+
_chainIdParams(params) {
|
|
214
|
+
return (0, validation_1.validateParams)(params);
|
|
215
|
+
}
|
|
216
|
+
async _chainIdAction() {
|
|
217
|
+
return (0, base_types_1.numberToRpcQuantity)(this._common.chainId());
|
|
218
|
+
}
|
|
219
|
+
// eth_coinbase
|
|
220
|
+
_coinbaseParams(params) {
|
|
221
|
+
return (0, validation_1.validateParams)(params);
|
|
222
|
+
}
|
|
223
|
+
async _coinbaseAction() {
|
|
224
|
+
return this._node.getCoinbaseAddress().toString();
|
|
225
|
+
}
|
|
226
|
+
// eth_compileLLL
|
|
227
|
+
// eth_compileSerpent
|
|
228
|
+
// eth_compileSolidity
|
|
229
|
+
// eth_estimateGas
|
|
230
|
+
_estimateGasParams(params) {
|
|
231
|
+
// Estimate gas uses a CallArgs in Geth, so we mimic it here
|
|
232
|
+
return (0, validation_1.validateParams)(params, callRequest_1.rpcCallRequest, blockTag_1.optionalRpcNewBlockTag);
|
|
233
|
+
}
|
|
234
|
+
async _estimateGasAction(callRequest, blockTag) {
|
|
235
|
+
this._validateTransactionAndCallRequest(callRequest);
|
|
236
|
+
// estimateGas behaves differently when there's no blockTag
|
|
237
|
+
// it uses "pending" as default instead of "latest"
|
|
238
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag, "pending");
|
|
239
|
+
const callParams = await this.rpcCallRequestToNodeCallParams(callRequest);
|
|
240
|
+
const { estimation, error, trace, consoleLogMessages } = await this._node.estimateGas(callParams, blockNumberOrPending);
|
|
241
|
+
if (error !== undefined) {
|
|
242
|
+
const code = await this._node.getCodeFromTrace(trace, blockNumberOrPending);
|
|
243
|
+
this._logger.logEstimateGasTrace(callParams, code, trace, consoleLogMessages, error);
|
|
244
|
+
const callReturnData = trace?.returnData.toString("hex") ?? "";
|
|
245
|
+
error.data = `0x${callReturnData}`;
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
return (0, base_types_1.numberToRpcQuantity)(estimation);
|
|
249
|
+
}
|
|
250
|
+
// eth_gasPrice
|
|
251
|
+
_gasPriceParams(params) {
|
|
252
|
+
return (0, validation_1.validateParams)(params);
|
|
253
|
+
}
|
|
254
|
+
async _gasPriceAction() {
|
|
255
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.getGasPrice());
|
|
256
|
+
}
|
|
257
|
+
// eth_getBalance
|
|
258
|
+
_getBalanceParams(params) {
|
|
259
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, blockTag_1.optionalRpcNewBlockTag);
|
|
260
|
+
}
|
|
261
|
+
async _getBalanceAction(address, blockTag) {
|
|
262
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag);
|
|
263
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.getAccountBalance(new ethereumjs_util_1.Address(address), blockNumberOrPending));
|
|
264
|
+
}
|
|
265
|
+
// eth_getBlockByHash
|
|
266
|
+
_getBlockByHashParams(params) {
|
|
267
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcHash, t.boolean);
|
|
268
|
+
}
|
|
269
|
+
async _getBlockByHashAction(hash, includeTransactions) {
|
|
270
|
+
const block = await this._node.getBlockByHash(hash);
|
|
271
|
+
if (block === undefined) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const totalDifficulty = await this._node.getBlockTotalDifficulty(block);
|
|
275
|
+
return (0, output_1.getRpcBlock)(block, totalDifficulty, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), includeTransactions);
|
|
276
|
+
}
|
|
277
|
+
// eth_getBlockByNumber
|
|
278
|
+
_getBlockByNumberParams(params) {
|
|
279
|
+
return (0, validation_1.validateParams)(params, blockTag_1.rpcOldBlockTag, t.boolean);
|
|
280
|
+
}
|
|
281
|
+
async _getBlockByNumberAction(oldBlockTag, includeTransactions) {
|
|
282
|
+
const numberOrPending = await this._resolveOldBlockTag(oldBlockTag);
|
|
283
|
+
if (numberOrPending === undefined) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
let block;
|
|
287
|
+
let totalDifficulty;
|
|
288
|
+
if (numberOrPending === "pending") {
|
|
289
|
+
[block, totalDifficulty] =
|
|
290
|
+
await this._node.getPendingBlockAndTotalDifficulty();
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
block = await this._node.getBlockByNumber(numberOrPending);
|
|
294
|
+
if (block === undefined) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
totalDifficulty = await this._node.getBlockTotalDifficulty(block);
|
|
298
|
+
}
|
|
299
|
+
return (0, output_1.getRpcBlock)(block, totalDifficulty, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), includeTransactions, numberOrPending === "pending");
|
|
300
|
+
}
|
|
301
|
+
// eth_getBlockTransactionCountByHash
|
|
302
|
+
_getBlockTransactionCountByHashParams(params) {
|
|
303
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcHash);
|
|
304
|
+
}
|
|
305
|
+
async _getBlockTransactionCountByHashAction(hash) {
|
|
306
|
+
const block = await this._node.getBlockByHash(hash);
|
|
307
|
+
if (block === undefined) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
return (0, base_types_1.numberToRpcQuantity)(block.transactions.length);
|
|
311
|
+
}
|
|
312
|
+
// eth_getBlockTransactionCountByNumber
|
|
313
|
+
_getBlockTransactionCountByNumberParams(params) {
|
|
314
|
+
return (0, validation_1.validateParams)(params, blockTag_1.rpcOldBlockTag);
|
|
315
|
+
}
|
|
316
|
+
async _getBlockTransactionCountByNumberAction(oldBlockTag) {
|
|
317
|
+
const numberOrPending = await this._resolveOldBlockTag(oldBlockTag);
|
|
318
|
+
if (numberOrPending === undefined) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
const block = await this._node.getBlockByNumber(numberOrPending);
|
|
322
|
+
if (block === undefined) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return (0, base_types_1.numberToRpcQuantity)(block.transactions.length);
|
|
326
|
+
}
|
|
327
|
+
// eth_getCode
|
|
328
|
+
_getCodeParams(params) {
|
|
329
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, blockTag_1.optionalRpcNewBlockTag);
|
|
330
|
+
}
|
|
331
|
+
async _getCodeAction(address, blockTag) {
|
|
332
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag);
|
|
333
|
+
return (0, base_types_1.bufferToRpcData)(await this._node.getCode(new ethereumjs_util_1.Address(address), blockNumberOrPending));
|
|
334
|
+
}
|
|
335
|
+
// eth_getCompilers
|
|
336
|
+
// eth_getFilterChanges
|
|
337
|
+
_getFilterChangesParams(params) {
|
|
338
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcQuantity);
|
|
339
|
+
}
|
|
340
|
+
async _getFilterChangesAction(filterId) {
|
|
341
|
+
const changes = await this._node.getFilterChanges(filterId);
|
|
342
|
+
if (changes === undefined) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
return changes;
|
|
346
|
+
}
|
|
347
|
+
// eth_getFilterLogs
|
|
348
|
+
_getFilterLogsParams(params) {
|
|
349
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcQuantity);
|
|
350
|
+
}
|
|
351
|
+
async _getFilterLogsAction(filterId) {
|
|
352
|
+
const changes = await this._node.getFilterLogs(filterId);
|
|
353
|
+
if (changes === undefined) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
return changes;
|
|
357
|
+
}
|
|
358
|
+
// eth_getLogs
|
|
359
|
+
_getLogsParams(params) {
|
|
360
|
+
return (0, validation_1.validateParams)(params, filterRequest_1.rpcFilterRequest);
|
|
361
|
+
}
|
|
362
|
+
async _rpcFilterRequestToGetLogsParams(filter) {
|
|
363
|
+
if (filter.blockHash !== undefined) {
|
|
364
|
+
if (filter.fromBlock !== undefined || filter.toBlock !== undefined) {
|
|
365
|
+
throw new errors_1.InvalidArgumentsError("blockHash is mutually exclusive with fromBlock/toBlock");
|
|
366
|
+
}
|
|
367
|
+
const block = await this._node.getBlockByHash(filter.blockHash);
|
|
368
|
+
if (block === undefined) {
|
|
369
|
+
throw new errors_1.InvalidArgumentsError("blockHash cannot be found");
|
|
370
|
+
}
|
|
371
|
+
filter.fromBlock = block.header.number;
|
|
372
|
+
filter.toBlock = block.header.number;
|
|
373
|
+
}
|
|
374
|
+
const [fromBlock, toBlock] = await Promise.all([
|
|
375
|
+
this._normalizeOldBlockTagForFilterRequest(filter.fromBlock),
|
|
376
|
+
this._normalizeOldBlockTagForFilterRequest(filter.toBlock),
|
|
377
|
+
]);
|
|
378
|
+
return {
|
|
379
|
+
fromBlock,
|
|
380
|
+
toBlock,
|
|
381
|
+
normalizedTopics: this._extractNormalizedLogTopics(filter.topics),
|
|
382
|
+
addresses: this._extractLogAddresses(filter.address),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
async _getLogsAction(filter) {
|
|
386
|
+
const filterParams = await this._rpcFilterRequestToGetLogsParams(filter);
|
|
387
|
+
const logs = await this._node.getLogs(filterParams);
|
|
388
|
+
return (0, cloneDeep_1.default)(logs);
|
|
389
|
+
}
|
|
390
|
+
// eth_getProof
|
|
391
|
+
// eth_getStorageAt
|
|
392
|
+
_getStorageAtParams(params) {
|
|
393
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, base_types_1.rpcStorageSlot, blockTag_1.optionalRpcNewBlockTag);
|
|
394
|
+
}
|
|
395
|
+
async _getStorageAtAction(address, slot, blockTag) {
|
|
396
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag);
|
|
397
|
+
const data = await this._node.getStorageAt(new ethereumjs_util_1.Address(address), slot, blockNumberOrPending);
|
|
398
|
+
return (0, base_types_1.bufferToRpcData)(data);
|
|
399
|
+
}
|
|
400
|
+
// eth_getTransactionByBlockHashAndIndex
|
|
401
|
+
_getTransactionByBlockHashAndIndexParams(params) {
|
|
402
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcHash, base_types_1.rpcQuantity);
|
|
403
|
+
}
|
|
404
|
+
async _getTransactionByBlockHashAndIndexAction(hash, index) {
|
|
405
|
+
const i = Number(index);
|
|
406
|
+
const block = await this._node.getBlockByHash(hash);
|
|
407
|
+
if (block === undefined) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
const tx = block.transactions[i];
|
|
411
|
+
if (tx === undefined) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
return (0, output_1.getRpcTransaction)(tx, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), block, i);
|
|
415
|
+
}
|
|
416
|
+
// eth_getTransactionByBlockNumberAndIndex
|
|
417
|
+
_getTransactionByBlockNumberAndIndexParams(params) {
|
|
418
|
+
return (0, validation_1.validateParams)(params, blockTag_1.rpcOldBlockTag, base_types_1.rpcQuantity);
|
|
419
|
+
}
|
|
420
|
+
async _getTransactionByBlockNumberAndIndexAction(oldBlockTag, index) {
|
|
421
|
+
const numberOrPending = await this._resolveOldBlockTag(oldBlockTag);
|
|
422
|
+
if (numberOrPending === undefined) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
const block = await this._node.getBlockByNumber(numberOrPending);
|
|
426
|
+
const i = Number(index);
|
|
427
|
+
if (block === undefined) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
const tx = block.transactions[i];
|
|
431
|
+
if (tx === undefined) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
const showTransactionType = (0, output_1.shouldShowTransactionTypeForHardfork)(this._common);
|
|
435
|
+
return numberOrPending === "pending"
|
|
436
|
+
? (0, output_1.getRpcTransaction)(tx, showTransactionType, "pending")
|
|
437
|
+
: (0, output_1.getRpcTransaction)(tx, showTransactionType, block, i);
|
|
438
|
+
}
|
|
439
|
+
// eth_getTransactionByHash
|
|
440
|
+
_getTransactionByHashParams(params) {
|
|
441
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcHash);
|
|
442
|
+
}
|
|
443
|
+
async _getTransactionByHashAction(hash) {
|
|
444
|
+
const pendingTx = await this._node.getPendingTransaction(hash);
|
|
445
|
+
if (pendingTx !== undefined) {
|
|
446
|
+
return (0, output_1.getRpcTransaction)(pendingTx, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), "pending");
|
|
447
|
+
}
|
|
448
|
+
const block = await this._node.getBlockByTransactionHash(hash);
|
|
449
|
+
if (block === undefined) {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
const index = block.transactions.findIndex((btx) => btx.hash().equals(hash));
|
|
453
|
+
const tx = block.transactions[index];
|
|
454
|
+
if (tx === undefined) {
|
|
455
|
+
throw new Error("Transaction not found in the saved block, this should never happen");
|
|
456
|
+
}
|
|
457
|
+
return (0, output_1.getRpcTransaction)(tx, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), block, index);
|
|
458
|
+
}
|
|
459
|
+
// eth_getTransactionCount
|
|
460
|
+
_getTransactionCountParams(params) {
|
|
461
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, blockTag_1.optionalRpcNewBlockTag);
|
|
462
|
+
}
|
|
463
|
+
async _getTransactionCountAction(address, blockTag) {
|
|
464
|
+
const blockNumberOrPending = await this.resolveNewBlockTag(blockTag);
|
|
465
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.getNextConfirmedNonce(new ethereumjs_util_1.Address(address), blockNumberOrPending));
|
|
466
|
+
}
|
|
467
|
+
// eth_getTransactionReceipt
|
|
468
|
+
_getTransactionReceiptParams(params) {
|
|
469
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcHash);
|
|
470
|
+
}
|
|
471
|
+
async _getTransactionReceiptAction(hash) {
|
|
472
|
+
const receipt = await this._node.getTransactionReceipt(hash);
|
|
473
|
+
if (receipt === undefined) {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
return (0, cloneDeep_1.default)(receipt);
|
|
477
|
+
}
|
|
478
|
+
// eth_getUncleByBlockHashAndIndex
|
|
479
|
+
// TODO: Implement
|
|
480
|
+
// eth_getUncleByBlockNumberAndIndex
|
|
481
|
+
// TODO: Implement
|
|
482
|
+
// eth_getUncleCountByBlockHash
|
|
483
|
+
// TODO: Implement
|
|
484
|
+
// eth_getUncleCountByBlockNumber
|
|
485
|
+
// TODO: Implement
|
|
486
|
+
// eth_getWork
|
|
487
|
+
// eth_hashrate
|
|
488
|
+
// eth_mining
|
|
489
|
+
_miningParams(params) {
|
|
490
|
+
return (0, validation_1.validateParams)(params);
|
|
491
|
+
}
|
|
492
|
+
async _miningAction() {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
// eth_newBlockFilter
|
|
496
|
+
_newBlockFilterParams(_params) {
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
async _newBlockFilterAction() {
|
|
500
|
+
const filterId = await this._node.newBlockFilter(false);
|
|
501
|
+
return (0, base_types_1.numberToRpcQuantity)(filterId);
|
|
502
|
+
}
|
|
503
|
+
// eth_newFilter
|
|
504
|
+
_newFilterParams(params) {
|
|
505
|
+
return (0, validation_1.validateParams)(params, filterRequest_1.rpcFilterRequest);
|
|
506
|
+
}
|
|
507
|
+
async _newFilterAction(filter) {
|
|
508
|
+
const filterParams = await this._rpcFilterRequestToGetLogsParams(filter);
|
|
509
|
+
const filterId = await this._node.newFilter(filterParams, false);
|
|
510
|
+
return (0, base_types_1.numberToRpcQuantity)(filterId);
|
|
511
|
+
}
|
|
512
|
+
// eth_newPendingTransactionFilter
|
|
513
|
+
_newPendingTransactionParams(_params) {
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
async _newPendingTransactionAction() {
|
|
517
|
+
const filterId = await this._node.newPendingTransactionFilter(false);
|
|
518
|
+
return (0, base_types_1.numberToRpcQuantity)(filterId);
|
|
519
|
+
}
|
|
520
|
+
// eth_pendingTransactions
|
|
521
|
+
_pendingTransactionsParams(_params) {
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
async _pendingTransactionsAction() {
|
|
525
|
+
const txs = await this._node.getPendingTransactions();
|
|
526
|
+
return txs.map((tx) => (0, output_1.getRpcTransaction)(tx, (0, output_1.shouldShowTransactionTypeForHardfork)(this._common), "pending"));
|
|
527
|
+
}
|
|
528
|
+
// eth_protocolVersion
|
|
529
|
+
// eth_sendRawTransaction
|
|
530
|
+
_sendRawTransactionParams(params) {
|
|
531
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcData);
|
|
532
|
+
}
|
|
533
|
+
async _sendRawTransactionAction(rawTx) {
|
|
534
|
+
this._validateRawTransactionHardforkRequirements(rawTx);
|
|
535
|
+
let tx;
|
|
536
|
+
try {
|
|
537
|
+
tx = ethereumjs_tx_1.TransactionFactory.fromSerializedData(rawTx, {
|
|
538
|
+
common: this._common,
|
|
539
|
+
disableMaxInitCodeSizeCheck: true,
|
|
540
|
+
});
|
|
541
|
+
this._validateEip3860MaxInitCodeSize(tx.to?.toBuffer(), tx.data);
|
|
542
|
+
}
|
|
543
|
+
catch (error) {
|
|
544
|
+
// This section of the code is incredibly dependant of TransactionFactory.fromSerializedData
|
|
545
|
+
// AccessListEIP2930Transaction.fromSerializedTx and Transaction.fromSerializedTx
|
|
546
|
+
// Please keep it updated.
|
|
547
|
+
if (error instanceof Error) {
|
|
548
|
+
if (error.message === "invalid RLP: remainder must be zero") {
|
|
549
|
+
throw new errors_1.InvalidArgumentsError("Invalid transaction", error);
|
|
550
|
+
}
|
|
551
|
+
if (error.message.includes("Incompatible EIP155")) {
|
|
552
|
+
throw new errors_1.InvalidArgumentsError("Trying to send an incompatible EIP-155 transaction, signed for another chain.", error);
|
|
553
|
+
}
|
|
554
|
+
if (error.message.includes("TypedTransaction with ID") &&
|
|
555
|
+
error.message.includes(" unknown")) {
|
|
556
|
+
throw new errors_1.InvalidArgumentsError(`Invalid transaction`, error);
|
|
557
|
+
}
|
|
558
|
+
if (error.message.includes("The chain ID does not match")) {
|
|
559
|
+
const chainId = this._common.chainId();
|
|
560
|
+
throw new errors_1.InvalidArgumentsError(`Trying to send a raw transaction with an invalid chainId. The expected chainId is ${chainId}`, error);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
throw error;
|
|
564
|
+
}
|
|
565
|
+
if (!tx.isSigned()) {
|
|
566
|
+
throw new errors_1.InvalidArgumentsError("Invalid Signature");
|
|
567
|
+
}
|
|
568
|
+
if (tx instanceof ethereumjs_tx_1.Transaction) {
|
|
569
|
+
this._validateEip155HardforkRequirement(tx);
|
|
570
|
+
}
|
|
571
|
+
return this._sendTransactionAndReturnHash(tx);
|
|
572
|
+
}
|
|
573
|
+
// eth_sendTransaction
|
|
574
|
+
_sendTransactionParams(params) {
|
|
575
|
+
return (0, validation_1.validateParams)(params, transactionRequest_1.rpcTransactionRequest);
|
|
576
|
+
}
|
|
577
|
+
async _sendTransactionAction(transactionRequest) {
|
|
578
|
+
this._validateEip3860MaxInitCodeSize(transactionRequest.to, transactionRequest.data ?? Buffer.from([]));
|
|
579
|
+
const expectedChainId = this._common.chainId();
|
|
580
|
+
if (transactionRequest.chainId !== undefined &&
|
|
581
|
+
transactionRequest.chainId !== expectedChainId) {
|
|
582
|
+
throw new errors_1.InvalidArgumentsError(`Invalid chainId ${transactionRequest.chainId.toString()} provided, expected ${expectedChainId.toString()} instead.`);
|
|
583
|
+
}
|
|
584
|
+
this._validateTransactionAndCallRequest(transactionRequest);
|
|
585
|
+
const txParams = await this._rpcTransactionRequestToNodeTransactionParams(transactionRequest);
|
|
586
|
+
const tx = await this._node.getSignedTransaction(txParams);
|
|
587
|
+
return this._sendTransactionAndReturnHash(tx);
|
|
588
|
+
}
|
|
589
|
+
// eth_sign
|
|
590
|
+
_signParams(params) {
|
|
591
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, base_types_1.rpcData);
|
|
592
|
+
}
|
|
593
|
+
async _signAction(address, data) {
|
|
594
|
+
const signature = await this._node.signPersonalMessage(new ethereumjs_util_1.Address(address), data);
|
|
595
|
+
return (0, ethereumjs_util_1.toRpcSig)(signature.v, signature.r, signature.s);
|
|
596
|
+
}
|
|
597
|
+
// eth_signTransaction
|
|
598
|
+
// eth_signTypedData_v4
|
|
599
|
+
_signTypedDataV4Params(params) {
|
|
600
|
+
// Validation of the TypedData parameter is handled by eth-sig-util
|
|
601
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcAddress, t.any);
|
|
602
|
+
}
|
|
603
|
+
async _signTypedDataV4Action(address, typedData) {
|
|
604
|
+
let typedMessage = typedData;
|
|
605
|
+
// According to the MetaMask implementation,
|
|
606
|
+
// the message parameter may be JSON stringified in versions later than V1
|
|
607
|
+
// See https://github.com/MetaMask/metamask-extension/blob/0dfdd44ae7728ed02cbf32c564c75b74f37acf77/app/scripts/metamask-controller.js#L1736
|
|
608
|
+
// In fact, ethers.js JSON stringifies the message at the time of writing.
|
|
609
|
+
if (typeof typedData === "string") {
|
|
610
|
+
try {
|
|
611
|
+
typedMessage = JSON.parse(typedData);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
throw new errors_1.InvalidInputError(`The message parameter is an invalid JSON. Either pass a valid JSON or a plain object conforming to EIP712 TypedData schema.`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return this._node.signTypedDataV4(new ethereumjs_util_1.Address(address), typedMessage);
|
|
618
|
+
}
|
|
619
|
+
// eth_submitHashrate
|
|
620
|
+
// eth_submitWork
|
|
621
|
+
_subscribeParams(params) {
|
|
622
|
+
if (params.length === 0) {
|
|
623
|
+
throw new errors_1.InvalidInputError("Expected subscription name as first argument");
|
|
624
|
+
}
|
|
625
|
+
return (0, validation_1.validateParams)(params, subscribeRequest_1.rpcSubscribeRequest, filterRequest_1.optionalRpcFilterRequest);
|
|
626
|
+
}
|
|
627
|
+
async _subscribeAction(subscribeRequest, optionalFilterRequest) {
|
|
628
|
+
switch (subscribeRequest) {
|
|
629
|
+
case "newHeads":
|
|
630
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.newBlockFilter(true));
|
|
631
|
+
case "newPendingTransactions":
|
|
632
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.newPendingTransactionFilter(true));
|
|
633
|
+
case "logs":
|
|
634
|
+
if (optionalFilterRequest === undefined) {
|
|
635
|
+
throw new errors_1.InvalidArgumentsError("missing params argument");
|
|
636
|
+
}
|
|
637
|
+
const filterParams = await this._rpcFilterRequestToGetLogsParams(optionalFilterRequest);
|
|
638
|
+
return (0, base_types_1.numberToRpcQuantity)(await this._node.newFilter(filterParams, true));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
// eth_syncing
|
|
642
|
+
_syncingParams(params) {
|
|
643
|
+
return (0, validation_1.validateParams)(params);
|
|
644
|
+
}
|
|
645
|
+
async _syncingAction() {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
// eth_uninstallFilter
|
|
649
|
+
_uninstallFilterParams(params) {
|
|
650
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcQuantity);
|
|
651
|
+
}
|
|
652
|
+
async _uninstallFilterAction(filterId) {
|
|
653
|
+
return this._node.uninstallFilter(filterId, false);
|
|
654
|
+
}
|
|
655
|
+
// eth_unsubscribe
|
|
656
|
+
_unsubscribeParams(params) {
|
|
657
|
+
return (0, validation_1.validateParams)(params, base_types_1.rpcQuantity);
|
|
658
|
+
}
|
|
659
|
+
async _unsubscribeAction(filterId) {
|
|
660
|
+
return this._node.uninstallFilter(filterId, true);
|
|
661
|
+
}
|
|
662
|
+
// eth_feeHistory
|
|
663
|
+
_feeHistoryParams(params) {
|
|
664
|
+
const [blockCount, newestBlock, rewardPercentiles] = (0, validation_1.validateParams)(params, base_types_1.rpcQuantity, blockTag_1.rpcNewBlockTag, (0, io_ts_1.optional)(t.array(base_types_1.rpcFloat)));
|
|
665
|
+
if (blockCount < 1n) {
|
|
666
|
+
throw new errors_1.InvalidInputError(`blockCount should be at least 1`);
|
|
667
|
+
}
|
|
668
|
+
if (blockCount > 1024n) {
|
|
669
|
+
throw new errors_1.InvalidInputError(`blockCount should be at most 1024`);
|
|
670
|
+
}
|
|
671
|
+
if (rewardPercentiles !== undefined) {
|
|
672
|
+
for (const [i, p] of rewardPercentiles.entries()) {
|
|
673
|
+
if (p < 0 || p > 100) {
|
|
674
|
+
throw new errors_1.InvalidInputError(`The reward percentile number ${i + 1} is invalid. It must be a float between 0 and 100, but is ${p} instead.`);
|
|
675
|
+
}
|
|
676
|
+
if (i !== 0) {
|
|
677
|
+
const prev = rewardPercentiles[i - 1];
|
|
678
|
+
if (prev > p) {
|
|
679
|
+
throw new errors_1.InvalidInputError(`The reward percentiles should be in non-decreasing order, but the percentile number ${i} is greater than the next one`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return [blockCount, newestBlock, rewardPercentiles];
|
|
685
|
+
}
|
|
686
|
+
async _feeHistoryAction(blockCount, newestBlock, rewardPercentiles) {
|
|
687
|
+
if (!this._node.isEip1559Active()) {
|
|
688
|
+
throw new errors_1.InvalidInputError(`eth_feeHistory is disabled. It only works with the London hardfork or a later one.`);
|
|
689
|
+
}
|
|
690
|
+
const resolvedNewestBlock = await this.resolveNewBlockTag(newestBlock);
|
|
691
|
+
const feeHistory = await this._node.getFeeHistory(blockCount, resolvedNewestBlock, rewardPercentiles ?? []);
|
|
692
|
+
const oldestBlock = (0, base_types_1.numberToRpcQuantity)(feeHistory.oldestBlock);
|
|
693
|
+
const baseFeePerGas = feeHistory.baseFeePerGas.map(base_types_1.numberToRpcQuantity);
|
|
694
|
+
const gasUsedRatio = feeHistory.gasUsedRatio;
|
|
695
|
+
const reward = feeHistory.reward?.map((rs) => rs.map(base_types_1.numberToRpcQuantity));
|
|
696
|
+
return {
|
|
697
|
+
oldestBlock,
|
|
698
|
+
baseFeePerGas,
|
|
699
|
+
gasUsedRatio,
|
|
700
|
+
reward,
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
// Utility methods
|
|
704
|
+
async _rpcTransactionRequestToNodeTransactionParams(rpcTx) {
|
|
705
|
+
const baseParams = {
|
|
706
|
+
to: rpcTx.to,
|
|
707
|
+
from: rpcTx.from,
|
|
708
|
+
gasLimit: rpcTx.gas !== undefined ? rpcTx.gas : this._node.getBlockGasLimit(),
|
|
709
|
+
value: rpcTx.value !== undefined ? rpcTx.value : 0n,
|
|
710
|
+
data: rpcTx.data !== undefined ? rpcTx.data : (0, ethereumjs_util_1.toBuffer)([]),
|
|
711
|
+
nonce: rpcTx.nonce !== undefined
|
|
712
|
+
? rpcTx.nonce
|
|
713
|
+
: await this._node.getAccountNextPendingNonce(new ethereumjs_util_1.Address(rpcTx.from)),
|
|
714
|
+
};
|
|
715
|
+
if (this._node.isEip1559Active() &&
|
|
716
|
+
(rpcTx.maxFeePerGas !== undefined ||
|
|
717
|
+
rpcTx.maxPriorityFeePerGas !== undefined ||
|
|
718
|
+
rpcTx.gasPrice === undefined)) {
|
|
719
|
+
const accessList = rpcTx.accessList !== undefined
|
|
720
|
+
? this._rpcAccessListToNodeAccessList(rpcTx.accessList)
|
|
721
|
+
: [];
|
|
722
|
+
if (rpcTx.maxPriorityFeePerGas === undefined) {
|
|
723
|
+
rpcTx.maxPriorityFeePerGas = await this._node.getMaxPriorityFeePerGas();
|
|
724
|
+
// If you only provide a maxFeePerGas, and the suggested tip is higher
|
|
725
|
+
// than that, we adjust the tip to make the tx valid
|
|
726
|
+
if (rpcTx.maxFeePerGas !== undefined &&
|
|
727
|
+
rpcTx.maxFeePerGas < rpcTx.maxPriorityFeePerGas) {
|
|
728
|
+
rpcTx.maxPriorityFeePerGas = rpcTx.maxFeePerGas;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (rpcTx.maxFeePerGas === undefined) {
|
|
732
|
+
const baseFeePerGas = await this._node.getNextBlockBaseFeePerGas();
|
|
733
|
+
(0, assertions_1.assertHardhatNetworkInvariant)(baseFeePerGas !== undefined, "EIP-1559 transactions should only be sent if the next block has baseFeePerGas");
|
|
734
|
+
rpcTx.maxFeePerGas = 2n * baseFeePerGas + rpcTx.maxPriorityFeePerGas;
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
...baseParams,
|
|
738
|
+
maxFeePerGas: rpcTx.maxFeePerGas,
|
|
739
|
+
maxPriorityFeePerGas: rpcTx.maxPriorityFeePerGas,
|
|
740
|
+
accessList,
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
const gasPrice = rpcTx.gasPrice ?? (await this._node.getGasPrice());
|
|
744
|
+
// AccessList params
|
|
745
|
+
if (rpcTx.accessList !== undefined) {
|
|
746
|
+
return {
|
|
747
|
+
...baseParams,
|
|
748
|
+
gasPrice,
|
|
749
|
+
accessList: this._rpcAccessListToNodeAccessList(rpcTx.accessList),
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
// Legacy params
|
|
753
|
+
return {
|
|
754
|
+
...baseParams,
|
|
755
|
+
gasPrice,
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
async _resolveOldBlockTag(oldBlockTag) {
|
|
759
|
+
if (oldBlockTag === undefined || oldBlockTag === "latest") {
|
|
760
|
+
return this._node.getLatestBlockNumber();
|
|
761
|
+
}
|
|
762
|
+
if (oldBlockTag === "pending") {
|
|
763
|
+
return "pending";
|
|
764
|
+
}
|
|
765
|
+
if (oldBlockTag === "earliest") {
|
|
766
|
+
return 0n;
|
|
767
|
+
}
|
|
768
|
+
if (oldBlockTag === "safe" || oldBlockTag === "finalized") {
|
|
769
|
+
this._checkPostMergeBlockTags(oldBlockTag);
|
|
770
|
+
return this._node.getLatestBlockNumber();
|
|
771
|
+
}
|
|
772
|
+
const block = await this._node.getBlockByNumber(oldBlockTag);
|
|
773
|
+
return block?.header.number;
|
|
774
|
+
}
|
|
775
|
+
async _resolveNewBlockTag(newBlockTag, defaultValue = "latest") {
|
|
776
|
+
if (newBlockTag === undefined) {
|
|
777
|
+
newBlockTag = defaultValue;
|
|
778
|
+
}
|
|
779
|
+
if (newBlockTag === "pending") {
|
|
780
|
+
return "pending";
|
|
781
|
+
}
|
|
782
|
+
if (newBlockTag === "latest") {
|
|
783
|
+
return this._node.getLatestBlockNumber();
|
|
784
|
+
}
|
|
785
|
+
if (newBlockTag === "earliest") {
|
|
786
|
+
return 0n;
|
|
787
|
+
}
|
|
788
|
+
if (newBlockTag === "safe" || newBlockTag === "finalized") {
|
|
789
|
+
this._checkPostMergeBlockTags(newBlockTag);
|
|
790
|
+
return this._node.getLatestBlockNumber();
|
|
791
|
+
}
|
|
792
|
+
if (!BigIntUtils.isBigInt(newBlockTag)) {
|
|
793
|
+
if ("blockNumber" in newBlockTag && "blockHash" in newBlockTag) {
|
|
794
|
+
throw new errors_1.InvalidArgumentsError("Invalid block tag received. Only one of hash or block number can be used.");
|
|
795
|
+
}
|
|
796
|
+
if ("blockNumber" in newBlockTag && "requireCanonical" in newBlockTag) {
|
|
797
|
+
throw new errors_1.InvalidArgumentsError("Invalid block tag received. requireCanonical only works with hashes.");
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
let block;
|
|
801
|
+
if (BigIntUtils.isBigInt(newBlockTag)) {
|
|
802
|
+
block = await this._node.getBlockByNumber(newBlockTag);
|
|
803
|
+
}
|
|
804
|
+
else if ("blockNumber" in newBlockTag) {
|
|
805
|
+
block = await this._node.getBlockByNumber(newBlockTag.blockNumber);
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
block = await this._node.getBlockByHash(newBlockTag.blockHash);
|
|
809
|
+
}
|
|
810
|
+
if (block === undefined) {
|
|
811
|
+
const latestBlock = this._node.getLatestBlockNumber();
|
|
812
|
+
throw new errors_1.InvalidInputError(`Received invalid block tag ${this._newBlockTagToString(newBlockTag)}. Latest block number is ${latestBlock.toString()}`);
|
|
813
|
+
}
|
|
814
|
+
return block.header.number;
|
|
815
|
+
}
|
|
816
|
+
async _normalizeOldBlockTagForFilterRequest(blockTag) {
|
|
817
|
+
if (blockTag === undefined ||
|
|
818
|
+
blockTag === "latest" ||
|
|
819
|
+
blockTag === "pending") {
|
|
820
|
+
return filter_1.LATEST_BLOCK;
|
|
821
|
+
}
|
|
822
|
+
if (blockTag === "safe" || blockTag === "finalized") {
|
|
823
|
+
this._checkPostMergeBlockTags(blockTag);
|
|
824
|
+
return filter_1.LATEST_BLOCK;
|
|
825
|
+
}
|
|
826
|
+
if (blockTag === "earliest") {
|
|
827
|
+
return 0n;
|
|
828
|
+
}
|
|
829
|
+
return blockTag;
|
|
830
|
+
}
|
|
831
|
+
_extractNormalizedLogTopics(topics) {
|
|
832
|
+
if (topics === undefined || topics.length === 0) {
|
|
833
|
+
return [];
|
|
834
|
+
}
|
|
835
|
+
const normalizedTopics = [];
|
|
836
|
+
for (const topic of topics) {
|
|
837
|
+
if (Buffer.isBuffer(topic)) {
|
|
838
|
+
normalizedTopics.push([topic]);
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
normalizedTopics.push(topic);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return normalizedTopics;
|
|
845
|
+
}
|
|
846
|
+
_extractLogAddresses(address) {
|
|
847
|
+
if (address === undefined) {
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
if (Buffer.isBuffer(address)) {
|
|
851
|
+
return [address];
|
|
852
|
+
}
|
|
853
|
+
return address;
|
|
854
|
+
}
|
|
855
|
+
async _sendTransactionAndReturnHash(tx) {
|
|
856
|
+
let result = await this._node.sendTransaction(tx);
|
|
857
|
+
if (typeof result === "string") {
|
|
858
|
+
return result;
|
|
859
|
+
}
|
|
860
|
+
if (Array.isArray(result)) {
|
|
861
|
+
if (result.length === 1 && result[0].block.transactions.length > 1) {
|
|
862
|
+
this._logger.logMultipleTransactionsWarning();
|
|
863
|
+
}
|
|
864
|
+
else if (result.length > 1) {
|
|
865
|
+
this._logger.logMultipleBlocksWarning();
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
if (result.block.transactions.length > 1) {
|
|
870
|
+
this._logger.logMultipleTransactionsWarning();
|
|
871
|
+
}
|
|
872
|
+
result = [result];
|
|
873
|
+
}
|
|
874
|
+
const trace = await this._handleMineBlockResults(result, tx);
|
|
875
|
+
if (trace.error !== undefined && this._throwOnTransactionFailures) {
|
|
876
|
+
const e = trace.error;
|
|
877
|
+
const returnData = trace.trace?.returnData.toString("hex") ?? "";
|
|
878
|
+
e.data = `0x${returnData}`;
|
|
879
|
+
e.transactionHash = (0, base_types_1.bufferToRpcData)(tx.hash());
|
|
880
|
+
throw e;
|
|
881
|
+
}
|
|
882
|
+
return (0, base_types_1.bufferToRpcData)(tx.hash());
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Returns the trace of the sent tx
|
|
886
|
+
*/
|
|
887
|
+
async _handleMineBlockResults(results, sentTx) {
|
|
888
|
+
const singleTransactionMined = results.length === 1 && results[0].block.transactions.length === 1;
|
|
889
|
+
if (singleTransactionMined) {
|
|
890
|
+
const block = results[0].block;
|
|
891
|
+
const tx = block.transactions[0];
|
|
892
|
+
const txGasUsed = results[0].blockResult.results[0].totalGasSpent;
|
|
893
|
+
const trace = results[0].traces[0];
|
|
894
|
+
await this._logSingleTransaction(tx, block, txGasUsed, trace);
|
|
895
|
+
return trace;
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
// this happens when automine is enabled, a tx is sent, and there are
|
|
899
|
+
// pending txs in the mempool
|
|
900
|
+
for (const result of results) {
|
|
901
|
+
await this._logBlock(result, sentTx);
|
|
902
|
+
}
|
|
903
|
+
const [sentTxResult, sentTxIndex] = this._getTransactionResultAndIndex(sentTx, results);
|
|
904
|
+
const sentTxTrace = sentTxResult.traces[sentTxIndex];
|
|
905
|
+
if (!singleTransactionMined) {
|
|
906
|
+
const blockNumber = sentTxResult.block.header.number;
|
|
907
|
+
const code = await this._node.getCodeFromTrace(sentTxTrace.trace, blockNumber);
|
|
908
|
+
const { block, blockResult } = sentTxResult;
|
|
909
|
+
const gasUsed = blockResult.results[sentTxIndex].totalGasSpent;
|
|
910
|
+
this._logger.logCurrentlySentTransaction(sentTx, gasUsed, sentTxTrace, code, block);
|
|
911
|
+
}
|
|
912
|
+
return sentTxTrace;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
async _logSingleTransaction(tx, block, txGasUsed, txTrace) {
|
|
916
|
+
const code = await this._node.getCodeFromTrace(txTrace.trace, block.header.number);
|
|
917
|
+
this._logger.logSingleTransaction(tx, block, txGasUsed, txTrace, code);
|
|
918
|
+
await this._runHardhatNetworkMessageTraceHooks(txTrace.trace, false);
|
|
919
|
+
}
|
|
920
|
+
async _logBlock(result, sentTx) {
|
|
921
|
+
const { block, traces } = result;
|
|
922
|
+
const codes = [];
|
|
923
|
+
for (const txTrace of traces) {
|
|
924
|
+
const code = await this._node.getCodeFromTrace(txTrace.trace, block.header.number);
|
|
925
|
+
codes.push(code);
|
|
926
|
+
}
|
|
927
|
+
this._logger.logBlockFromAutomine(result, codes, sentTx.hash());
|
|
928
|
+
this._logger.logEmptyLine();
|
|
929
|
+
for (const txTrace of traces) {
|
|
930
|
+
await this._runHardhatNetworkMessageTraceHooks(txTrace.trace, false);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
_getTransactionResultAndIndex(tx, results) {
|
|
934
|
+
for (const result of results) {
|
|
935
|
+
const transactions = result.block.transactions;
|
|
936
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
937
|
+
const blockTx = transactions[i];
|
|
938
|
+
if (blockTx.hash().equals(tx.hash())) {
|
|
939
|
+
return [result, i];
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
throw new Error("The sent transaction not found in sendTransaction result, this should never happen");
|
|
944
|
+
}
|
|
945
|
+
async _runHardhatNetworkMessageTraceHooks(trace, isCall) {
|
|
946
|
+
if (trace === undefined) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
for (const hook of this._experimentalHardhatNetworkMessageTraceHooks) {
|
|
950
|
+
await hook(trace, isCall);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
_validateTransactionAndCallRequest(rpcRequest) {
|
|
954
|
+
if ((rpcRequest.maxFeePerGas !== undefined ||
|
|
955
|
+
rpcRequest.maxPriorityFeePerGas !== undefined) &&
|
|
956
|
+
!this._common.gteHardfork(EIP1559_MIN_HARDFORK)) {
|
|
957
|
+
throw new errors_1.InvalidArgumentsError(`EIP-1559 style fee params (maxFeePerGas or maxPriorityFeePerGas) received but they are not supported by the current hardfork.
|
|
958
|
+
|
|
959
|
+
You can use them by running Hardhat Network with 'hardfork' ${EIP1559_MIN_HARDFORK} or later.`);
|
|
960
|
+
}
|
|
961
|
+
// NOTE: This validation should go after the maxFeePerGas one, as EIP-1559
|
|
962
|
+
// also accepts access list.
|
|
963
|
+
if (rpcRequest.accessList !== undefined &&
|
|
964
|
+
!this._common.gteHardfork(ACCESS_LIST_MIN_HARDFORK)) {
|
|
965
|
+
throw new errors_1.InvalidArgumentsError(`Access list received but is not supported by the current hardfork.
|
|
966
|
+
|
|
967
|
+
You can use them by running Hardhat Network with 'hardfork' ${ACCESS_LIST_MIN_HARDFORK} or later.`);
|
|
968
|
+
}
|
|
969
|
+
if (rpcRequest.gasPrice !== undefined &&
|
|
970
|
+
rpcRequest.maxFeePerGas !== undefined) {
|
|
971
|
+
throw new errors_1.InvalidInputError("Cannot send both gasPrice and maxFeePerGas params");
|
|
972
|
+
}
|
|
973
|
+
if (rpcRequest.gasPrice !== undefined &&
|
|
974
|
+
rpcRequest.maxPriorityFeePerGas !== undefined) {
|
|
975
|
+
throw new errors_1.InvalidInputError("Cannot send both gasPrice and maxPriorityFeePerGas");
|
|
976
|
+
}
|
|
977
|
+
if (rpcRequest.maxFeePerGas !== undefined &&
|
|
978
|
+
rpcRequest.maxPriorityFeePerGas !== undefined &&
|
|
979
|
+
rpcRequest.maxPriorityFeePerGas > rpcRequest.maxFeePerGas) {
|
|
980
|
+
throw new errors_1.InvalidInputError(`maxPriorityFeePerGas (${rpcRequest.maxPriorityFeePerGas.toString()}) is bigger than maxFeePerGas (${rpcRequest.maxFeePerGas.toString()})`);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
// TODO: Find a better place for this
|
|
984
|
+
_validateEip155HardforkRequirement(tx) {
|
|
985
|
+
// 27 and 28 are only valid for non-EIP-155 legacy txs
|
|
986
|
+
if (tx.v === 27n || tx.v === 28n) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (!this._common.gteHardfork(EIP155_MIN_HARDFORK)) {
|
|
990
|
+
throw new errors_1.InvalidArgumentsError(`Trying to send an EIP-155 transaction, but they are not supported by the current hardfork.
|
|
991
|
+
|
|
992
|
+
You can use them by running Hardhat Network with 'hardfork' ${EIP155_MIN_HARDFORK} or later.`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
_validateEip3860MaxInitCodeSize(to, data) {
|
|
996
|
+
if (!this._common.gteHardfork(EIP3860_MIN_HARDFORK)) {
|
|
997
|
+
// this check is only relevant after shanghai
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (to !== undefined) {
|
|
1001
|
+
// this check is only relevant for deployments
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (this._node.allowUnlimitedContractSize) {
|
|
1005
|
+
// this check is not performed if allowUnlimitedContractSize is enabled
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
const maxInitCodeSize = this._common.param("vm", "maxInitCodeSize");
|
|
1009
|
+
if (data.length > maxInitCodeSize) {
|
|
1010
|
+
throw new errors_1.InvalidArgumentsError(`Trying to send a deployment transaction whose init code length is ${data.length}. The max length allowed by EIP-3860 is ${maxInitCodeSize}.
|
|
1011
|
+
|
|
1012
|
+
Enable the 'allowUnlimitedContractSize' option to allow init codes of any length.`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
_validateRawTransactionHardforkRequirements(rawTx) {
|
|
1016
|
+
if (rawTx[0] <= 0x7f && rawTx[0] !== 1 && rawTx[0] !== 2) {
|
|
1017
|
+
throw new errors_1.InvalidArgumentsError(`Invalid transaction type ${rawTx[0]}.
|
|
1018
|
+
|
|
1019
|
+
Your raw transaction is incorrectly formatted, or Hardhat Network doesn't support this transaction type yet.`);
|
|
1020
|
+
}
|
|
1021
|
+
if (rawTx[0] === 1 && !this._common.gteHardfork(ACCESS_LIST_MIN_HARDFORK)) {
|
|
1022
|
+
throw new errors_1.InvalidArgumentsError(`Trying to send an EIP-2930 transaction but they are not supported by the current hard fork.
|
|
1023
|
+
|
|
1024
|
+
You can use them by running Hardhat Network with 'hardfork' ${ACCESS_LIST_MIN_HARDFORK} or later.`);
|
|
1025
|
+
}
|
|
1026
|
+
if (rawTx[0] === 2 && !this._common.gteHardfork(EIP1559_MIN_HARDFORK)) {
|
|
1027
|
+
throw new errors_1.InvalidArgumentsError(`Trying to send an EIP-1559 transaction but they are not supported by the current hard fork.
|
|
1028
|
+
|
|
1029
|
+
You can use them by running Hardhat Network with 'hardfork' ${EIP1559_MIN_HARDFORK} or later.`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
exports.EthModule = EthModule;
|
|
1034
|
+
//# sourceMappingURL=eth.js.map
|