ERC165Storage.sol 1.3 KB

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