2019-02-14 02:18:08 -02:00
|
|
|
pragma solidity >=0.5.0 <0.6.0;
|
2017-11-28 01:33:25 -02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @title DelegatedCall
|
|
|
|
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
2019-02-14 02:18:08 -02:00
|
|
|
* @dev Encapsulates delegatecall related logic.
|
2017-11-28 01:33:25 -02:00
|
|
|
*/
|
|
|
|
contract DelegatedCall {
|
2018-05-13 02:47:51 -03:00
|
|
|
|
2019-02-14 02:18:08 -02:00
|
|
|
constructor(address _init, bytes memory _initMsg) internal {
|
|
|
|
if(_init == address(0)) return;
|
|
|
|
bool success;
|
|
|
|
(success, ) = _init.delegatecall(_initMsg);
|
|
|
|
require(success, "Delegated Construct fail");
|
2018-05-13 02:47:51 -03:00
|
|
|
}
|
2017-11-28 01:33:25 -02:00
|
|
|
/**
|
|
|
|
* @dev delegates the call of this function
|
|
|
|
*/
|
2019-02-14 02:18:08 -02:00
|
|
|
modifier delegateAndReturn(address _target) {
|
|
|
|
if(_target == address(0)) {
|
|
|
|
_; //normal execution
|
|
|
|
} else {
|
|
|
|
//delegated execution
|
|
|
|
bytes memory returnData;
|
|
|
|
bool success;
|
|
|
|
(success, returnData) = _target.delegatecall(msg.data);
|
|
|
|
require(success, "Delegated Call failed");
|
|
|
|
|
|
|
|
//exit-return delegatecall returnData
|
|
|
|
assembly {
|
|
|
|
return(add(returnData, 0x20), returnData)
|
|
|
|
}
|
2017-11-28 01:33:25 -02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|