2018-03-07 21:29:21 +00:00
|
|
|
pragma solidity ^0.4.0;
|
|
|
|
|
|
|
|
import './AbstractENS.sol';
|
2018-01-29 19:44:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ENS registry contract.
|
|
|
|
*/
|
2018-03-07 21:29:21 +00:00
|
|
|
contract ENS is AbstractENS {
|
2018-01-29 19:44:18 +00:00
|
|
|
struct Record {
|
|
|
|
address owner;
|
|
|
|
address resolver;
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64 ttl;
|
2018-01-29 19:44:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
mapping(bytes32=>Record) records;
|
2018-01-29 19:44:18 +00:00
|
|
|
|
|
|
|
// Permits modifications only by the owner of the specified node.
|
|
|
|
modifier only_owner(bytes32 node) {
|
2018-03-07 21:29:21 +00:00
|
|
|
if (records[node].owner != msg.sender) throw;
|
|
|
|
_;
|
2018-01-29 19:44:18 +00:00
|
|
|
}
|
2018-03-07 21:29:21 +00:00
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
/**
|
2018-03-07 21:29:21 +00:00
|
|
|
* Constructs a new ENS registrar.
|
2018-01-29 19:44:18 +00:00
|
|
|
*/
|
2018-03-07 21:29:21 +00:00
|
|
|
function ENS() {
|
|
|
|
records[0].owner = msg.sender;
|
2018-01-29 19:44:18 +00:00
|
|
|
}
|
2018-03-07 21:29:21 +00:00
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
/**
|
|
|
|
* Returns the address that owns the specified node.
|
|
|
|
*/
|
|
|
|
function owner(bytes32 node) constant returns (address) {
|
|
|
|
return records[node].owner;
|
|
|
|
}
|
2018-03-07 21:29:21 +00:00
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
/**
|
|
|
|
* Returns the address of the resolver for the specified node.
|
|
|
|
*/
|
|
|
|
function resolver(bytes32 node) constant returns (address) {
|
|
|
|
return records[node].resolver;
|
|
|
|
}
|
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
/**
|
|
|
|
* Returns the TTL of a node, and any records associated with it.
|
|
|
|
*/
|
|
|
|
function ttl(bytes32 node) constant returns (uint64) {
|
|
|
|
return records[node].ttl;
|
|
|
|
}
|
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
function setOwner(bytes32 node, address owner) only_owner(node) {
|
|
|
|
Transfer(node, owner);
|
|
|
|
records[node].owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfers ownership of a subnode sha3(node, label) to a new address. May only be
|
|
|
|
* called by the owner of the parent node.
|
|
|
|
* @param node The parent node.
|
|
|
|
* @param label The hash of the label specifying the subnode.
|
|
|
|
* @param owner The address of the new owner.
|
|
|
|
*/
|
|
|
|
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) only_owner(node) {
|
|
|
|
var subnode = sha3(node, label);
|
|
|
|
NewOwner(node, label, owner);
|
|
|
|
records[subnode].owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the resolver address for the specified node.
|
|
|
|
* @param node The node to update.
|
|
|
|
* @param resolver The address of the resolver.
|
|
|
|
*/
|
|
|
|
function setResolver(bytes32 node, address resolver) only_owner(node) {
|
|
|
|
NewResolver(node, resolver);
|
|
|
|
records[node].resolver = resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-07 21:29:21 +00:00
|
|
|
* Sets the TTL for the specified node.
|
2018-01-29 19:44:18 +00:00
|
|
|
* @param node The node to update.
|
2018-03-07 21:29:21 +00:00
|
|
|
* @param ttl The TTL in seconds.
|
2018-01-29 19:44:18 +00:00
|
|
|
*/
|
2018-03-07 21:29:21 +00:00
|
|
|
function setTTL(bytes32 node, uint64 ttl) only_owner(node) {
|
|
|
|
NewTTL(node, ttl);
|
|
|
|
records[node].ttl = ttl;
|
2018-01-29 19:44:18 +00:00
|
|
|
}
|
|
|
|
}
|