ERC165.sol 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma solidity ^0.5.0;
  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 _INTERFACE_ID_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) private _supportedInterfaces;
  18. /**
  19. * @dev A contract implementing SupportsInterfaceWithLookup
  20. * implement ERC165 itself
  21. */
  22. constructor () internal {
  23. _registerInterface(_INTERFACE_ID_ERC165);
  24. }
  25. /**
  26. * @dev implement supportsInterface(bytes4) using a lookup table
  27. */
  28. function supportsInterface(bytes4 interfaceId) external view returns (bool) {
  29. return _supportedInterfaces[interfaceId];
  30. }
  31. /**
  32. * @dev internal method for registering an interface
  33. */
  34. function _registerInterface(bytes4 interfaceId) internal {
  35. require(interfaceId != 0xffffffff);
  36. _supportedInterfaces[interfaceId] = true;
  37. }
  38. }