Created
November 12, 2020 10:46
-
-
Save viraj124/860568f8652d1799037fc3e285ab0149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
// very simple version of the wallet contract | |
contract Wallet { | |
// this doesn't have a authentication layer since it is an example ideally which ever user is the owner of this wallet can only call this method | |
function execute(address _target, bytes memory _data) | |
public | |
payable | |
returns (bytes32 response) | |
{ | |
require(_target != address(0)); | |
// call contract in current context | |
assembly { | |
let succeeded := delegatecall(sub(gas(), 5000), _target, add(_data, 0x20), mload(_data), 0, 32) | |
response := mload(0) // load delegatecall output | |
switch iszero(succeeded) | |
case 1 { | |
// throw if delegatecall failed | |
revert(0, 0) | |
} | |
} | |
} | |
receive() external payable {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment