2018-06-20 19:14:06 +00:00
|
|
|
pragma solidity ^0.4.18;
|
|
|
|
|
|
|
|
import './ENS.sol';
|
2018-07-13 16:37:34 +00:00
|
|
|
import './Resolver.sol';
|
2018-06-20 19:14:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A registrar that allocates subdomains to the first person to claim them.
|
|
|
|
*/
|
|
|
|
contract FIFSRegistrar {
|
|
|
|
ENS ens;
|
|
|
|
bytes32 rootNode;
|
2018-07-13 16:37:34 +00:00
|
|
|
Resolver resolver;
|
2018-06-20 19:14:06 +00:00
|
|
|
|
|
|
|
modifier only_owner(bytes32 subnode) {
|
2018-07-12 20:31:00 +00:00
|
|
|
bytes32 node = sha3(rootNode, subnode);
|
|
|
|
address currentOwner = ens.owner(node);
|
2018-06-20 19:14:06 +00:00
|
|
|
require(currentOwner == 0 || currentOwner == msg.sender);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param ensAddr The address of the ENS registry.
|
|
|
|
* @param node The node that this registrar administers.
|
|
|
|
*/
|
2018-07-13 16:37:34 +00:00
|
|
|
function FIFSRegistrar(ENS ensAddr, bytes32 node, Resolver resolverAddr) public {
|
2018-06-20 19:14:06 +00:00
|
|
|
ens = ensAddr;
|
|
|
|
rootNode = node;
|
2018-07-13 16:37:34 +00:00
|
|
|
resolver = resolverAddr;
|
2018-06-20 19:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a name, or change the owner of an existing registration.
|
|
|
|
* @param subnode The hash of the label to register.
|
|
|
|
* @param owner The address of the new owner.
|
|
|
|
*/
|
2018-07-13 16:37:34 +00:00
|
|
|
function register(bytes32 subnode, address owner, address _account) public only_owner(subnode) {
|
|
|
|
bytes32 subdomainHash = sha3(rootNode, subnode);
|
2018-06-20 19:14:06 +00:00
|
|
|
ens.setSubnodeOwner(rootNode, subnode, owner);
|
2018-07-13 16:37:34 +00:00
|
|
|
ens.setResolver(subdomainHash, resolver); //default resolver
|
|
|
|
bool resolveAccount = _account != address(0);
|
|
|
|
if (resolveAccount) {
|
|
|
|
resolver.setAddr(subdomainHash, _account);
|
|
|
|
}
|
2018-06-20 19:14:06 +00:00
|
|
|
}
|
|
|
|
}
|