ENS.sol 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. pragma solidity ^0.4.0;
  2. import './AbstractENS.sol';
  3. /**
  4. * The ENS registry contract.
  5. */
  6. contract ENS is AbstractENS {
  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. if (records[node].owner != msg.sender) throw;
  16. _;
  17. }
  18. /**
  19. * Constructs a new ENS registrar.
  20. */
  21. function ENS() {
  22. records[0].owner = msg.sender;
  23. }
  24. /**
  25. * Returns the address that owns the specified node.
  26. */
  27. function owner(bytes32 node) constant returns (address) {
  28. return records[node].owner;
  29. }
  30. /**
  31. * Returns the address of the resolver for the specified node.
  32. */
  33. function resolver(bytes32 node) constant returns (address) {
  34. return records[node].resolver;
  35. }
  36. /**
  37. * Returns the TTL of a node, and any records associated with it.
  38. */
  39. function ttl(bytes32 node) constant returns (uint64) {
  40. return records[node].ttl;
  41. }
  42. /**
  43. * Transfers ownership of a node to a new address. May only be called by the current
  44. * owner of the node.
  45. * @param node The node to transfer ownership of.
  46. * @param owner The address of the new owner.
  47. */
  48. function setOwner(bytes32 node, address owner) only_owner(node) {
  49. Transfer(node, owner);
  50. records[node].owner = owner;
  51. }
  52. /**
  53. * Transfers ownership of a subnode sha3(node, label) to a new address. May only be
  54. * called by the owner of the parent node.
  55. * @param node The parent node.
  56. * @param label The hash of the label specifying the subnode.
  57. * @param owner The address of the new owner.
  58. */
  59. function setSubnodeOwner(bytes32 node, bytes32 label, address owner) only_owner(node) {
  60. var subnode = sha3(node, label);
  61. NewOwner(node, label, owner);
  62. records[subnode].owner = owner;
  63. }
  64. /**
  65. * Sets the resolver address for the specified node.
  66. * @param node The node to update.
  67. * @param resolver The address of the resolver.
  68. */
  69. function setResolver(bytes32 node, address resolver) only_owner(node) {
  70. NewResolver(node, resolver);
  71. records[node].resolver = resolver;
  72. }
  73. /**
  74. * Sets the TTL for the specified node.
  75. * @param node The node to update.
  76. * @param ttl The TTL in seconds.
  77. */
  78. function setTTL(bytes32 node, uint64 ttl) only_owner(node) {
  79. NewTTL(node, ttl);
  80. records[node].ttl = ttl;
  81. }
  82. }