topic-democracy/contracts/deploy/DelegatedCall.sol
Ricardo Guilherme Schmidt 2a0495f9f7
update instance factory
2019-02-14 02:18:08 -02:00

38 lines
1.0 KiB
Solidity

pragma solidity >=0.5.0 <0.6.0;
/**
* @title DelegatedCall
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @dev Encapsulates delegatecall related logic.
*/
contract DelegatedCall {
constructor(address _init, bytes memory _initMsg) internal {
if(_init == address(0)) return;
bool success;
(success, ) = _init.delegatecall(_initMsg);
require(success, "Delegated Construct fail");
}
/**
* @dev delegates the call of this function
*/
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)
}
}
}
}