Skip to content

Instantly share code, notes, and snippets.

@lex-world
Created January 26, 2022 06:30
Show Gist options
  • Save lex-world/7cb28d5246b4e66b8d98d5fda8894139 to your computer and use it in GitHub Desktop.
Save lex-world/7cb28d5246b4e66b8d98d5fda8894139 to your computer and use it in GitHub Desktop.
Name Server for Binance Smart Chain.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BSCNS {
struct Record {
address owner;
string domainName;
uint expirationDate;
}
mapping (string => Record) private records;
mapping (string => Record) private expiredRecords;
modifier checkIfExpired(string memory _domainName) {
if(records[_domainName].expirationDate < block.timestamp){
_;
} else {
if(expiredRecords[_domainName].expirationDate == 0) {
markExpired(_domainName);
require(1 == 0, "Domain is Expired!");
}
}
}
function _checkRecordExist(string memory _domainName) private view returns (bool) {
if(records[_domainName].owner != address(0)){
return true;
} else {
return false;
}
}
function createRecord(string memory _domainName, uint64 _subscriptionYear) public {
require(!_checkRecordExist(_domainName), "Record already exists!");
uint expirationDate = uint(_subscriptionYear * 365 days) + block.timestamp;
records[_domainName] = Record(msg.sender, _domainName, expirationDate);
}
function transferOwnership(address _newOwner, string memory _domainName) public checkIfExpired(_domainName) {
require(_checkRecordExist(_domainName), "Record do not exists!");
require(records[_domainName].owner == msg.sender, "Only domain record owner can transfer ownership!");
records[_domainName].owner = _newOwner;
}
function markExpired(string memory _domainName) public {
expiredRecords[_domainName] = records[_domainName];
}
function getRecord(string memory _domainName) external view returns (Record memory) {
return records[_domainName];
}
}
@lex-world
Copy link
Author

Yet not completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment