Working on a NFT marketplace I want to disallow direct transfers, to only allow transfering through this contract's custom function createSale()
Here is the way I came about:
function onERC721Received( address operator, address from, uint256 tokenId,bytes calldata data ) external override returns (bytes4) {
if(msg.sender != address(this) && tx.origin == operator) revert("direct transfer not allowed"); //disallow direct transfers
emit NFTReceived(operator, from, tokenId, 1, "ERC721", data);
return IERC721Receiver.onERC721Received.selector;
}
So far it seems to be working and the tons of tests I ran seem to be fine.
However I'm wondering if there are any problems that I may have not seen, and is such method totally secure ? Are there any potential pitfalls ?