Skip to content

Commit f6f8f08

Browse files
committed
chore: match Hardhat console.sol helper fns
1 parent 5a802d7 commit f6f8f08

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/console.sol

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,38 @@
22
pragma solidity >=0.4.22 <0.9.0;
33

44
library console {
5-
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
5+
address constant CONSOLE_ADDRESS =
6+
0x000000000000000000636F6e736F6c652e6c6f67;
67

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
1011
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+
)
1222
}
1323
}
1424

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) {
2328
assembly {
24-
let payloadStart := add(payload, 32)
25-
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
29+
fnOut := fnIn
2630
}
2731
}
2832

33+
function _sendLogPayload(bytes memory payload) internal pure {
34+
_castToPure(_sendLogPayloadImplementation)(payload);
35+
}
36+
2937
function log() internal pure {
3038
_sendLogPayload(abi.encodeWithSignature("log()"));
3139
}

0 commit comments

Comments
 (0)