ERC165.sol 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. pragma solidity ^0.4.24;
  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. bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
  10. /**
  11. * 0x01ffc9a7 ===
  12. * bytes4(keccak256('supportsInterface(bytes4)'))
  13. */
  14. /**
  15. * @dev a mapping of interface id to whether or not it's supported
  16. */
  17. mapping(bytes4 => bool) internal _supportedInterfaces;
  18. /**
  19. * @dev A contract implementing SupportsInterfaceWithLookup
  20. * implement ERC165 itself
  21. */
  22. constructor()
  23. public
  24. {
  25. _registerInterface(_InterfaceId_ERC165);
  26. }
  27. /**
  28. * @dev implement supportsInterface(bytes4) using a lookup table
  29. */
  30. function supportsInterface(bytes4 interfaceId)
  31. external
  32. view
  33. returns (bool)
  34. {
  35. return _supportedInterfaces[interfaceId];
  36. }
  37. /**
  38. * @dev private method for registering an interface
  39. */
  40. function _registerInterface(bytes4 interfaceId)
  41. internal
  42. {
  43. require(interfaceId != 0xffffffff);
  44. _supportedInterfaces[interfaceId] = true;
  45. }
  46. }