From c273f7ec1da532e6de77b6e4f398f99c6d879e95 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Tue, 28 Nov 2017 01:33:25 -0200 Subject: [PATCH] base structure of upgradable republic --- contracts/deploy/DelegatedCall.sol | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 contracts/deploy/DelegatedCall.sol diff --git a/contracts/deploy/DelegatedCall.sol b/contracts/deploy/DelegatedCall.sol new file mode 100644 index 0000000..cbed2b4 --- /dev/null +++ b/contracts/deploy/DelegatedCall.sol @@ -0,0 +1,33 @@ +pragma solidity ^0.4.17; + + +/** + * @title DelegatedCall + * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) + * @dev Abstract contract that delegates calls by `delegated` modifier to result of `_target()` + */ +contract DelegatedCall { + /** + * @dev delegates the call of this function + */ + modifier delegated { + require(_target().delegatecall(msg.data)); //require successfull delegate call to remote `_target()` + assembly { + let outSize := returndatasize + let outDataPtr := mload(0x40) //load memory + returndatacopy(outDataPtr, 0, outSize) //copy last return into pointer + return(outDataPtr, outSize) + } + assert(false); //should never reach here + _; //never will execute local logic + } + + /** + * @dev defines the address for delegation of calls + */ + function _target() + internal + constant + returns(address); + +}