FIFSRegistrar.sol 1.0 KB

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