Skip to content

Commit

Permalink
Merge pull request #6 from web3-identity/beta4
Browse files Browse the repository at this point in the history
Sync with newest ens NameWrapper code
  • Loading branch information
Pana authored Feb 22, 2023
2 parents 08fc9bb + 2f82115 commit 6084df8
Show file tree
Hide file tree
Showing 19 changed files with 1,205 additions and 1,014 deletions.
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

0 comments on commit 6084df8

Please sign in to comment.