Created
February 26, 2023 20:24
-
-
Save leonpw/2be1f4d433af1672250005db0cf678e6 to your computer and use it in GitHub Desktop.
Example function selector as a member of a function. Should revert if ERC20 transfer is passed.
This file contains hidden or 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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.4.22 <0.9.0; | |
contract QueryContract { | |
event Selector(bytes4); | |
function query(bytes memory data, function(address,uint) external test) public { | |
emit Selector(test.selector); | |
if(test.selector == 0xa9059cbb) | |
revert(); | |
} | |
} | |
contract QueryUser { | |
QueryContract public query; | |
constructor (){ | |
query = new QueryContract(); | |
} | |
function callQueryTransfer() public { | |
query.query("This should revert", this.transfer); | |
} | |
function callQueryNotTransfer() public { | |
query.query("This is ok", this.notTransfer); | |
} | |
function transfer(address dest, uint256 amount) external { | |
// | |
} | |
function notTransfer(address dest, uint256 amount) external{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment