refactor release to check effects interactions

This commit is contained in:
Ricardo Guilherme Schmidt 2018-09-30 01:57:18 -03:00
parent a8ec75cc04
commit fbd0e3a9a2
No known key found for this signature in database
GPG Key ID: 3F95A3AD0B607030
1 changed files with 9 additions and 7 deletions

View File

@ -134,11 +134,19 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
if (state == RegistrarState.Active) {
require(msg.sender == ensRegistry.owner(namehash), "Not owner of ENS node.");
require(block.timestamp > account.creationTime + releaseDelay, "Release period not reached.");
} else {
require(msg.sender == account.owner, "Not the former account owner.");
}
delete accounts[_label];
if (account.balance > 0) {
reserveAmount -= account.balance;
require(token.transfer(msg.sender, account.balance), "Transfer failed");
}
if (state == RegistrarState.Active) {
ensRegistry.setSubnodeOwner(ensNode, _label, address(this));
ensRegistry.setResolver(namehash, address(0));
ensRegistry.setOwner(namehash, address(0));
} else {
require(msg.sender == account.owner, "Not the former account owner.");
address newOwner = ensRegistry.owner(ensNode);
//Low level call, case dropUsername not implemented or failing, proceed release.
//Invert (!) to supress warning, return of this call have no use.
@ -149,13 +157,7 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
)
);
}
delete accounts[_label];
if (account.balance > 0) {
reserveAmount -= account.balance;
require(token.transfer(msg.sender, account.balance), "Transfer failed");
}
emit UsernameOwner(namehash, address(0));
}
/**