ERC1820Implementer.sol 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "./IERC1820Implementer.sol";
  4. /**
  5. * @dev Implementation of the {IERC1820Implementer} interface.
  6. *
  7. * Contracts may inherit from this and call {_registerInterfaceForAddress} to
  8. * declare their willingness to be implementers.
  9. * {IERC1820Registry-setInterfaceImplementer} should then be called for the
  10. * registration to be complete.
  11. */
  12. contract ERC1820Implementer is IERC1820Implementer {
  13. bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
  14. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  15. /**
  16. * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
  17. */
  18. function canImplementInterfaceForAddress(bytes32 interfaceHash, address account)
  19. public
  20. view
  21. virtual
  22. override
  23. returns (bytes32)
  24. {
  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. }