Closed chriseth closed 6 years ago
using the FIFSRegistrar
pragma solidity ^0.4.0;
import 'interface.sol';
/**
* A registrar that allocates subdomains to the first person to claim them.
*/
contract FIFSRegistrar {
AbstractENS ens;
bytes32 rootNode;
mapping (address => uint8) allowedAddresses;
modifier only_allowed() {
if (allowedAddresses[msg.sender] != 1)
throw;
_;
}
modifier only_owner(bytes32 subnode) {
var node = sha3(rootNode, subnode);
var currentOwner = ens.owner(node);
if(currentOwner != 0 && currentOwner != msg.sender)
throw;
_;
}
/**
* Constructor.
* @param ensAddr The address of the ENS registry.
* @param node The node that this registrar administers.
*/
function FIFSRegistrar(AbstractENS ensAddr, bytes32 node) {
ens = ensAddr;
rootNode = node;
}
/**
* 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.
*/
function register(bytes32 subnode, address owner) only_allowed() {
ens.setSubnodeOwner(rootNode, subnode, owner);
}
/**
* @param allowed Address who is allowed to register here.
*/
function setAllowedAddress(address allowed) only_owner(rootNode) {
allowedAddresses[allowed] = 1;
}
/**
* @param allowed Remove address who is allowed to register here.
*/
function removeAllowedAddress(address allowed) only_owner(rootNode) {
delete allowedAddresses[allowed];
}
}
The owner can arbitrarily modify the addresses that can freely register subdomains with this registrar.
Initially it was proposed that the registrar contract creates the proxy itself, but I think just specifying an address is more flexible.