ERC1820Implementer.sol 1.2 KB

123456789101112131415161718192021222324
  1. pragma solidity ^0.5.2;
  2. import "./IERC1820Implementer.sol";
  3. /**
  4. * @dev ERC1820Implementer allows your contract to implement an interface for another account in the sense of ERC1820.
  5. * That account or one of its ERC1820 managers can register the implementer in the ERC1820 registry, but the registry
  6. * will first check with the implementer if it agrees to it, and only allow it if it does. Using the internal
  7. * function _registerInterfaceForAddress provided by this contract, you are expressing this agreement,
  8. * and you will be able to register the contract as an implementer in the registry for that account.
  9. */
  10. contract ERC1820Implementer is IERC1820Implementer {
  11. bytes32 constant private ERC1820_ACCEPT_MAGIC = keccak256(abi.encodePacked("ERC1820_ACCEPT_MAGIC"));
  12. mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
  13. function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view returns (bytes32) {
  14. return _supportedInterfaces[interfaceHash][account] ? ERC1820_ACCEPT_MAGIC : bytes32(0x00);
  15. }
  16. function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal {
  17. _supportedInterfaces[interfaceHash][account] = true;
  18. }
  19. }