ERC165.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. pragma solidity ^0.5.7;
  2. import "./IERC165.sol";
  3. /**
  4. * @title ERC165
  5. * @author Matt Condon (@shrugs)
  6. * @dev Implements ERC165 using a lookup table.
  7. */
  8. contract ERC165 is IERC165 {
  9. /*
  10. * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
  11. */
  12. bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
  13. /**
  14. * @dev Mapping of interface ids to whether or not it's supported.
  15. */
  16. mapping(bytes4 => bool) private _supportedInterfaces;
  17. /**
  18. * @dev A contract implementing SupportsInterfaceWithLookup
  19. * implements ERC165 itself.
  20. */
  21. constructor () internal {
  22. _registerInterface(_INTERFACE_ID_ERC165);
  23. }
  24. /**
  25. * @dev Implement supportsInterface(bytes4) using a lookup table.
  26. */
  27. function supportsInterface(bytes4 interfaceId) external view returns (bool) {
  28. return _supportedInterfaces[interfaceId];
  29. }
  30. /**
  31. * @dev Internal method for registering an interface.
  32. */
  33. function _registerInterface(bytes4 interfaceId) internal {
  34. require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
  35. _supportedInterfaces[interfaceId] = true;
  36. }
  37. }