Guest User

Untitled

a guest
Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. pragma solidity ^0.4.21;
  2.  
  3. import "./Ownable.sol";
  4.  
  5. contract UpgradeableContractProxy is Ownable {
  6.  
  7. address private _currentImplementation;
  8.  
  9. function UpgradeableContractProxy() public Ownable() {
  10. }
  11.  
  12. function updateImplementation(address _newImplementation) onlyOwner public {
  13. require(_newImplementation != address(0));
  14.  
  15. _currentImplementation = _newImplementation;
  16. }
  17.  
  18. function implementation() public view returns (address) {
  19. return _currentImplementation;
  20. }
  21.  
  22. function () payable public {
  23. address _impl = implementation();
  24. require(_impl != address(0));
  25.  
  26. assembly {
  27. // Copy the data sent to the memory address starting 0x40
  28. let ptr := mload(0x40)
  29. calldatacopy(ptr, 0, calldatasize)
  30.  
  31. // Proxy the call to the contract address with the provided gas and data
  32. let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0)
  33.  
  34. // Copy the data returned by the proxied call to memory
  35. let size := returndatasize
  36. returndatacopy(ptr, 0, size)
  37.  
  38. // Check what the result is, return and revert accordingly
  39. switch result
  40. case 0 { revert(ptr, size) }
  41. case 1 { return(ptr, size) }
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment