ERC1820Implementer.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. contract ERC1820Implementer is IERC1820Implementer {
  14. bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
  15. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  16. /**
  17. * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
  18. */
  19. function canImplementInterfaceForAddress(
  20. bytes32 interfaceHash,
  21. address account
  22. ) public view virtual override returns (bytes32) {
  23. return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  24. }
  25. /**
  26. * @dev Declares the contract as willing to be an implementer of
  27. * `interfaceHash` for `account`.
  28. *
  29. * See {IERC1820Registry-setInterfaceImplementer} and
  30. * {IERC1820Registry-interfaceHash}.
  31. */
  32. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
  33. _supportedInterfaces[interfaceHash][account] = true;
  34. }
  35. }