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-05-01 14:58:05 +00:00
|
|
|
import "../ens/ENS.sol";
|
2018-05-02 22:59:05 +00:00
|
|
|
import "../ens/PublicResolver.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;
|
2018-05-02 22:59:05 +00:00
|
|
|
mapping (bytes32 => address) public owner;
|
2018-03-24 03:40:03 +00:00
|
|
|
|
|
|
|
ERC20Token public token;
|
2018-05-01 14:58:05 +00:00
|
|
|
ENS public ens;
|
2018-05-02 22:59:05 +00:00
|
|
|
PublicResolver public resolver;
|
2018-03-24 03:40:03 +00:00
|
|
|
|
|
|
|
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),
|
2018-05-01 14:58:05 +00:00
|
|
|
ENS(_ens),
|
2018-05-02 22:59:05 +00:00
|
|
|
PublicResolver(_resolver),
|
2018-03-24 03:40:03 +00:00
|
|
|
address(msg.sender)
|
|
|
|
);
|
2018-01-10 01:19:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function register(
|
|
|
|
bytes32 _userHash,
|
2018-05-02 22:59:05 +00:00
|
|
|
bytes32 _domainHash,
|
|
|
|
address _account,
|
|
|
|
bytes32 _pubkeyA,
|
|
|
|
bytes32 _pubkeyB
|
2018-03-24 03:40:03 +00:00
|
|
|
)
|
|
|
|
external
|
|
|
|
returns(bytes32 subdomainHash)
|
|
|
|
{
|
2018-05-02 22:59:05 +00:00
|
|
|
return _register(_userHash, _domainHash, msg.sender, _account, _pubkeyA, _pubkeyB);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _register(
|
|
|
|
bytes32 _userHash,
|
|
|
|
bytes32 _domainHash,
|
|
|
|
address _owner,
|
|
|
|
address _account,
|
|
|
|
bytes32 _pubkeyA,
|
|
|
|
bytes32 _pubkeyB
|
|
|
|
)
|
|
|
|
internal
|
|
|
|
returns(bytes32 subdomainHash)
|
|
|
|
{
|
2018-03-24 03:40:03 +00:00
|
|
|
Domain memory domain = domains[_domainHash];
|
|
|
|
require(domain.active);
|
2018-05-01 14:58:05 +00:00
|
|
|
|
|
|
|
subdomainHash = keccak256(_userHash, _domainHash);
|
2018-05-02 22:59:05 +00:00
|
|
|
require(owner[subdomainHash] == address(0));
|
|
|
|
owner[subdomainHash] = _owner;
|
2018-05-01 14:58:05 +00:00
|
|
|
|
|
|
|
address currentOwner = ens.owner(subdomainHash);
|
2018-05-02 22:59:05 +00:00
|
|
|
require(currentOwner == 0);
|
2018-05-01 14:58:05 +00:00
|
|
|
|
|
|
|
ens.setSubnodeOwner(_domainHash, _userHash, address(this));
|
|
|
|
ens.setResolver(subdomainHash, resolver);
|
2018-03-24 03:40:03 +00:00
|
|
|
|
2018-05-02 22:59:05 +00:00
|
|
|
if(_account != address(0)){
|
|
|
|
resolver.setAddr(subdomainHash, _account);
|
|
|
|
}
|
|
|
|
if(_pubkeyA != 0 || _pubkeyB != 0) {
|
|
|
|
resolver.setPubkey(subdomainHash, _pubkeyA, _pubkeyB);
|
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
require(
|
|
|
|
token.transferFrom(
|
|
|
|
address(msg.sender),
|
|
|
|
address(this),
|
|
|
|
domain.price
|
|
|
|
)
|
|
|
|
);
|
2018-04-23 09:17:35 +00:00
|
|
|
|
2018-05-02 22:59:05 +00:00
|
|
|
emit Registered(subdomainHash, _owner);
|
2018-01-10 01:19:42 +00:00
|
|
|
}
|
2018-05-02 22:59:05 +00:00
|
|
|
|
|
|
|
function claimSubnodeOwnership(
|
|
|
|
bytes32 _userHash,
|
|
|
|
bytes32 _domainHash
|
|
|
|
)
|
|
|
|
external
|
|
|
|
{
|
|
|
|
bytes32 subdomainHash = keccak256(_userHash, _domainHash);
|
|
|
|
address currentOwner = owner[subdomainHash];
|
|
|
|
require(currentOwner == msg.sender);
|
|
|
|
ens.setSubnodeOwner(_domainHash, _userHash, currentOwner);
|
|
|
|
}
|
|
|
|
|
2018-03-24 03:40:03 +00:00
|
|
|
function update(
|
|
|
|
bytes32 _subdomainHash,
|
|
|
|
address _newContract
|
|
|
|
)
|
|
|
|
external
|
|
|
|
{
|
|
|
|
require(
|
2018-05-02 22:59:05 +00:00
|
|
|
msg.sender == owner[_subdomainHash] &&
|
|
|
|
address(this) == ens.owner(_subdomainHash)
|
2018-03-24 03:40:03 +00:00
|
|
|
);
|
2018-05-02 22:59:05 +00:00
|
|
|
PublicResolver(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);
|
2018-05-01 14:58:05 +00:00
|
|
|
require(ens.owner(_domain) == address(this));
|
2018-03-24 03:40:03 +00:00
|
|
|
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
|
|
|
|
{
|
2018-05-01 14:58:05 +00:00
|
|
|
require(ens.owner(_domain) == address(this));
|
|
|
|
ens.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
|
|
|
|
{
|
2018-05-02 22:59:05 +00:00
|
|
|
resolver = PublicResolver(_resolver);
|
2018-03-24 03:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2018-05-01 14:58:05 +00:00
|
|
|
ENS _ens,
|
2018-05-02 22:59:05 +00:00
|
|
|
PublicResolver _resolver,
|
2018-03-24 03:40:03 +00:00
|
|
|
address _controller
|
|
|
|
)
|
|
|
|
public
|
|
|
|
{
|
|
|
|
require(controller == 0x0);
|
2018-05-01 14:58:05 +00:00
|
|
|
require(address(ens) == 0x0);
|
2018-03-24 03:40:03 +00:00
|
|
|
require(address(token) == 0x0);
|
|
|
|
require(address(resolver) == 0x0);
|
|
|
|
controller = _controller;
|
|
|
|
token = _token;
|
2018-05-01 14:58:05 +00:00
|
|
|
ens = _ens;
|
2018-03-24 03:40:03 +00:00
|
|
|
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
|
|
|
}
|