2018-04-23 09:17:35 +00:00
|
|
|
pragma solidity ^0.4.23;
|
2018-01-09 17:07:58 +00:00
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
import "../common/Controlled.sol";
|
2018-04-23 09:17:35 +00:00
|
|
|
import "../token/ERC20Token.sol";
|
2018-01-09 17:07:58 +00:00
|
|
|
import "../ens/AbstractENS.sol";
|
|
|
|
import "../ens/PublicResolverInterface.sol";
|
2018-04-23 09:17:35 +00:00
|
|
|
|
2018-01-09 17:07:58 +00:00
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
contract SubdomainRegistry is Controlled {
|
|
|
|
|
|
|
|
struct Domain {
|
|
|
|
bool active;
|
|
|
|
uint256 price;
|
2018-01-10 01:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
mapping (bytes32 => Domain) public domains;
|
|
|
|
mapping (bytes32 => address) public registry;
|
|
|
|
mapping (bytes32 => address) public taken;
|
|
|
|
|
|
|
|
ERC20Token public token;
|
|
|
|
AbstractENS public ENSroot;
|
|
|
|
PublicResolverInterface public resolver;
|
|
|
|
|
|
|
|
event Registered(bytes32 indexed _subDomainHash, address _identity);
|
|
|
|
|
2018-04-23 09:17:35 +00:00
|
|
|
constructor(
|
2018-03-24 03:40:03 +00:00
|
|
|
address _token,
|
|
|
|
address _ens,
|
|
|
|
address _resolver
|
|
|
|
)
|
|
|
|
public
|
|
|
|
{
|
|
|
|
initialize(
|
|
|
|
ERC20Token(_token),
|
|
|
|
AbstractENS(_ens),
|
|
|
|
PublicResolverInterface(_resolver),
|
|
|
|
address(msg.sender)
|
|
|
|
);
|
2018-01-10 01:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function register(
|
|
|
|
bytes32 _userHash,
|
|
|
|
bytes32 _domainHash
|
|
|
|
)
|
|
|
|
external
|
|
|
|
returns(bytes32 subdomainHash)
|
|
|
|
{
|
|
|
|
|
|
|
|
Domain memory domain = domains[_domainHash];
|
|
|
|
require(domain.active);
|
|
|
|
|
|
|
|
require(
|
|
|
|
token.transferFrom(
|
|
|
|
address(msg.sender),
|
|
|
|
address(this),
|
|
|
|
domain.price
|
|
|
|
)
|
|
|
|
);
|
2018-04-23 09:17:35 +00:00
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
subdomainHash = keccak256(_userHash, _domainHash);
|
|
|
|
require(taken[subdomainHash] == address(0));
|
|
|
|
taken[subdomainHash] = address(msg.sender);
|
|
|
|
|
|
|
|
ENSroot.setSubnodeOwner(_domainHash, _userHash, address(this));
|
|
|
|
ENSroot.setResolver(subdomainHash, resolver);
|
|
|
|
resolver.setAddr(subdomainHash, address(msg.sender));
|
|
|
|
|
|
|
|
emit Registered(subdomainHash, address(msg.sender));
|
2018-01-10 01:19:42 +00:00
|
|
|
}
|
2018-03-24 03:40:03 +00:00
|
|
|
|
|
|
|
function update(
|
|
|
|
bytes32 _subdomainHash,
|
|
|
|
address _newContract
|
|
|
|
)
|
|
|
|
external
|
|
|
|
{
|
|
|
|
require(
|
|
|
|
msg.sender == taken[_subdomainHash] ||
|
|
|
|
msg.sender == controller
|
|
|
|
);
|
|
|
|
require(PublicResolverInterface(resolver).addr(_subdomainHash) == msg.sender);
|
|
|
|
PublicResolverInterface(resolver).setAddr(_subdomainHash, _newContract);
|
2018-01-09 17:07:58 +00:00
|
|
|
}
|
2018-03-24 03:40:03 +00:00
|
|
|
|
|
|
|
function addDomain(
|
|
|
|
bytes32 _domain,
|
|
|
|
uint256 _price
|
|
|
|
)
|
|
|
|
external
|
|
|
|
onlyController
|
|
|
|
{
|
|
|
|
require(!domains[_domain].active);
|
|
|
|
require(ENSroot.owner(_domain) == address(this));
|
|
|
|
domains[_domain] = Domain(true, _price);
|
2018-01-09 17:07:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function removeDomain(
|
|
|
|
bytes32 _domain,
|
|
|
|
address _newOwner
|
|
|
|
)
|
|
|
|
external
|
|
|
|
onlyController
|
|
|
|
{
|
|
|
|
require(ENSroot.owner(_domain) == address(this));
|
|
|
|
ENSroot.setOwner(_domain, _newOwner);
|
2018-01-09 17:07:58 +00:00
|
|
|
delete domains[_domain];
|
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function setResolver(
|
|
|
|
address _resolver
|
|
|
|
)
|
|
|
|
external
|
|
|
|
onlyController
|
|
|
|
{
|
|
|
|
resolver = PublicResolverInterface(_resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDomainPrice(
|
|
|
|
bytes32 _domain,
|
|
|
|
uint256 _price
|
|
|
|
)
|
|
|
|
external
|
|
|
|
onlyController
|
|
|
|
{
|
|
|
|
Domain storage domain = domains[_domain];
|
|
|
|
require(domain.active);
|
|
|
|
domain.price = _price;
|
2018-01-09 17:07:58 +00:00
|
|
|
}
|
2018-01-10 01:19:42 +00:00
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function initialize(
|
|
|
|
ERC20Token _token,
|
|
|
|
AbstractENS _ens,
|
|
|
|
PublicResolverInterface _resolver,
|
|
|
|
address _controller
|
|
|
|
)
|
|
|
|
public
|
|
|
|
{
|
|
|
|
require(controller == 0x0);
|
|
|
|
require(address(ENSroot) == 0x0);
|
|
|
|
require(address(token) == 0x0);
|
|
|
|
require(address(resolver) == 0x0);
|
|
|
|
controller = _controller;
|
|
|
|
token = _token;
|
|
|
|
ENSroot = _ens;
|
|
|
|
resolver = _resolver;
|
2018-01-09 17:07:58 +00:00
|
|
|
}
|
2018-03-24 03:40:03 +00:00
|
|
|
|
2018-01-09 17:07:58 +00:00
|
|
|
}
|