ERC1820ImplementerUpgradeable.sol 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. __ERC1820Implementer_init_unchained();
  17. }
  18. function __ERC1820Implementer_init_unchained() internal onlyInitializing {
  19. }
  20. bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
  21. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  22. /**
  23. * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
  24. */
  25. function canImplementInterfaceForAddress(bytes32 interfaceHash, address account)
  26. public
  27. view
  28. virtual
  29. override
  30. returns (bytes32)
  31. {
  32. return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  33. }
  34. /**
  35. * @dev Declares the contract as willing to be an implementer of
  36. * `interfaceHash` for `account`.
  37. *
  38. * See {IERC1820Registry-setInterfaceImplementer} and
  39. * {IERC1820Registry-interfaceHash}.
  40. */
  41. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
  42. _supportedInterfaces[interfaceHash][account] = true;
  43. }
  44. uint256[49] private __gap;
  45. }