ERC165StorageUpgradeable.sol 1.7 KB

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