ERC1820ImplementerUpgradeable.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC1820Implementer.sol)
  3. pragma solidity ^0.8.0;
  4. import "./IERC1820ImplementerUpgradeable.sol";
  5. import "../../proxy/utils/Initializable.sol";
  6. /**
  7. * @dev Implementation of the {IERC1820Implementer} interface.
  8. *
  9. * Contracts may inherit from this and call {_registerInterfaceForAddress} to
  10. * declare their willingness to be implementers.
  11. * {IERC1820Registry-setInterfaceImplementer} should then be called for the
  12. * registration to be complete.
  13. */
  14. contract ERC1820ImplementerUpgradeable is Initializable, IERC1820ImplementerUpgradeable {
  15. function __ERC1820Implementer_init() internal onlyInitializing {
  16. }
  17. function __ERC1820Implementer_init_unchained() internal onlyInitializing {
  18. }
  19. bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
  20. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  21. /**
  22. * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
  23. */
  24. function canImplementInterfaceForAddress(bytes32 interfaceHash, address account)
  25. public
  26. view
  27. virtual
  28. override
  29. returns (bytes32)
  30. {
  31. return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  32. }
  33. /**
  34. * @dev Declares the contract as willing to be an implementer of
  35. * `interfaceHash` for `account`.
  36. *
  37. * See {IERC1820Registry-setInterfaceImplementer} and
  38. * {IERC1820Registry-interfaceHash}.
  39. */
  40. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
  41. _supportedInterfaces[interfaceHash][account] = true;
  42. }
  43. /**
  44. * @dev This empty reserved space is put in place to allow future versions to add new
  45. * variables without shifting down storage in the inheritance chain.
  46. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  47. */
  48. uint256[49] private __gap;
  49. }