ERC721ReceiverMock.sol 731 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pragma solidity ^0.4.24;
  2. import "../token/ERC721/IERC721Receiver.sol";
  3. contract ERC721ReceiverMock is IERC721Receiver {
  4. bytes4 private _retval;
  5. bool private _reverts;
  6. event Received(
  7. address operator,
  8. address from,
  9. uint256 tokenId,
  10. bytes data,
  11. uint256 gas
  12. );
  13. constructor(bytes4 retval, bool reverts) public {
  14. _retval = retval;
  15. _reverts = reverts;
  16. }
  17. function onERC721Received(
  18. address operator,
  19. address from,
  20. uint256 tokenId,
  21. bytes data
  22. )
  23. public
  24. returns(bytes4)
  25. {
  26. require(!_reverts);
  27. emit Received(
  28. operator,
  29. from,
  30. tokenId,
  31. data,
  32. gasleft() // msg.gas was deprecated in solidityv0.4.21
  33. );
  34. return _retval;
  35. }
  36. }