github.com/tri-stone/burrow@v0.25.0/tests/jobs_fixtures/app51-user-account-forward-proxy-pattern/DefaultUserAccount.sol (about) 1 pragma solidity >=0.0.0; 2 /** 3 * @title DefaultUserAccount 4 * @dev The default implementation of a UserAccount 5 */ 6 contract DefaultUserAccount { 7 8 /** 9 * @dev Forwards a call to the specified target using the given bytes message. 10 * @param _target the address to call 11 * @param _payload the function payload consisting of the 4-bytes function hash and the abi-encoded function parameters which is typically created by 12 * calling abi.encodeWithSelector(bytes4, args...) or abi.encodeWithSignature(signatureString, args...) 13 * @return success - whether the forwarding call returned normally 14 * @return returnData - the bytes returned from calling the target function, if successful (NOTE: this is currently not supported, yet, and the returnData will always be empty) 15 * REVERTS if: 16 * - the target address is empty (0x0) 17 */ 18 function forwardCall(address _target, bytes calldata _payload) 19 external 20 returns (bool success, bytes memory returnData) 21 { 22 require(_target != address(0), "Empty target not allowed"); 23 bytes memory data = _payload; 24 assembly { 25 // Note that the return value from a method is returned via the 26 // returndata buffer, so the output argument (2nd from last) 27 // should not be used, however solidity seems to output code which 28 // does use it. Simply pass the input data as this can be read safely. 29 success := call(gas, _target, 0, add(data, 0x20), mload(data), data, 0) 30 } 31 if (success) { 32 uint returnSize; 33 assembly { 34 returnSize := returndatasize 35 } 36 returnData = new bytes(returnSize); // allocates a new byte array with the right size 37 assembly { 38 returndatacopy(add(returnData, 0x20), 0, returnSize) // copies the returned bytes from the function call into the return variable 39 } 40 } 41 } 42 43 }