github.com/daeglee/go-ethereum@v0.0.0-20190504220456-cad3e8d18e9b/contracts/ens/contract/ENSRegistry.sol (about)

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