ERC165InterfacesSupported.sol 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. pragma solidity ^0.4.24;
  2. import "../../introspection/ERC165.sol";
  3. /**
  4. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-214.md#specification
  5. * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead throw an exception.
  6. * > These operations include [...], LOG0, LOG1, LOG2, [...]
  7. *
  8. * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works)
  9. * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
  10. */
  11. contract SupportsInterfaceWithLookupMock is ERC165 {
  12. bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7;
  13. /**
  14. * 0x01ffc9a7 ===
  15. * bytes4(keccak256('supportsInterface(bytes4)'))
  16. */
  17. /**
  18. * @dev a mapping of interface id to whether or not it's supported
  19. */
  20. mapping(bytes4 => bool) internal supportedInterfaces;
  21. /**
  22. * @dev A contract implementing SupportsInterfaceWithLookup
  23. * implement ERC165 itself
  24. */
  25. constructor()
  26. public
  27. {
  28. _registerInterface(InterfaceId_ERC165);
  29. }
  30. /**
  31. * @dev implement supportsInterface(bytes4) using a lookup table
  32. */
  33. function supportsInterface(bytes4 _interfaceId)
  34. external
  35. view
  36. returns (bool)
  37. {
  38. return supportedInterfaces[_interfaceId];
  39. }
  40. /**
  41. * @dev private method for registering an interface
  42. */
  43. function _registerInterface(bytes4 _interfaceId)
  44. internal
  45. {
  46. require(_interfaceId != 0xffffffff);
  47. supportedInterfaces[_interfaceId] = true;
  48. }
  49. }
  50. contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
  51. constructor (bytes4[] _interfaceIds)
  52. public
  53. {
  54. for (uint256 i = 0; i < _interfaceIds.length; i++) {
  55. _registerInterface(_interfaceIds[i]);
  56. }
  57. }
  58. }