require allowance + only set resolver if needed

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-03 17:37:42 -03:00 committed by Barry Gitarts
parent 2ecaa0fabe
commit 5874d599cc
1 changed files with 17 additions and 8 deletions

View File

@ -70,21 +70,30 @@ contract ENSSubdomainRegistry is Controlled {
{ {
Domain memory domain = domains[_domainHash]; Domain memory domain = domains[_domainHash];
require(domain.active); require(domain.active);
subdomainHash = keccak256(_userHash, _domainHash); subdomainHash = keccak256(_userHash, _domainHash);
require(ens.owner(subdomainHash) == address(0)); require(ens.owner(subdomainHash) == address(0));
require(accounts[subdomainHash].creationTime == 0); require(accounts[subdomainHash].creationTime == 0);
accounts[subdomainHash] = Account(domain.price, block.timestamp); accounts[subdomainHash] = Account(domain.price, block.timestamp);
require(token.allowance(msg.sender, address(this)) >= domain.price);
bool resolvePubkey = _pubkeyA != 0 || _pubkeyB != 0;
bool resolveAccount = _account != address(0);
if(resolvePubkey || resolveAccount) {
//set to self the ownship to setup initial resolver
ens.setSubnodeOwner(_domainHash, _userHash, address(this)); ens.setSubnodeOwner(_domainHash, _userHash, address(this));
ens.setResolver(subdomainHash, resolver); ens.setResolver(subdomainHash, resolver); //default resolver
if(_account != address(0)){ if(resolveAccount){
resolver.setAddr(subdomainHash, _account); resolver.setAddr(subdomainHash, _account);
} }
if(_pubkeyA != 0 || _pubkeyB != 0) { if(resolvePubkey) {
resolver.setPubkey(subdomainHash, _pubkeyA, _pubkeyB); resolver.setPubkey(subdomainHash, _pubkeyA, _pubkeyB);
} }
}
//transfer ownship of subdone to registrant
ens.setSubnodeOwner(_domainHash, _userHash, msg.sender); ens.setSubnodeOwner(_domainHash, _userHash, msg.sender);
//get payment
require( require(
token.transferFrom( token.transferFrom(
address(msg.sender), address(msg.sender),