Last active
May 30, 2019 01:56
-
-
Save dfinzer/ad0a691b2fd73fb49f0ee88804ee09de to your computer and use it in GitHub Desktop.
ShortNameController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
class ShortNameController is Ownable { | |
BaseRegistrar base; | |
ProxyRegistry proxyRegistry; | |
address whitelistedCaller; | |
constructor(BaseRegistrar _base, ProxyRegistry _proxyRegistry, uint _registrationDuration, address _whitelistedCaller) public { | |
proxyRegistry = _proxyRegistry; | |
base = _base; | |
registrationDuration = _registrationDuration; | |
whitelistedCaller = _whitelistedCaller; | |
} | |
function available(string memory name) public view returns(bool) { | |
bytes32 label = keccak256(bytes(name)); | |
return valid(name) && base.available(uint256(label)); | |
} | |
function register(string name, address owner) external { | |
// Check that register is being called owner of the controller, or the owner's Wyvern proxy. | |
require(address(proxyRegistry.proxies(whitelistedCaller)) == msg.sender || whitelistedCaller == msg.sender); | |
// Check that the name is 3 - 6 characters. | |
uint len = name.strlen(); | |
require(len >= 3 && len <= 6); | |
// Check that the name is available. | |
require(available(name)); | |
// Register the name for the configured duration (presumably one year). | |
base.register(uint256(label), owner, _registrationDuration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment