github.com/needkane/go-ethereum@v1.7.4-0.20180131070256-c212876ea2b7/contracts/ens/contract/ENS.sol (about)

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