github.com/annchain/OG@v0.0.9/vm/vm_test/contracts/delegatecall.sol (about)

     1  pragma solidity ^0.4.0;
     2  
     3  contract Caller {
     4      uint public value;
     5      address public msgSender;
     6      address public txOrigin;
     7  
     8      function callSetValue(address _callee, uint _value) {
     9          _callee.call(bytes4(keccak256("setValue(uint256)")), _value); // Callee's storage is set as given , Caller's is not modified
    10      }
    11  
    12      function callcodeSetValue(address _callee, uint _value) {
    13          _callee.callcode(bytes4(keccak256("setValue(uint256)")), _value); // Caller's storage is set, Calee is not modified
    14      }
    15  
    16      function delegatecallSetValue(address _callee, uint _value) {
    17          _callee.delegatecall(bytes4(keccak256("setValue(uint256)")), _value); // Caller's storage is set, Callee is not modified
    18      }
    19  }
    20  
    21  contract Callee {
    22      uint public value;
    23      address public msgSender;
    24      address public txOrigin;
    25  
    26  
    27      function setValue(uint _value) {
    28          value = _value;
    29          msgSender = msg.sender;
    30          txOrigin = tx.origin;
    31          // msg.sender is Caller if invoked by Caller's callcodeSetValue. None of Callee's storage is updated
    32          // msg.sender is OnlyCaller if invoked by onlyCaller.justCall(). None of Callee's storage is updated
    33  
    34          // the value of "this" is Caller, when invoked by either Caller's callcodeSetValue or CallHelper.justCall()
    35      }
    36  }
    37  
    38  contract CallHelper {
    39      function justCall(Caller _caller, Callee _callee, uint _value) {
    40          _caller.delegatecallSetValue(_callee, _value);
    41      }
    42  }