Created
February 3, 2023 17:05
-
-
Save faytey/9f3ee229d5e3159c69040ac8fc262090 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| pragma experimental ABIEncoderV2; | |
| /// @author Faith M. Roberts | |
| /// @title A Simple Decentralized Domain Naming Service Contract. | |
| contract Faytey7Dns { | |
| address public owner; | |
| /// @dev Setting up the complex variable | |
| struct Domain { | |
| string DName; | |
| address Address; | |
| string Duration; | |
| bool exists; | |
| } | |
| uint public domains; | |
| constructor(){ | |
| owner = msg.sender; | |
| domains = 0; | |
| registerDomain("Faith", 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, "3 months"); | |
| } | |
| // Mapping the struct to a variable | |
| mapping (string => Domain) public nameservice; | |
| string registeredNames; | |
| mapping (address => bool) public Account; | |
| // Events to be emitted in the contract whenever there's a function call. | |
| event LogRegisteredDomain(string _DName, address _Address, string message); | |
| event LogDomainLookupStatus(bool); | |
| event LogReassignedDomainName(string _DName, string _NewDomain, string message); | |
| // Function to register new domain. | |
| function registerDomain(string memory _DName, address _Address, string memory _Duration) public returns(bool){ | |
| require(!Account[msg.sender], "This Account Already Exists!!!"); | |
| require(nameservice[_DName].exists == false, "Domain already exists!!!"); | |
| Domain memory _newDomain = Domain(_DName,_Address,_Duration, true); | |
| nameservice[_DName] = _newDomain; | |
| emit LogRegisteredDomain(_DName,_Address, "Successfully registered"); | |
| Account[msg.sender] = true; | |
| domains++; | |
| return true; | |
| } | |
| // Function to look up proposed names availability | |
| function domainNameLookup(string memory _DName) public view returns (address, string memory){ | |
| require(nameservice[_DName].exists == true, "This Domain is currently Available"); | |
| return(nameservice[_DName].Address,nameservice[_DName].Duration); | |
| } | |
| // Modifiers can be used to change the body of a function. | |
| // If this modifier is used, it will prepend a check that only passes | |
| // if the function is called from the owners address. | |
| modifier OnlyOwner(){ | |
| require(isOwner()); | |
| _; | |
| } | |
| // This function is used to confirm the caller of | |
| // the reassign address name is the owner. | |
| function isOwner() public view returns(bool){ | |
| return msg.sender == owner; | |
| } | |
| //Function to change the domain name to an available name | |
| function reassignAddressName(string memory _DName, string memory _NewDomain) public OnlyOwner returns(bool) { | |
| require(nameservice[_DName].exists == true, "This Domain is currently Available"); | |
| nameservice[_DName].DName = _NewDomain; | |
| emit LogReassignedDomainName(_DName, _NewDomain, "Successfully reassigned"); | |
| return true; | |
| } | |
| function getDomains() public view returns (Domain[] memory){ | |
| Domain[] memory id = new Domain[](domains); | |
| for (uint i = 0; i < domains; i++) { | |
| Domain storage domain = nameservice[i]; | |
| id[i] = domain; | |
| } | |
| return id; | |
| } | |
| function delete(uint8 index) internal{ | |
| return delete domains[index]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment