Skip to content

Instantly share code, notes, and snippets.

@torralbaa
Last active September 15, 2019 18:15
Show Gist options
  • Save torralbaa/5ec7dabfa5f3ead0cb37d4c73ab20c82 to your computer and use it in GitHub Desktop.
Save torralbaa/5ec7dabfa5f3ead0cb37d4c73ab20c82 to your computer and use it in GitHub Desktop.
dns3 Ethereum smart constract.
/*
* dns3.sol
*
* Copyright 2019 Alvarito050506 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
pragma solidity >= 0.5.11;
contract dns3
{
struct Domain
{
address owner;
string[6] records;
string parent;
uint256 expire;
}
mapping (string => Domain) private domains;
address private developer;
string[] private topleveldomains = ["alt", "bit", "coin", "ether", "hack", "ip", "me", "my", "network", "node", "test", "token"];
constructor() public
{
developer = msg.sender;
for (uint8 i = 0; i < topleveldomains.length; i++)
{
domains[topleveldomains[i]].owner = address(this);
}
}
function claimDomain(string memory _name, string memory _parent) public returns (bool success)
{
string memory _domain = string(abi.encodePacked(_name, ".", _parent));
require(bytes(_name).length >= 3);
require(domains[_domain].owner == address(0x00) || now > domains[_domain].expire);
require(domains[_parent].owner == msg.sender || domains[_parent].owner == address(this));
domains[_domain].owner = msg.sender;
domains[_domain].parent = _parent;
domains[_domain].expire = now + 31536000;
return true;
}
function renewDomain(string memory _domain) public returns (bool success)
{
require(domains[_domain].owner == msg.sender);
require(now < domains[_domain].expire && now >= domains[_domain].expire - 25200);
domains[_domain].expire = now + 31536000;
return true;
}
function transferDomain(string memory _domain, address _to) public returns (bool success)
{
require(domains[_domain].owner == msg.sender && now < domains[_domain].expire - 25200);
require(_to != address(this) && _to != address(0x00));
domains[_domain].owner = _to;
return true;
}
function getRecord(string memory _domain, uint8 _record) public view returns (string memory record)
{
return domains[_domain].records[_record];
}
function setRecord(string memory _domain, string memory _data, uint8 _record) public returns (bool success)
{
require(domains[_domain].owner == msg.sender && now < domains[_domain].expire - 25200);
domains[_domain].records[_record] = _data;
return true;
}
function ownerOf(string memory _domain) public view returns (address owner)
{
return domains[_domain].owner;
}
function newTopLevelDomain(string memory _domain) public returns (bool success)
{
require(developer == msg.sender);
require(domains[_domain].owner == address(0x00));
domains[_domain].owner = address(this);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment