ERC1820Implementer.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC1820Implementer.sol)
  3. pragma solidity ^0.8.0;
  4. import "./IERC1820Implementer.sol";
  5. /**
  6. * @dev Implementation of the {IERC1820Implementer} interface.
  7. *
  8. * Contracts may inherit from this and call {_registerInterfaceForAddress} to
  9. * declare their willingness to be implementers.
  10. * {IERC1820Registry-setInterfaceImplementer} should then be called for the
  11. * registration to be complete.
  12. *
  13. * CAUTION: This file is deprecated as of v4.9 and will be removed in the next major release.
  14. */
  15. contract ERC1820Implementer is IERC1820Implementer {
  16. bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
  17. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  18. /**
  19. * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
  20. */
  21. function canImplementInterfaceForAddress(
  22. bytes32 interfaceHash,
  23. address account
  24. ) public view virtual override returns (bytes32) {
  25. return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  26. }
  27. /**
  28. * @dev Declares the contract as willing to be an implementer of
  29. * `interfaceHash` for `account`.
  30. *
  31. * See {IERC1820Registry-setInterfaceImplementer} and
  32. * {IERC1820Registry-interfaceHash}.
  33. */
  34. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
  35. _supportedInterfaces[interfaceHash][account] = true;
  36. }
  37. }