/
TestRegistrar.sol
38 lines (32 loc) · 1.09 KB
/
TestRegistrar.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import "./PNS.sol";
/**
* A registrar that allocates subdomains to the first person to claim them, but
* expires registrations a fixed period after they're initially claimed.
*/
contract TestRegistrar {
uint256 constant registrationPeriod = 4 weeks;
PNS public immutable pns;
bytes32 public immutable rootNode;
mapping(bytes32 => uint256) public expiryTimes;
/**
* Constructor.
* @param pnsAddr The address of the PNS registry.
* @param node The node that this registrar administers.
*/
constructor(PNS pnsAddr, bytes32 node) {
pns = pnsAddr;
rootNode = node;
}
/**
* Register a name that's not currently registered
* @param label The hash of the label to register.
* @param owner The address of the new owner.
*/
function register(bytes32 label, address owner) public {
require(expiryTimes[label] < block.timestamp);
expiryTimes[label] = block.timestamp + registrationPeriod;
pns.setSubnodeOwner(rootNode, label, owner);
}
}