2018-06-13 17:29:43 +00:00
|
|
|
pragma solidity ^0.4.18;
|
|
|
|
|
|
|
|
import './ENS.sol';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ENS registry contract.
|
|
|
|
*/
|
|
|
|
contract ENSRegistry is ENS {
|
|
|
|
struct Record {
|
|
|
|
address owner;
|
|
|
|
address resolver;
|
|
|
|
uint64 ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapping (bytes32 => Record) records;
|
|
|
|
|
|
|
|
// Permits modifications only by the owner of the specified node.
|
2018-07-23 15:56:33 +00:00
|
|
|
modifier only_owner(bytes32 node, address owner) {
|
|
|
|
require(records[node].owner == 0 || records[node].owner == msg.sender || records[node].owner == owner);
|
2018-06-13 17:29:43 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Constructs a new ENS registrar.
|
|
|
|
*/
|
2018-08-16 15:34:47 +00:00
|
|
|
constructor() public {
|
2018-06-13 17:29:43 +00:00
|
|
|
records[0x0].owner = msg.sender;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.
|
|
|
|
* @param node The node to transfer ownership of.
|
|
|
|
* @param owner The address of the new owner.
|
|
|
|
*/
|
2018-07-23 15:56:33 +00:00
|
|
|
function setOwner(bytes32 node, address owner) public only_owner(node, owner) {
|
2018-08-16 15:34:47 +00:00
|
|
|
emit Transfer(node, owner);
|
2018-06-13 17:29:43 +00:00
|
|
|
records[node].owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-13 16:37:34 +00:00
|
|
|
* @dev Transfers ownership of a subnode sha3(node, label) to a new address. May only be called by the owner of the parent node.
|
2018-06-13 17:29:43 +00:00
|
|
|
* @param node The parent node.
|
|
|
|
* @param label The hash of the label specifying the subnode.
|
|
|
|
* @param owner The address of the new owner.
|
|
|
|
*/
|
2018-07-23 15:56:33 +00:00
|
|
|
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public only_owner(node, owner) {
|
2018-08-16 15:34:47 +00:00
|
|
|
bytes32 subnode = keccak256(abi.encodePacked(node, label));
|
|
|
|
emit NewOwner(node, label, owner);
|
2018-06-13 17:29:43 +00:00
|
|
|
records[subnode].owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Sets the resolver address for the specified node.
|
|
|
|
* @param node The node to update.
|
|
|
|
* @param resolver The address of the resolver.
|
|
|
|
*/
|
2018-07-25 15:05:27 +00:00
|
|
|
function setResolver(bytes32 node, address resolver) public only_owner(node, 0x0) {
|
2018-08-16 15:34:47 +00:00
|
|
|
emit NewResolver(node, resolver);
|
2018-06-13 17:29:43 +00:00
|
|
|
records[node].resolver = resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Sets the TTL for the specified node.
|
|
|
|
* @param node The node to update.
|
|
|
|
* @param ttl The TTL in seconds.
|
|
|
|
*/
|
2018-07-23 15:56:33 +00:00
|
|
|
function setTTL(bytes32 node, uint64 ttl) public only_owner(node, 0x0) {
|
2018-08-16 15:34:47 +00:00
|
|
|
emit NewTTL(node, ttl);
|
2018-06-13 17:29:43 +00:00
|
|
|
records[node].ttl = ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the address that owns the specified node.
|
|
|
|
* @param node The specified node.
|
|
|
|
* @return address of the owner.
|
|
|
|
*/
|
|
|
|
function owner(bytes32 node) public view returns (address) {
|
|
|
|
return records[node].owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the address of the resolver for the specified node.
|
|
|
|
* @param node The specified node.
|
|
|
|
* @return address of the resolver.
|
|
|
|
*/
|
|
|
|
function resolver(bytes32 node) public view returns (address) {
|
|
|
|
return records[node].resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the TTL of a node, and any records associated with it.
|
|
|
|
* @param node The specified node.
|
|
|
|
* @return ttl of the node.
|
|
|
|
*/
|
|
|
|
function ttl(bytes32 node) public view returns (uint64) {
|
|
|
|
return records[node].ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|