forked from chriseth/solidity-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.sol
75 lines (61 loc) · 1.65 KB
/
console.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Adapted from nomiclabs' console.log
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import "./string.sol" as String;
export { log };
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = 0x000000000000000000636F6e736F6c652e6c6f67;
(bool success,) = consoleAddress.staticcall{gas: gasleft()}(payload);
}
function _createSignature<A>() pure returns (string memory)
{
return abi.encodePacked(
"log(",
type(A).name,
")"
);
}
function _createSignature<A, B>() pure returns (string memory)
{
return abi.encodePacked(
"log(",
type(A).name,
type(B).name,
")"
);
}
function _createSignature<A, B, C>() pure returns (string memory)
{
return abi.encodePacked(
"log(",
type(A).name,
type(B).name,
type(C).name,
")"
);
}
function _createSignature<A, B, C, D>() pure returns (string memory)
{
return abi.encodePacked(
"log(",
type(A).name,
type(B).name,
type(C).name,
type(D).name,
")"
);
}
function log<A>(A a) view {
// need 'type(A).name'
_sendLogPayload(abi.encodeWithSignature(_createSignature::<A>(), a));
}
function log<A, B>(A a, B b) view {
_sendLogPayload(abi.encodeWithSignature(_createSignature::<A, B>(), a, b));
}
function log<A, B, C>(A a, B b, C c) view {
_sendLogPayload(abi.encodeWithSignature(_createSignature::<A, B, C>(), a, b, c));
}
function log<A, B, C, D>(A a, B b, C c, D d) view {
_sendLogPayload(abi.encodeWithSignature(_createSignature::<A, B, C, D>(), a, b, c, d));
}