|
2 | 2 | pragma solidity >=0.4.22 <0.9.0; |
3 | 3 |
|
4 | 4 | library console { |
5 | | - address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); |
| 5 | + address constant CONSOLE_ADDRESS = |
| 6 | + 0x000000000000000000636F6e736F6c652e6c6f67; |
6 | 7 |
|
7 | | - function _castLogPayloadViewToPure( |
8 | | - function(bytes memory) internal view fnIn |
9 | | - ) internal pure returns (function(bytes memory) internal pure fnOut) { |
| 8 | + function _sendLogPayloadImplementation(bytes memory payload) internal view { |
| 9 | + address consoleAddress = CONSOLE_ADDRESS; |
| 10 | + /// @solidity memory-safe-assembly |
10 | 11 | assembly { |
11 | | - fnOut := fnIn |
| 12 | + pop( |
| 13 | + staticcall( |
| 14 | + gas(), |
| 15 | + consoleAddress, |
| 16 | + add(payload, 32), |
| 17 | + mload(payload), |
| 18 | + 0, |
| 19 | + 0 |
| 20 | + ) |
| 21 | + ) |
12 | 22 | } |
13 | 23 | } |
14 | 24 |
|
15 | | - function _sendLogPayload(bytes memory payload) internal pure { |
16 | | - _castLogPayloadViewToPure(_sendLogPayloadView)(payload); |
17 | | - } |
18 | | - |
19 | | - function _sendLogPayloadView(bytes memory payload) private view { |
20 | | - uint256 payloadLength = payload.length; |
21 | | - address consoleAddress = CONSOLE_ADDRESS; |
22 | | - /// @solidity memory-safe-assembly |
| 25 | + function _castToPure( |
| 26 | + function(bytes memory) internal view fnIn |
| 27 | + ) internal pure returns (function(bytes memory) pure fnOut) { |
23 | 28 | assembly { |
24 | | - let payloadStart := add(payload, 32) |
25 | | - let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) |
| 29 | + fnOut := fnIn |
26 | 30 | } |
27 | 31 | } |
28 | 32 |
|
| 33 | + function _sendLogPayload(bytes memory payload) internal pure { |
| 34 | + _castToPure(_sendLogPayloadImplementation)(payload); |
| 35 | + } |
| 36 | + |
29 | 37 | function log() internal pure { |
30 | 38 | _sendLogPayload(abi.encodeWithSignature("log()")); |
31 | 39 | } |
|
0 commit comments