|
2 | 2 | pragma solidity ^0.8.0; |
3 | 3 |
|
4 | 4 | contract TracingCaller { |
5 | | - event TraceEvent(uint256 value, string message); |
| 5 | + event TraceEvent(uint256 value, string message); |
6 | 6 | address payable public callee; |
7 | 7 |
|
8 | | - constructor(address payable _callee) payable { |
9 | | - require(_callee != address(0), "Callee address cannot be zero"); |
| 8 | + constructor(address payable _callee) payable { |
| 9 | + require(_callee != address(0), 'Callee address cannot be zero'); |
10 | 10 | callee = _callee; |
11 | 11 | } |
12 | 12 |
|
13 | 13 | function start(uint256 counter) external { |
14 | 14 | if (counter == 0) { |
15 | | - return; |
| 15 | + return; |
16 | 16 | } |
17 | 17 |
|
18 | 18 | uint256 paymentAmount = 0.01 ether; |
19 | 19 | callee.transfer(paymentAmount); |
20 | 20 |
|
21 | | - emit TraceEvent(counter, "before"); |
22 | | - TracingCallee(callee).consumeGas(counter); |
23 | | - emit TraceEvent(counter, "after"); |
| 21 | + emit TraceEvent(counter, 'before'); |
| 22 | + TracingCallee(callee).consumeGas(counter); |
| 23 | + emit TraceEvent(counter, 'after'); |
24 | 24 |
|
25 | | - try TracingCallee(callee).failingFunction{value: paymentAmount}() { |
26 | | - } catch { |
27 | | - } |
| 25 | + try |
| 26 | + TracingCallee(callee).failingFunction{value: paymentAmount}() |
| 27 | + {} catch {} |
| 28 | + |
| 29 | + this.start(counter - 1); |
| 30 | + } |
28 | 31 |
|
29 | | - this.start(counter - 1); |
| 32 | + function create() external returns (address) { |
| 33 | + TracingCallee newCallee = new TracingCallee(); |
| 34 | + return address(newCallee); |
| 35 | + } |
| 36 | + |
| 37 | + function create2() external returns (address) { |
| 38 | + bytes32 salt = bytes32(uint256(0x42)); |
| 39 | + TracingCallee newCallee = new TracingCallee{salt: salt}(); |
| 40 | + return address(newCallee); |
30 | 41 | } |
31 | 42 | } |
32 | 43 |
|
33 | 44 | contract TracingCallee { |
34 | 45 | event CalleeCalled(uint256 counter); |
35 | 46 |
|
36 | 47 | function consumeGas(uint256 counter) external { |
37 | | - // burn some gas |
| 48 | + // burn some gas |
38 | 49 | for (uint256 i = 0; i < 10; i++) { |
39 | | - uint256(keccak256(abi.encodePacked(i))); |
| 50 | + uint256(keccak256(abi.encodePacked(i))); |
40 | 51 | } |
41 | 52 |
|
42 | 53 | emit CalleeCalled(counter); |
43 | 54 | } |
44 | 55 |
|
45 | | - function failingFunction() external payable { |
46 | | - require(false, "This function always fails"); |
| 56 | + function failingFunction() external payable { |
| 57 | + require(false, 'This function always fails'); |
47 | 58 | } |
48 | 59 |
|
49 | | - // Enable contract to receive Ether |
| 60 | + // Enable contract to receive Ether |
50 | 61 | receive() external payable {} |
51 | 62 | } |
52 | | - |
|
0 commit comments