Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
openzeppelin-labs/upgradeability_using_eternal_storage/contracts/Proxy.sol
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (30 sloc)
980 Bytes
This file contains 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; | |
/** | |
* @title Proxy | |
* @dev Gives the possibility to delegate any call to a foreign implementation. | |
*/ | |
contract Proxy { | |
/** | |
* @dev Tells the address of the implementation where every call will be delegated. | |
* @return address of the implementation to which it will be delegated | |
*/ | |
function implementation() public view returns (address); | |
/** | |
* @dev Fallback function allowing to perform a delegatecall to the given implementation. | |
* This function will return whatever the implementation call returns | |
*/ | |
function () payable public { | |
address _impl = implementation(); | |
require(_impl != address(0)); | |
assembly { | |
let ptr := mload(0x40) | |
calldatacopy(ptr, 0, calldatasize) | |
let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) | |
let size := returndatasize | |
returndatacopy(ptr, 0, size) | |
switch result | |
case 0 { revert(ptr, size) } | |
default { return(ptr, size) } | |
} | |
} | |
} |