FIFSRegistrar.sol 1007 B

123456789101112131415161718192021222324252627282930313233343536
  1. pragma solidity ^0.5.0;
  2. import "./ENS.sol";
  3. /**
  4. * A registrar that allocates subdomains to the first person to claim them.
  5. */
  6. contract FIFSRegistrar {
  7. ENS ens;
  8. bytes32 rootNode;
  9. modifier only_owner(bytes32 label) {
  10. address currentOwner = ens.owner(keccak256(abi.encodePacked(rootNode, label)));
  11. require(currentOwner == address(0x0) || currentOwner == msg.sender);
  12. _;
  13. }
  14. /**
  15. * Constructor.
  16. * @param ensAddr The address of the ENS registry.
  17. * @param node The node that this registrar administers.
  18. */
  19. constructor(ENS ensAddr, bytes32 node) public {
  20. ens = ensAddr;
  21. rootNode = node;
  22. }
  23. /**
  24. * Register a name, or change the owner of an existing registration.
  25. * @param label The hash of the label to register.
  26. * @param owner The address of the new owner.
  27. */
  28. function register(bytes32 label, address owner) public only_owner(label) {
  29. ens.setSubnodeOwner(rootNode, label, owner);
  30. }
  31. }