# DcnRegistry

*Address:* [*0xE9F4dfE02f895DC17E2e146e578873c9095bA293*](https://polygonscan.com/address/0xE9F4dfE02f895DC17E2e146e578873c9095bA293)

The `DcnRegistry` contract plays a pivotal role in the DCN system, providing a foundation for managing and interacting with DCN names. Built upon the ERC721 standard, the `DcnRegistry` treats each name as a unique Non-Fungible Token (NFT) ID, enabling seamless ownership, resolution, and management of DCN names.

### Manager-Exclusive Functions

Several key functions within the `DcnRegistry` are reserved for access exclusively by designated managers, such as the `DcnManager` contract. These functions include minting, minting TLDs, claiming expired names, renewing ownership periods, and setting resolvers. This design ensures a controlled and secure environment for critical operations within the DCN ecosystem.

### Resolver Management

The `DcnRegistry` facilitates the association of resolvers with individual names. Managers can utilize dedicated functions to set the resolver for a specific name, providing a seamless mechanism for resolving names to relevant data or resources.

### Information Retrieval

The contract offers a range of informative `view` functions, enabling users to access essential details about the DCN system. These functions include querying resolver information, checking the expiration status of a node, and verifying the existence of a specific node.

### Name Storage Mechanism

Names submitted for minting undergo a unique storage mechanism within the `DcnRegistry`. Upon submission, the labels of the name (in the format \["myname", "tld"]) are hashed from top to bottom, resulting in a `bytes32` variable. This `bytes32` value is then converted to a `uint256`, serving as the NFT ID uniquely associated with the submitted name. This  approach ensures the integrity and uniqueness of each DCN name while facilitating efficient and effective resolution.

```solidity
/// Iteratively calculates the name hash of a list of labels
function labelsHash(
    string[] calldata labels
) private view returns (bytes32 node) {
    require(labels.length > 1, "Labels length below 2");
    for (uint256 i = labels.length; i > 0; i--) {
        require(_exists(uint256(node)), "Parent node does not exist");
        node = namehash(node, labels[i - 1]);
    }
}

/// Calculates the name hash of a label given the parent node
function namehash(
    bytes32 node,
    string calldata label
) private pure returns (bytes32 hashed) {
    require(bytes(label).length != 0, "Empty label");
    hashed = keccak256(
        abi.encodePacked(node, keccak256(abi.encodePacked(label)))
    );
}
```

<br>
