ENSRegistry.sol 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. pragma solidity ^0.5.0;
  2. import "./ENS.sol";
  3. /**
  4. * The ENS registry contract.
  5. */
  6. contract ENSRegistry is ENS {
  7. struct Record {
  8. address owner;
  9. address resolver;
  10. uint64 ttl;
  11. }
  12. mapping (bytes32 => Record) records;
  13. // Permits modifications only by the owner of the specified node.
  14. modifier only_owner(bytes32 node) {
  15. require(records[node].owner == msg.sender);
  16. _;
  17. }
  18. /**
  19. * @dev Constructs a new ENS registrar.
  20. */
  21. constructor() public {
  22. records[0x0].owner = msg.sender;
  23. }
  24. /**
  25. * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.
  26. * @param node The node to transfer ownership of.
  27. * @param owner The address of the new owner.
  28. */
  29. function setOwner(bytes32 node, address owner) external only_owner(node) {
  30. emit Transfer(node, owner);
  31. records[node].owner = owner;
  32. }
  33. /**
  34. * @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
  35. * @param node The parent node.
  36. * @param label The hash of the label specifying the subnode.
  37. * @param owner The address of the new owner.
  38. */
  39. function setSubnodeOwner(bytes32 node, bytes32 label, address owner) external only_owner(node) {
  40. bytes32 subnode = keccak256(abi.encodePacked(node, label));
  41. emit NewOwner(node, label, owner);
  42. records[subnode].owner = owner;
  43. }
  44. /**
  45. * @dev Sets the resolver address for the specified node.
  46. * @param node The node to update.
  47. * @param resolver The address of the resolver.
  48. */
  49. function setResolver(bytes32 node, address resolver) external only_owner(node) {
  50. emit NewResolver(node, resolver);
  51. records[node].resolver = resolver;
  52. }
  53. /**
  54. * @dev Sets the TTL for the specified node.
  55. * @param node The node to update.
  56. * @param ttl The TTL in seconds.
  57. */
  58. function setTTL(bytes32 node, uint64 ttl) external only_owner(node) {
  59. emit NewTTL(node, ttl);
  60. records[node].ttl = ttl;
  61. }
  62. /**
  63. * @dev Returns the address that owns the specified node.
  64. * @param node The specified node.
  65. * @return address of the owner.
  66. */
  67. function owner(bytes32 node) external view returns (address) {
  68. return records[node].owner;
  69. }
  70. /**
  71. * @dev Returns the address of the resolver for the specified node.
  72. * @param node The specified node.
  73. * @return address of the resolver.
  74. */
  75. function resolver(bytes32 node) external view returns (address) {
  76. return records[node].resolver;
  77. }
  78. /**
  79. * @dev Returns the TTL of a node, and any records associated with it.
  80. * @param node The specified node.
  81. * @return ttl of the node.
  82. */
  83. function ttl(bytes32 node) external view returns (uint64) {
  84. return records[node].ttl;
  85. }
  86. }