hardhat 2.20.0 → 2.21.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/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
- package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -6
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +28 -4
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/http.d.ts +2 -0
- package/internal/core/providers/http.d.ts.map +1 -1
- package/internal/core/providers/http.js +2 -1
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts +0 -2
- package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.js +0 -16
- package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +9 -1
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.d.ts +5 -5
- package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.js +10 -10
- package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +0 -7
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -14
- package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/TxPool.d.ts +3 -2
- package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
- package/internal/hardhat-network/provider/TxPool.js +16 -16
- package/internal/hardhat-network/provider/TxPool.js.map +1 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js +1 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
- package/internal/hardhat-network/provider/filter.d.ts +6 -5
- package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
- package/internal/hardhat-network/provider/filter.js +2 -2
- package/internal/hardhat-network/provider/filter.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +0 -7
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +4 -21
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +13 -19
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.js +61 -59
- package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js +0 -3
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
- package/internal/hardhat-network/provider/modules/base.js +4 -4
- package/internal/hardhat-network/provider/modules/base.js.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.js +9 -16
- package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.d.ts +6 -84
- package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +3 -530
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +2 -65
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node-types.js +0 -5
- package/internal/hardhat-network/provider/node-types.js.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +2 -6
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +79 -148
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/output.d.ts +0 -14
- package/internal/hardhat-network/provider/output.d.ts.map +1 -1
- package/internal/hardhat-network/provider/output.js +0 -264
- package/internal/hardhat-network/provider/output.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +26 -25
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +342 -186
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +10 -8
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +9 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +10 -8
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +9 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +10 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +7 -6
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +6 -5
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +5 -4
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +8 -7
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +2 -2
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +8 -7
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +2 -2
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -4
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +14 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.js +191 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -0
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +0 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +1 -5
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.js +1 -3
- package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +2 -2
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +1 -15
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +10 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.js +38 -18
- package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.js +2 -2
- package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +3 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -6
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
- package/internal/hardhat-network/provider/utils/random.d.ts +1 -0
- package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/random.js +7 -1
- package/internal/hardhat-network/provider/utils/random.js.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.js +5 -5
- package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.d.ts +22 -0
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/exit.js +93 -0
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts +29 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.js +46 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.js.map +1 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.d.ts +36 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.js +73 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.js.map +1 -0
- package/internal/hardhat-network/provider/vm/types.d.ts +27 -0
- package/internal/hardhat-network/provider/vm/types.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/types.js +3 -0
- package/internal/hardhat-network/provider/vm/types.js.map +1 -0
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +6 -0
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +33 -16
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +1 -2
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.js +6 -7
- package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
- package/internal/hardhat-network/stack-traces/debug.js +6 -6
- package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +13 -7
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.d.ts +8 -3
- package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.js +22 -1
- package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/model.d.ts +8 -0
- package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/model.js +52 -0
- package/internal/hardhat-network/stack-traces/model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/opcodes.d.ts +1 -0
- package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/opcodes.js +5 -1
- package/internal/hardhat-network/stack-traces/opcodes.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -5
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +28 -34
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +7 -0
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +69 -2
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +7 -12
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.js +46 -65
- package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
- package/internal/util/date.d.ts +1 -0
- package/internal/util/date.d.ts.map +1 -1
- package/internal/util/date.js +5 -1
- package/internal/util/date.js.map +1 -1
- package/internal/util/hardforks.d.ts +2 -0
- package/internal/util/hardforks.d.ts.map +1 -1
- package/internal/util/hardforks.js +27 -1
- package/internal/util/hardforks.js.map +1 -1
- package/package.json +18 -16
- package/src/internal/core/providers/construction.ts +7 -9
- package/src/internal/core/providers/http.ts +3 -1
- package/src/internal/core/runtime-environment.ts +2 -1
- package/src/internal/hardhat-network/jsonrpc/client.ts +1 -28
- package/src/internal/hardhat-network/jsonrpc/handler.ts +9 -1
- package/src/internal/hardhat-network/provider/modules/logger.ts +6 -801
- package/src/internal/hardhat-network/provider/node-types.ts +2 -89
- package/src/internal/hardhat-network/provider/output.ts +0 -352
- package/src/internal/hardhat-network/provider/provider.ts +482 -263
- package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +228 -0
- package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +0 -4
- package/src/internal/hardhat-network/provider/utils/makeCommon.ts +1 -12
- package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +63 -24
- package/src/internal/hardhat-network/provider/utils/random.ts +8 -1
- package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +5 -5
- package/src/internal/hardhat-network/provider/vm/exit.ts +101 -0
- package/src/internal/hardhat-network/provider/vm/minimal-vm.ts +101 -0
- package/src/internal/hardhat-network/provider/vm/types.ts +31 -0
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +40 -21
- package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +10 -12
- package/src/internal/hardhat-network/stack-traces/debug.ts +6 -6
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +15 -8
- package/src/internal/hardhat-network/stack-traces/message-trace.ts +40 -4
- package/src/internal/hardhat-network/stack-traces/model.ts +61 -0
- package/src/internal/hardhat-network/stack-traces/opcodes.ts +4 -0
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -5
- package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +113 -4
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +67 -95
- package/src/internal/util/date.ts +4 -0
- package/src/internal/util/hardforks.ts +52 -0
- package/src/internal/hardhat-network/provider/BlockchainBase.ts +0 -185
- package/src/internal/hardhat-network/provider/BlockchainData.ts +0 -261
- package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +0 -140
- package/src/internal/hardhat-network/provider/PoolState.ts +0 -48
- package/src/internal/hardhat-network/provider/TransactionQueue.ts +0 -158
- package/src/internal/hardhat-network/provider/TxPool.ts +0 -715
- package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +0 -21
- package/src/internal/hardhat-network/provider/filter.ts +0 -142
- package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +0 -433
- package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +0 -480
- package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +0 -35
- package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +0 -44
- package/src/internal/hardhat-network/provider/modules/base.ts +0 -156
- package/src/internal/hardhat-network/provider/modules/debug.ts +0 -104
- package/src/internal/hardhat-network/provider/modules/eth.ts +0 -1781
- package/src/internal/hardhat-network/provider/modules/evm.ts +0 -249
- package/src/internal/hardhat-network/provider/modules/hardhat.ts +0 -481
- package/src/internal/hardhat-network/provider/modules/net.ts +0 -60
- package/src/internal/hardhat-network/provider/modules/personal.ts +0 -40
- package/src/internal/hardhat-network/provider/modules/web3.ts +0 -49
- package/src/internal/hardhat-network/provider/node.ts +0 -2993
- package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +0 -226
- package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +0 -224
- package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +0 -216
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +0 -143
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +0 -144
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +0 -171
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.ts +0 -169
- package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +0 -25
- package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +0 -60
- package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +0 -29
- package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +0 -61
- package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +0 -45
- package/src/internal/hardhat-network/provider/utils/txMapToArray.ts +0 -7
- package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +0 -630
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
import { Block } from "@nomicfoundation/ethereumjs-block";
|
|
2
|
-
import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
|
|
3
|
-
import {
|
|
4
|
-
bytesToHex as bufferToHex,
|
|
5
|
-
equalsBytes,
|
|
6
|
-
} from "@nomicfoundation/ethereumjs-util";
|
|
7
1
|
import ansiEscapes from "ansi-escapes";
|
|
8
|
-
import chalk, { Chalk } from "chalk";
|
|
9
|
-
import util from "util";
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
import { TransactionExecutionError } from "../../../core/providers/errors";
|
|
13
|
-
import { weiToHumanReadableString } from "../../../util/wei-values";
|
|
14
|
-
import {
|
|
15
|
-
isCreateTrace,
|
|
16
|
-
isPrecompileTrace,
|
|
17
|
-
MessageTrace,
|
|
18
|
-
} from "../../stack-traces/message-trace";
|
|
19
|
-
import { ContractFunctionType } from "../../stack-traces/model";
|
|
20
|
-
import { SolidityError } from "../../stack-traces/solidity-errors";
|
|
21
|
-
import {
|
|
22
|
-
FALLBACK_FUNCTION_NAME,
|
|
23
|
-
RECEIVE_FUNCTION_NAME,
|
|
24
|
-
UNRECOGNIZED_CONTRACT_NAME,
|
|
25
|
-
UNRECOGNIZED_FUNCTION_NAME,
|
|
26
|
-
} from "../../stack-traces/solidity-stack-trace";
|
|
27
|
-
import { CallParams, GatherTracesResult, MineBlockResult } from "../node-types";
|
|
28
|
-
|
|
29
|
-
interface PrintOptions {
|
|
30
|
-
color?: Chalk;
|
|
31
|
-
replaceLastLine?: boolean;
|
|
32
|
-
collapsePrintedMethod?: boolean;
|
|
33
|
-
collapseIntervalMinedBlock?: boolean;
|
|
34
|
-
collapseHardhatMinedBlock?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function printLine(line: string) {
|
|
3
|
+
export function printLine(line: string) {
|
|
38
4
|
console.log(line);
|
|
39
5
|
}
|
|
40
6
|
|
|
41
|
-
function replaceLastLine(newLine: string) {
|
|
7
|
+
export function replaceLastLine(newLine: string) {
|
|
42
8
|
if (process.stdout.isTTY === true) {
|
|
43
9
|
process.stdout.write(
|
|
44
10
|
// eslint-disable-next-line prefer-template
|
|
@@ -54,769 +20,8 @@ function replaceLastLine(newLine: string) {
|
|
|
54
20
|
}
|
|
55
21
|
}
|
|
56
22
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* - Methods that start with `log` add those messages to a list of things to log
|
|
62
|
-
* - Methods that start with `print` print to stdout immediately
|
|
63
|
-
*/
|
|
64
|
-
export class ModulesLogger {
|
|
65
|
-
private _logs: Array<string | [string, string]> = [];
|
|
66
|
-
private _titleLength = 0;
|
|
67
|
-
private _currentIndent = 0;
|
|
68
|
-
private _emptyIntervalMinedBlocksRangeStart: bigint | undefined = undefined;
|
|
69
|
-
private _emptyHardhatMinedBlocksRangeStart: bigint | undefined = undefined;
|
|
70
|
-
private _methodBeingCollapsed?: string;
|
|
71
|
-
private _methodCollapsedCount: number = 0;
|
|
72
|
-
|
|
73
|
-
constructor(
|
|
74
|
-
private _enabled: boolean,
|
|
75
|
-
private _printLine = printLine,
|
|
76
|
-
private _replaceLastLine = replaceLastLine
|
|
77
|
-
) {}
|
|
78
|
-
|
|
79
|
-
public isEnabled() {
|
|
80
|
-
return this._enabled;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public setEnabled(enabled: boolean) {
|
|
84
|
-
this._enabled = enabled;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public isLoggedError(err: Error) {
|
|
88
|
-
return (
|
|
89
|
-
err instanceof SolidityError || err instanceof TransactionExecutionError
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public logBlockFromAutomine(
|
|
94
|
-
result: MineBlockResult,
|
|
95
|
-
codes: Uint8Array[],
|
|
96
|
-
txHashToHighlight: Uint8Array
|
|
97
|
-
) {
|
|
98
|
-
const { block, blockResult, traces } = result;
|
|
99
|
-
const { results } = blockResult;
|
|
100
|
-
|
|
101
|
-
assertHardhatInvariant(
|
|
102
|
-
results.length === codes.length,
|
|
103
|
-
"The array of codes should have the same length as the array of results"
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
this._indent(() => {
|
|
107
|
-
this._logBlockNumber(block);
|
|
108
|
-
|
|
109
|
-
this._indent(() => {
|
|
110
|
-
this._logBaseFeePerGas(block);
|
|
111
|
-
|
|
112
|
-
for (let i = 0; i < block.transactions.length; i++) {
|
|
113
|
-
const tx = block.transactions[i];
|
|
114
|
-
|
|
115
|
-
const txGasUsed = results[i].totalGasSpent;
|
|
116
|
-
const txTrace = traces[i];
|
|
117
|
-
const code = codes[i];
|
|
118
|
-
|
|
119
|
-
const highlightTxHash = equalsBytes(tx.hash(), txHashToHighlight);
|
|
120
|
-
|
|
121
|
-
this._logTxInsideBlock(tx, txTrace, code, txGasUsed, {
|
|
122
|
-
highlightTxHash,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
this._logEmptyLineBetweenTransactions(i, block.transactions.length);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public logMinedBlock(result: MineBlockResult, codes: Buffer[]) {
|
|
132
|
-
const { block, blockResult, traces } = result;
|
|
133
|
-
const { results } = blockResult;
|
|
134
|
-
|
|
135
|
-
assertHardhatInvariant(
|
|
136
|
-
results.length === codes.length,
|
|
137
|
-
"The array of codes should have the same length as the array of results"
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
const blockNumber = result.block.header.number;
|
|
141
|
-
const isEmpty = result.block.transactions.length === 0;
|
|
142
|
-
|
|
143
|
-
this._indent(() => {
|
|
144
|
-
this.logMinedBlockNumber(
|
|
145
|
-
blockNumber,
|
|
146
|
-
isEmpty,
|
|
147
|
-
block.header.baseFeePerGas
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
if (isEmpty) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this._indent(() => {
|
|
155
|
-
this._logBlockHash(block);
|
|
156
|
-
|
|
157
|
-
this._indent(() => {
|
|
158
|
-
this._logBaseFeePerGas(block);
|
|
159
|
-
|
|
160
|
-
for (let i = 0; i < block.transactions.length; i++) {
|
|
161
|
-
const tx = block.transactions[i];
|
|
162
|
-
const txGasUsed = results[i].totalGasSpent;
|
|
163
|
-
const txTrace = traces[i];
|
|
164
|
-
const code = codes[i];
|
|
165
|
-
|
|
166
|
-
this._logTxInsideBlock(tx, txTrace, code, txGasUsed, {
|
|
167
|
-
highlightTxHash: false,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
this._logEmptyLineBetweenTransactions(i, block.transactions.length);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public logIntervalMinedBlock(result: MineBlockResult, codes: Buffer[]) {
|
|
178
|
-
const { block, blockResult, traces } = result;
|
|
179
|
-
const { results } = blockResult;
|
|
180
|
-
|
|
181
|
-
assertHardhatInvariant(
|
|
182
|
-
results.length === codes.length,
|
|
183
|
-
"The array of codes should have the same length as the array of results"
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
this._indent(() => {
|
|
187
|
-
this._logBlockHash(block);
|
|
188
|
-
|
|
189
|
-
this._indent(() => {
|
|
190
|
-
this._logBaseFeePerGas(block);
|
|
191
|
-
|
|
192
|
-
for (let i = 0; i < block.transactions.length; i++) {
|
|
193
|
-
const tx = block.transactions[i];
|
|
194
|
-
const txGasUsed = results[i].totalGasSpent;
|
|
195
|
-
const txTrace = traces[i];
|
|
196
|
-
const code = codes[i];
|
|
197
|
-
|
|
198
|
-
this._logTxInsideBlock(tx, txTrace, code, txGasUsed, {
|
|
199
|
-
highlightTxHash: false,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
this._logEmptyLineBetweenTransactions(i, block.transactions.length);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
public logSingleTransaction(
|
|
209
|
-
tx: TypedTransaction,
|
|
210
|
-
block: Block,
|
|
211
|
-
txGasUsed: bigint,
|
|
212
|
-
txTrace: GatherTracesResult,
|
|
213
|
-
code: Buffer
|
|
214
|
-
) {
|
|
215
|
-
this._indent(() => {
|
|
216
|
-
this._logContractAndFunctionName(txTrace.trace, code);
|
|
217
|
-
|
|
218
|
-
const txHash = bufferToHex(tx.hash());
|
|
219
|
-
|
|
220
|
-
this._logWithTitle("Transaction", txHash);
|
|
221
|
-
|
|
222
|
-
this._logTxFrom(Buffer.from(tx.getSenderAddress().toBytes()));
|
|
223
|
-
this._logTxTo(tx.to?.toBytes(), txTrace.trace);
|
|
224
|
-
this._logTxValue(tx.value);
|
|
225
|
-
this._logWithTitle("Gas used", `${txGasUsed} of ${tx.gasLimit}`);
|
|
226
|
-
|
|
227
|
-
this._logWithTitle(
|
|
228
|
-
`Block #${block.header.number}`,
|
|
229
|
-
bufferToHex(block.hash())
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
this._logConsoleLogMessages(txTrace.consoleLogMessages);
|
|
233
|
-
|
|
234
|
-
if (txTrace.error !== undefined) {
|
|
235
|
-
this._logError(txTrace.error);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public logCurrentlySentTransaction(
|
|
241
|
-
tx: TypedTransaction,
|
|
242
|
-
txGasUsed: bigint,
|
|
243
|
-
txTrace: GatherTracesResult,
|
|
244
|
-
code: Buffer,
|
|
245
|
-
block: Block
|
|
246
|
-
) {
|
|
247
|
-
this._indent(() => {
|
|
248
|
-
this._log("Currently sent transaction:");
|
|
249
|
-
this.logEmptyLine();
|
|
250
|
-
|
|
251
|
-
this._logContractAndFunctionName(txTrace.trace, code);
|
|
252
|
-
|
|
253
|
-
const txHash = bufferToHex(tx.hash());
|
|
254
|
-
|
|
255
|
-
this._logWithTitle("Transaction", txHash);
|
|
256
|
-
|
|
257
|
-
this._logTxFrom(tx.getSenderAddress().toBytes());
|
|
258
|
-
this._logTxTo(tx.to?.toBytes(), txTrace.trace);
|
|
259
|
-
this._logTxValue(tx.value);
|
|
260
|
-
this._logWithTitle("Gas used", `${txGasUsed} of ${tx.gasLimit}`);
|
|
261
|
-
|
|
262
|
-
this._logWithTitle(
|
|
263
|
-
`Block #${block.header.number}`,
|
|
264
|
-
bufferToHex(block.hash())
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
this._logConsoleLogMessages(txTrace.consoleLogMessages);
|
|
268
|
-
|
|
269
|
-
if (txTrace.error !== undefined) {
|
|
270
|
-
this._logError(txTrace.error);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
public logEstimateGasTrace(
|
|
276
|
-
callParams: CallParams,
|
|
277
|
-
code: Buffer,
|
|
278
|
-
trace: MessageTrace | undefined,
|
|
279
|
-
consoleLogMessages: string[],
|
|
280
|
-
error: Error
|
|
281
|
-
) {
|
|
282
|
-
this._indent(() => {
|
|
283
|
-
this._logContractAndFunctionName(trace, code, {
|
|
284
|
-
printNonContractCalled: true,
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
this._logTxFrom(callParams.from);
|
|
288
|
-
this._logTxTo(callParams.to, trace);
|
|
289
|
-
this._logTxValue(callParams.value);
|
|
290
|
-
|
|
291
|
-
this._logConsoleLogMessages(consoleLogMessages);
|
|
292
|
-
|
|
293
|
-
this._logError(error);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
public logCallTrace(
|
|
298
|
-
callParams: CallParams,
|
|
299
|
-
code: Buffer,
|
|
300
|
-
trace: MessageTrace | undefined,
|
|
301
|
-
consoleLogMessages: string[],
|
|
302
|
-
error: Error | undefined
|
|
303
|
-
) {
|
|
304
|
-
this._indent(() => {
|
|
305
|
-
this._logContractAndFunctionName(trace, code, {
|
|
306
|
-
printNonContractCalled: true,
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
this._logTxFrom(callParams.from);
|
|
310
|
-
this._logTxTo(callParams.to, trace);
|
|
311
|
-
if (callParams.value > 0n) {
|
|
312
|
-
this._logTxValue(callParams.value);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
this._logConsoleLogMessages(consoleLogMessages);
|
|
316
|
-
|
|
317
|
-
if (error !== undefined) {
|
|
318
|
-
// TODO: If throwOnCallFailures is false, this will log the error, but the RPC method won't be red
|
|
319
|
-
this._logError(error);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public logMinedBlockNumber(
|
|
325
|
-
blockNumber: bigint,
|
|
326
|
-
isEmpty: boolean,
|
|
327
|
-
baseFeePerGas?: bigint
|
|
328
|
-
) {
|
|
329
|
-
if (isEmpty) {
|
|
330
|
-
this._log(
|
|
331
|
-
`Mined empty block #${blockNumber}${
|
|
332
|
-
baseFeePerGas !== undefined
|
|
333
|
-
? ` with base fee ${baseFeePerGas.toString()}`
|
|
334
|
-
: ""
|
|
335
|
-
}`
|
|
336
|
-
);
|
|
337
|
-
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
this._log(`Mined block #${blockNumber}`);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
public logMultipleTransactionsWarning() {
|
|
345
|
-
this._indent(() => {
|
|
346
|
-
this._log(
|
|
347
|
-
"There were other pending transactions mined in the same block:"
|
|
348
|
-
);
|
|
349
|
-
});
|
|
350
|
-
this.logEmptyLine();
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
public logMultipleBlocksWarning() {
|
|
354
|
-
this._indent(() => {
|
|
355
|
-
this._log(
|
|
356
|
-
"There were other pending transactions. More than one block had to be mined:"
|
|
357
|
-
);
|
|
358
|
-
});
|
|
359
|
-
this.logEmptyLine();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
public logEmptyLine() {
|
|
363
|
-
this._log("");
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private _logBaseFeePerGas(block: Block) {
|
|
367
|
-
if (block.header.baseFeePerGas !== undefined) {
|
|
368
|
-
this._log(`Base fee: ${block.header.baseFeePerGas.toString()}`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
public printErrorMessage(errorMessage: string) {
|
|
373
|
-
this._indent(() => {
|
|
374
|
-
this._print(errorMessage);
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
public printFailedMethod(method: string) {
|
|
379
|
-
this._print(method, { color: chalk.red });
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Print all accumulated logs
|
|
384
|
-
*/
|
|
385
|
-
public printLogs(): boolean {
|
|
386
|
-
const logs = this._getLogs();
|
|
387
|
-
if (logs.length === 0) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
for (const msg of logs) {
|
|
392
|
-
this._print(msg);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
this._clearLogs();
|
|
396
|
-
|
|
397
|
-
return true;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
public printIntervalMinedBlockNumber(
|
|
401
|
-
blockNumber: bigint,
|
|
402
|
-
isEmpty: boolean,
|
|
403
|
-
baseFeePerGas?: bigint
|
|
404
|
-
) {
|
|
405
|
-
if (this._emptyIntervalMinedBlocksRangeStart !== undefined) {
|
|
406
|
-
this._print(
|
|
407
|
-
`Mined empty block range #${this._emptyIntervalMinedBlocksRangeStart} to #${blockNumber}`,
|
|
408
|
-
{ collapseIntervalMinedBlock: true, replaceLastLine: true }
|
|
409
|
-
);
|
|
410
|
-
} else {
|
|
411
|
-
this._emptyIntervalMinedBlocksRangeStart = blockNumber;
|
|
412
|
-
|
|
413
|
-
if (isEmpty) {
|
|
414
|
-
this._print(
|
|
415
|
-
`Mined empty block #${blockNumber}${
|
|
416
|
-
baseFeePerGas !== undefined
|
|
417
|
-
? ` with base fee ${baseFeePerGas.toString()}`
|
|
418
|
-
: ""
|
|
419
|
-
}`,
|
|
420
|
-
{
|
|
421
|
-
collapseIntervalMinedBlock: true,
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
this._print(`Mined block #${blockNumber}`, {
|
|
429
|
-
collapseIntervalMinedBlock: true,
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
public logEmptyHardhatMinedBlock(
|
|
435
|
-
blockNumber: bigint,
|
|
436
|
-
baseFeePerGas?: bigint
|
|
437
|
-
) {
|
|
438
|
-
this._indent(() => {
|
|
439
|
-
if (this._emptyHardhatMinedBlocksRangeStart !== undefined) {
|
|
440
|
-
this._log(
|
|
441
|
-
`Mined empty block range #${this._emptyHardhatMinedBlocksRangeStart} to #${blockNumber}`,
|
|
442
|
-
{ collapseHardhatMinedBlock: true, replaceLastLine: true }
|
|
443
|
-
);
|
|
444
|
-
} else {
|
|
445
|
-
this._emptyHardhatMinedBlocksRangeStart = blockNumber;
|
|
446
|
-
|
|
447
|
-
this._log(
|
|
448
|
-
`Mined empty block #${blockNumber}${
|
|
449
|
-
baseFeePerGas !== undefined
|
|
450
|
-
? ` with base fee ${baseFeePerGas.toString()}`
|
|
451
|
-
: ""
|
|
452
|
-
}`,
|
|
453
|
-
{
|
|
454
|
-
collapseHardhatMinedBlock: true,
|
|
455
|
-
}
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
public printMetaMaskWarning() {
|
|
464
|
-
const message =
|
|
465
|
-
"If you are using MetaMask, you can learn how to fix this error here: https://hardhat.org/metamask-issue";
|
|
466
|
-
|
|
467
|
-
this._indent(() => {
|
|
468
|
-
this._print(message, { color: chalk.yellow });
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
public printMethod(method: string) {
|
|
473
|
-
if (this._shouldCollapseMethod(method)) {
|
|
474
|
-
this._methodCollapsedCount += 1;
|
|
475
|
-
|
|
476
|
-
this._print(chalk.green(`${method} (${this._methodCollapsedCount})`), {
|
|
477
|
-
collapsePrintedMethod: true,
|
|
478
|
-
replaceLastLine: true,
|
|
479
|
-
});
|
|
480
|
-
} else {
|
|
481
|
-
this._startCollapsingMethod(method);
|
|
482
|
-
this._print(method, { color: chalk.green, collapsePrintedMethod: true });
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
public printMethodNotSupported(method: string) {
|
|
487
|
-
this._print(`${method} - Method not supported`, { color: chalk.red });
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
public printEmptyLine() {
|
|
491
|
-
this._print("");
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
public printUnknownError(err: Error) {
|
|
495
|
-
this._indent(() => {
|
|
496
|
-
this._printError(err);
|
|
497
|
-
this.printEmptyLine();
|
|
498
|
-
|
|
499
|
-
this._print(
|
|
500
|
-
"If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bug"
|
|
501
|
-
);
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
private _format(msg: string, { color }: PrintOptions = {}): string {
|
|
506
|
-
if (msg === "") {
|
|
507
|
-
// don't indent empty lines
|
|
508
|
-
return msg;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (this._currentIndent > 0) {
|
|
512
|
-
msg = msg
|
|
513
|
-
.split("\n")
|
|
514
|
-
.map((line) => " ".repeat(this._currentIndent) + line)
|
|
515
|
-
.join("\n");
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (color !== undefined) {
|
|
519
|
-
return color(msg);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
return msg;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
private _indent<T>(cb: () => T, enabled = true) {
|
|
526
|
-
if (enabled) {
|
|
527
|
-
this._currentIndent += 2;
|
|
528
|
-
}
|
|
529
|
-
try {
|
|
530
|
-
return cb();
|
|
531
|
-
} finally {
|
|
532
|
-
if (enabled) {
|
|
533
|
-
this._currentIndent -= 2;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
private _indentSingleLine(message: string): string {
|
|
539
|
-
return " ".repeat(this._currentIndent) + message;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
private _log(msg: string, printOptions: PrintOptions = {}) {
|
|
543
|
-
if (printOptions.collapsePrintedMethod !== true) {
|
|
544
|
-
this._stopCollapsingMethod();
|
|
545
|
-
}
|
|
546
|
-
if (printOptions.collapseIntervalMinedBlock !== true) {
|
|
547
|
-
this._emptyIntervalMinedBlocksRangeStart = undefined;
|
|
548
|
-
}
|
|
549
|
-
if (printOptions.collapseHardhatMinedBlock !== true) {
|
|
550
|
-
this._emptyHardhatMinedBlocksRangeStart = undefined;
|
|
551
|
-
}
|
|
552
|
-
const formattedMessage = this._format(msg, printOptions);
|
|
553
|
-
|
|
554
|
-
if (printOptions.replaceLastLine === true) {
|
|
555
|
-
this._logs[this._logs.length - 1] = formattedMessage;
|
|
556
|
-
} else {
|
|
557
|
-
this._logs.push(formattedMessage);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
private _logError(err: Error) {
|
|
562
|
-
if (this.isLoggedError(err)) {
|
|
563
|
-
this.logEmptyLine();
|
|
564
|
-
this._log(util.inspect(err));
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
private _logTxInsideBlock(
|
|
569
|
-
tx: TypedTransaction,
|
|
570
|
-
txTrace: GatherTracesResult,
|
|
571
|
-
code: Uint8Array,
|
|
572
|
-
txGasUsed: bigint,
|
|
573
|
-
{
|
|
574
|
-
highlightTxHash,
|
|
575
|
-
}: {
|
|
576
|
-
highlightTxHash: boolean;
|
|
577
|
-
}
|
|
578
|
-
) {
|
|
579
|
-
// indentAfterTransactionHash: true,
|
|
580
|
-
// printTxBlockNumber: false,
|
|
581
|
-
// startWithTxHash: true,
|
|
582
|
-
let txHash = bufferToHex(tx.hash());
|
|
583
|
-
|
|
584
|
-
if (highlightTxHash) {
|
|
585
|
-
txHash = chalk.bold(txHash);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
this._logWithTitle("Transaction", txHash);
|
|
589
|
-
|
|
590
|
-
this._indent(() => {
|
|
591
|
-
this._logContractAndFunctionName(txTrace.trace, code);
|
|
592
|
-
this._logTxFrom(tx.getSenderAddress().toBytes());
|
|
593
|
-
this._logTxTo(tx.to?.toBytes(), txTrace.trace);
|
|
594
|
-
this._logTxValue(tx.value);
|
|
595
|
-
this._logWithTitle("Gas used", `${txGasUsed} of ${tx.gasLimit}`);
|
|
596
|
-
|
|
597
|
-
this._logConsoleLogMessages(txTrace.consoleLogMessages);
|
|
598
|
-
|
|
599
|
-
if (txTrace.error !== undefined) {
|
|
600
|
-
this._logError(txTrace.error);
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* This should be the only function that calls _printLine and
|
|
607
|
-
* _replaceLastLine (except for the special console.sol case),
|
|
608
|
-
* because it's the only function that checks if the logger
|
|
609
|
-
* is enabled.
|
|
610
|
-
*/
|
|
611
|
-
private _print(msg: string, printOptions: PrintOptions = {}) {
|
|
612
|
-
if (!this._enabled) {
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
if (printOptions.collapsePrintedMethod !== true) {
|
|
617
|
-
this._stopCollapsingMethod();
|
|
618
|
-
}
|
|
619
|
-
if (printOptions.collapseIntervalMinedBlock !== true) {
|
|
620
|
-
this._emptyIntervalMinedBlocksRangeStart = undefined;
|
|
621
|
-
}
|
|
622
|
-
if (printOptions.collapseHardhatMinedBlock !== true) {
|
|
623
|
-
this._emptyHardhatMinedBlocksRangeStart = undefined;
|
|
624
|
-
}
|
|
625
|
-
const formattedMessage = this._format(msg, printOptions);
|
|
626
|
-
|
|
627
|
-
if (printOptions.replaceLastLine === true) {
|
|
628
|
-
this._replaceLastLine(formattedMessage);
|
|
629
|
-
} else {
|
|
630
|
-
this._printLine(formattedMessage);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
private _printError(err: Error) {
|
|
635
|
-
if (this.isLoggedError(err)) {
|
|
636
|
-
this.printEmptyLine();
|
|
637
|
-
this._print(util.inspect(err));
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
private _logContractAndFunctionName(
|
|
642
|
-
trace: MessageTrace | undefined,
|
|
643
|
-
code: Uint8Array,
|
|
644
|
-
{
|
|
645
|
-
printNonContractCalled = false,
|
|
646
|
-
}: { printNonContractCalled?: boolean } = {}
|
|
647
|
-
) {
|
|
648
|
-
if (trace === undefined) {
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (isPrecompileTrace(trace)) {
|
|
653
|
-
this._logWithTitle(
|
|
654
|
-
"Precompile call",
|
|
655
|
-
`<PrecompileContract ${trace.precompile}>`
|
|
656
|
-
);
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
if (isCreateTrace(trace)) {
|
|
661
|
-
if (trace.bytecode === undefined) {
|
|
662
|
-
this._logWithTitle("Contract deployment", UNRECOGNIZED_CONTRACT_NAME);
|
|
663
|
-
} else {
|
|
664
|
-
this._logWithTitle("Contract deployment", trace.bytecode.contract.name);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
if (trace.deployedContract !== undefined && trace.error === undefined) {
|
|
668
|
-
this._logWithTitle(
|
|
669
|
-
"Contract address",
|
|
670
|
-
bufferToHex(trace.deployedContract)
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
if (code.length === 0) {
|
|
678
|
-
if (printNonContractCalled) {
|
|
679
|
-
this._log(`WARNING: Calling an account which is not a contract`);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
if (trace.bytecode === undefined) {
|
|
686
|
-
this._logWithTitle("Contract call", UNRECOGNIZED_CONTRACT_NAME);
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
const func = trace.bytecode.contract.getFunctionFromSelector(
|
|
691
|
-
trace.calldata.slice(0, 4)
|
|
692
|
-
);
|
|
693
|
-
|
|
694
|
-
const functionName: string =
|
|
695
|
-
func === undefined
|
|
696
|
-
? UNRECOGNIZED_FUNCTION_NAME
|
|
697
|
-
: func.type === ContractFunctionType.FALLBACK
|
|
698
|
-
? FALLBACK_FUNCTION_NAME
|
|
699
|
-
: func.type === ContractFunctionType.RECEIVE
|
|
700
|
-
? RECEIVE_FUNCTION_NAME
|
|
701
|
-
: func.name;
|
|
702
|
-
|
|
703
|
-
this._logWithTitle(
|
|
704
|
-
"Contract call",
|
|
705
|
-
`${trace.bytecode.contract.name}#${functionName}`
|
|
706
|
-
);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
private _shouldCollapseMethod(method: string) {
|
|
710
|
-
return (
|
|
711
|
-
method === this._methodBeingCollapsed &&
|
|
712
|
-
!this._hasLogs() &&
|
|
713
|
-
this._methodCollapsedCount > 0
|
|
714
|
-
);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
private _startCollapsingMethod(method: string) {
|
|
718
|
-
this._methodBeingCollapsed = method;
|
|
719
|
-
this._methodCollapsedCount = 1;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
private _stopCollapsingMethod() {
|
|
723
|
-
this._methodBeingCollapsed = undefined;
|
|
724
|
-
this._methodCollapsedCount = 0;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
private _logTxTo(to: Uint8Array | undefined, trace?: MessageTrace) {
|
|
728
|
-
if (trace !== undefined && isCreateTrace(trace)) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
if (to === undefined) {
|
|
732
|
-
// only for the type-checker, since `to` is undefined only when
|
|
733
|
-
// the message is a create trace
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
const toString = bufferToHex(to);
|
|
738
|
-
|
|
739
|
-
this._logWithTitle("To", toString);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
private _logTxValue(value: bigint) {
|
|
743
|
-
this._logWithTitle("Value", weiToHumanReadableString(value));
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
private _logTxFrom(from: Uint8Array) {
|
|
747
|
-
this._logWithTitle("From", bufferToHex(from));
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
private _logBlockNumber(block: Block) {
|
|
751
|
-
this._log(`Block #${block.header.number}: ${bufferToHex(block.hash())}`);
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
private _logEmptyLineBetweenTransactions(
|
|
755
|
-
currentIndex: number,
|
|
756
|
-
totalTransactions: number
|
|
757
|
-
) {
|
|
758
|
-
if (currentIndex + 1 < totalTransactions && totalTransactions > 1) {
|
|
759
|
-
this.logEmptyLine();
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
private _logBlockHash(block: Block) {
|
|
764
|
-
this._log(`Block: ${bufferToHex(block.hash())}`);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
private _logConsoleLogMessages(messages: string[]) {
|
|
768
|
-
// This is a especial case, as we always want to print the console.log
|
|
769
|
-
// messages. The difference is how.
|
|
770
|
-
// If we have a logger, we should use that, so that logs are printed in
|
|
771
|
-
// order. If we don't, we just print the messages here.
|
|
772
|
-
if (!this._enabled) {
|
|
773
|
-
for (const msg of messages) {
|
|
774
|
-
this._printLine(msg);
|
|
775
|
-
}
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
if (messages.length === 0) {
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
this.logEmptyLine();
|
|
784
|
-
this._log("console.log:");
|
|
785
|
-
|
|
786
|
-
for (const msg of messages) {
|
|
787
|
-
this._log(` ${msg}`);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
private _logWithTitle(title: string, message: string) {
|
|
792
|
-
title = this._indentSingleLine(title);
|
|
793
|
-
|
|
794
|
-
// We always use the max title length we've seen. Otherwise the value move
|
|
795
|
-
// a lot with each tx/call.
|
|
796
|
-
if (title.length > this._titleLength) {
|
|
797
|
-
this._titleLength = title.length;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
this._logs.push([title, message]);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
private _clearLogs() {
|
|
804
|
-
this._logs = [];
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
private _hasLogs(): boolean {
|
|
808
|
-
return this._logs.length > 0;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
private _getLogs(): string[] {
|
|
812
|
-
return this._logs.map((l) => {
|
|
813
|
-
if (typeof l === "string") {
|
|
814
|
-
return l;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
const title = `${l[0]}:`;
|
|
818
|
-
|
|
819
|
-
return `${title.padEnd(this._titleLength + 1)} ${l[1]}`;
|
|
820
|
-
});
|
|
821
|
-
}
|
|
23
|
+
export interface LoggerConfig {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
printLineFn?: (line: string) => void;
|
|
26
|
+
replaceLastLineFn?: (line: string) => void;
|
|
822
27
|
}
|