-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDelegateCall.sol
42 lines (31 loc) · 973 Bytes
/
DelegateCall.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
pragma solidity ^0.5.0;
contract Callee {
address public caller;
event Called(address indexed);
event WhoAmI(address indexed);
constructor() public {
}
function func() public returns (bool result){
caller = msg.sender;
emit Called(caller);
emit WhoAmI(address(this));
result = true;
}
}
contract Caller {
Callee public _callee;
constructor(address _ca) public {
_callee = Callee(_ca);
}
function funcDefaultCall() public returns (bool result){
result = _callee.func();
}
function funcStaticCall() public returns (bool){
(bool result,) = address(_callee).call(abi.encodePacked(bytes4(keccak256("func()"))));
return result;
}
function funcDelegateCall() public returns (bool ){
(bool result,) = address(_callee).delegatecall(abi.encodePacked(bytes4(keccak256("func()"))));
return result;
}
}