ERC165InterfacesSupported.sol 1.8 KB

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