ERC1820Implementer.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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(bytes32 interfaceHash, address account)
  20. public
  21. view
  22. virtual
  23. override
  24. returns (bytes32)
  25. {
  26. return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  27. }
  28. /**
  29. * @dev Declares the contract as willing to be an implementer of
  30. * `interfaceHash` for `account`.
  31. *
  32. * See {IERC1820Registry-setInterfaceImplementer} and
  33. * {IERC1820Registry-interfaceHash}.
  34. */
  35. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
  36. _supportedInterfaces[interfaceHash][account] = true;
  37. }
  38. }