Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with newest ens NameWrapper code #6

Merged
merged 7 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CHANGELOG
===

Last ens-contracts sync time: 2022.10.7
Last ens-contracts sync time: Feb 13, 2023

## v0.2.3

Expand Down
58 changes: 58 additions & 0 deletions contracts/utils/CNSUtil.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import '@ensdomains/ens-contracts/contracts/registry/ENS.sol';
import '@ensdomains/ens-contracts/contracts/resolvers/Resolver.sol';
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IBaseRegistrar} from '@ensdomains/ens-contracts/contracts/ethregistrar/IBaseRegistrar.sol';

contract CNSUtil is Ownable {
ENS public ens;
IBaseRegistrar public baseRegistrar;

constructor(address _ens, address _base) {
ens = ENS(_ens);
baseRegistrar = IBaseRegistrar(_base);
}

function addr(bytes32 node) public view returns (address) {
address resolver = ens.resolver(node);
if (resolver == address(0)) {
return address(0);
}
return Resolver(resolver).addr(node);
}

function addr(bytes32 node, uint256 coinType) public view returns (bytes memory) {
address resolver = ens.resolver(node);
if (resolver == address(0)) {
return bytes("");
}
return Resolver(resolver).addr(node, coinType);
}

function addrBatch(bytes32[] memory nodes) public view returns (address[] memory) {
address[] memory addrs = new address[](nodes.length);
for (uint256 i = 0; i < nodes.length; i++) {
addrs[i] = addr(nodes[i]);
}
return addrs;
}

// if token not exist of expire return zero address rather than revert
function ownerOf(uint256 tokenId) public view returns(address) {
if (baseRegistrar.nameExpires(tokenId) <= block.timestamp) {
return address(0);
}
return baseRegistrar.ownerOf(tokenId);
}

function setENS(address _ens) public onlyOwner {
ens = ENS(_ens);
}

function setBaseRegistrar(address _base) public onlyOwner {
baseRegistrar = IBaseRegistrar(_base);
}

}
28 changes: 12 additions & 16 deletions contracts/web3registrar/NameWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ contract NameWhitelist is Ownable, INameWhitelist {

bytes constant ZERO_WIDTH_SPACE = hex"e2808b";

string constant CHAR_WHITE_LIST = "abcdefghijklmnopqrstuvwxyz0123456789-"; // ABCDEFGHIJKLMNOPQRSTUVWXYZ
string constant CHAR_WHITE_LIST = "abcdefghijklmnopqrstuvwxyz0123456789_"; // ABCDEFGHIJKLMNOPQRSTUVWXYZ

string constant EMOJI_WHITE_LIST = unicode"✅";

// string constant EMOJI_BLACK_LIST = unicode"​🇨🇳";

mapping(string => bool) whiteList;
// mapping(string => bool) blackList;
mapping(string => bool) specialNames; // Reserved names
mapping(bytes32 => bool) specialNames; // Reserved names

constructor() {
strings.slice memory s1 = CHAR_WHITE_LIST.toSlice();
Expand Down Expand Up @@ -96,41 +96,37 @@ contract NameWhitelist is Ownable, INameWhitelist {
return true;
}

/* function isInEmojiBlackList(string memory toCheck) public view returns (bool) {
return blackList[toCheck];
} */

function isInWhiteList(string memory toCheck) public view returns (bool) {
return whiteList[toCheck];
}

function isReserved(string memory label) public view returns (bool) {
return specialNames[label];
return specialNames[keccak(label)];
}

function setSpecialName(string memory name, bool isSpecial) public onlyOwner {
function setSpecialName(bytes32 name, bool isSpecial) public onlyOwner {
specialNames[name] = isSpecial;
}

function setSpecialNameBatch(string[] memory names, bool isSpecial) public onlyOwner {
function setSpecialNameBatch(bytes32[] memory names, bool isSpecial) public onlyOwner {
for(uint i = 0; i < names.length; i++) {
specialNames[names[i]] = isSpecial;
}
}

function setWhiteList(string memory name, bool isWhite) public onlyOwner {
whiteList[name] = isWhite;
function setWhiteList(string memory char, bool isWhite) public onlyOwner {
whiteList[char] = isWhite;
}

function setWhiteListBatch(string memory name, bool isWhite) public onlyOwner {
strings.slice memory s1 = name.toSlice();
function setWhiteListBatch(string memory chars, bool isWhite) public onlyOwner {
strings.slice memory s1 = chars.toSlice();
uint s1Len = s1.len();
for (uint256 i = 0; i < s1Len; i++) {
whiteList[s1.nextRune().toString()] = isWhite;
}
}

/* function setBlackList(string memory name, bool isBlack) public onlyOwner {
blackList[name] = isBlack;
} */
function keccak(string memory str) private pure returns (bytes32) {
return keccak256(abi.encode(str));
}
}
Loading