Skip to content

Commit

Permalink
feat(controller): implement validate-name (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 authored Oct 25, 2023
2 parents 1fdb55e + 19ed00e commit 6be381f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";

contract Migration__20231025_UpgradeController is RNSDeploy {
function run() public trySetUp {
_upgradeProxy(ContractKey.RONRegistrarController, EMPTY_ARGS);
}
}
23 changes: 17 additions & 6 deletions src/RONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ contract RONRegistrarController is
/// @dev Mapping id => owner => flag indicating whether the owner is whitelisted to buy protected name
mapping(uint256 id => mapping(address owner => bool)) internal _protectedNamesWhitelisted;

modifier onlyAvailable(string memory name) {
_requireAvailable(name);
_;
}

constructor() payable {
_disableInitializers();
}
Expand Down Expand Up @@ -150,7 +155,7 @@ contract RONRegistrarController is
address resolver,
bytes[] calldata data,
bool reverseRecord
) public pure returns (bytes32) {
) public view onlyAvailable(name) returns (bytes32) {
if (data.length != 0 && resolver == address(0)) revert ResolverRequiredWhenDataSupplied();
return keccak256(abi.encode(computeId(name), owner, duration, secret, resolver, data, reverseRecord));
}
Expand Down Expand Up @@ -201,7 +206,7 @@ contract RONRegistrarController is
data: data,
reverseRecord: reverseRecord
});
_validateCommitment(name, duration, commitHash);
_validateCommitment(duration, commitHash);

(uint256 usdPrice, uint256 ronPrice) = _handlePrice(name, duration);
_register(name, owner, duration, resolver, data, reverseRecord, usdPrice, ronPrice);
Expand Down Expand Up @@ -233,7 +238,8 @@ contract RONRegistrarController is
address resolver,
bytes[] calldata data,
bool reverseRecord
) external payable whenNotPaused nonReentrant {
) external payable whenNotPaused nonReentrant onlyAvailable(name) {
if (!available(name)) revert NameNotAvailable(name);
uint256 id = computeId(name);
bool protected = _rnsUnified.getRecord(id).mut.protected;
bool whitelisted = _protectedNamesWhitelisted[id][owner];
Expand Down Expand Up @@ -358,12 +364,10 @@ contract RONRegistrarController is
*
* Requirements:
* - The duration must larger than or equal to minimum registration duration.
* - The name must be available.
* - The passed duration must in a valid range.
*/
function _validateCommitment(string memory name, uint64 duration, bytes32 commitment) internal {
function _validateCommitment(uint64 duration, bytes32 commitment) internal {
if (duration < _minRegistrationDuration) revert DurationTooShort(duration);
if (!available(name)) revert NameNotAvailable(name);

uint256 passedDuration = block.timestamp - _committedAt[commitment];
if (passedDuration < _minCommitmentAge) revert CommitmentTooNew(commitment);
Expand Down Expand Up @@ -447,4 +451,11 @@ contract RONRegistrarController is
_priceOracle = priceOracle;
emit DomainPriceUpdated(_msgSender(), priceOracle);
}

/**
* @dev Helper method to check if a domain name is available for register.
*/
function _requireAvailable(string memory name) internal view {
if (!available(name)) revert NameNotAvailable(name);
}
}
2 changes: 1 addition & 1 deletion src/interfaces/IRONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ interface IRONRegistrarController {
address resolver,
bytes[] calldata data,
bool reverseRecord
) external pure returns (bytes32);
) external view returns (bytes32);

/**
* @dev Commits to a registration using the commitment hash.
Expand Down

0 comments on commit 6be381f

Please sign in to comment.