Skip to content

Instantly share code, notes, and snippets.

@leonpw
Created February 26, 2023 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonpw/2be1f4d433af1672250005db0cf678e6 to your computer and use it in GitHub Desktop.
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.
// 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