ERC1820Implementer.sol 1.3 KB

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