ERC165Storage.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "./ERC165.sol";
  4. /**
  5. * @dev Storage based implementation of the {IERC165} interface.
  6. *
  7. * Contracts may inherit from this and call {_registerInterface} to declare
  8. * their support of an interface.
  9. */
  10. abstract contract ERC165Storage is ERC165 {
  11. /**
  12. * @dev Mapping of interface ids to whether or not it's supported.
  13. */
  14. mapping(bytes4 => bool) private _supportedInterfaces;
  15. /**
  16. * @dev See {IERC165-supportsInterface}.
  17. */
  18. function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  19. return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId];
  20. }
  21. /**
  22. * @dev Registers the contract as an implementer of the interface defined by
  23. * `interfaceId`. Support of the actual ERC165 interface is automatic and
  24. * registering its interface id is not required.
  25. *
  26. * See {IERC165-supportsInterface}.
  27. *
  28. * Requirements:
  29. *
  30. * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
  31. */
  32. function _registerInterface(bytes4 interfaceId) internal virtual {
  33. require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
  34. _supportedInterfaces[interfaceId] = true;
  35. }
  36. }