From 5874d599cc4047306d5f1b22a0ce9754affb2bd9 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 3 May 2018 17:37:42 -0300 Subject: [PATCH] require allowance + only set resolver if needed --- ...rRegistry.sol => ENSSubdomainRegistry.sol} | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) rename contracts/registry/{UserRegistry.sol => ENSSubdomainRegistry.sol} (87%) diff --git a/contracts/registry/UserRegistry.sol b/contracts/registry/ENSSubdomainRegistry.sol similarity index 87% rename from contracts/registry/UserRegistry.sol rename to contracts/registry/ENSSubdomainRegistry.sol index ba0109f..db9c755 100644 --- a/contracts/registry/UserRegistry.sol +++ b/contracts/registry/ENSSubdomainRegistry.sol @@ -70,21 +70,30 @@ contract ENSSubdomainRegistry is Controlled { { Domain memory domain = domains[_domainHash]; require(domain.active); - subdomainHash = keccak256(_userHash, _domainHash); require(ens.owner(subdomainHash) == address(0)); require(accounts[subdomainHash].creationTime == 0); accounts[subdomainHash] = Account(domain.price, block.timestamp); - ens.setSubnodeOwner(_domainHash, _userHash, address(this)); - ens.setResolver(subdomainHash, resolver); - if(_account != address(0)){ - resolver.setAddr(subdomainHash, _account); - } - if(_pubkeyA != 0 || _pubkeyB != 0) { - resolver.setPubkey(subdomainHash, _pubkeyA, _pubkeyB); + 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.setResolver(subdomainHash, resolver); //default resolver + if(resolveAccount){ + resolver.setAddr(subdomainHash, _account); + } + if(resolvePubkey) { + resolver.setPubkey(subdomainHash, _pubkeyA, _pubkeyB); + } } + + //transfer ownship of subdone to registrant ens.setSubnodeOwner(_domainHash, _userHash, msg.sender); + //get payment require( token.transferFrom( address(msg.sender),