-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from web3-identity/beta4
Sync with newest ens NameWrapper code
- Loading branch information
Showing
19 changed files
with
1,205 additions
and
1,014 deletions.
There are no files selected for viewing
This file contains 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
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 | ||
|
||
|
This file contains 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
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); | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.