Created
April 4, 2018 14:52
-
-
Save ayinot/4f2aa3c528918ca3a57dbd3ec5f9cd26 to your computer and use it in GitHub Desktop.
Related to Contract Upgradation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
import "./Ownable.sol"; | |
contract Proxy is Ownable { | |
event Upgraded(address indexed implementation); | |
address internal _implementation; | |
function implementation() public view returns (address) { | |
return _implementation; | |
} | |
function upgradeTo(address impl) public onlyOwner { | |
require(_implementation != impl); | |
_implementation = impl; | |
Upgraded(impl); | |
} | |
function () payable public { | |
address _impl = implementation(); | |
require(_impl != address(0)); | |
bytes memory data = msg.data; | |
assembly { | |
let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0) | |
let size := returndatasize | |
let ptr := mload(0x40) | |
returndatacopy(ptr, 0, size) | |
switch result | |
case 0 { revert(ptr, size) } | |
default { return(ptr, size) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment