Skip to content

Commit

Permalink
Merge pull request ensdomains#42 from ensdomains/namewrapper
Browse files Browse the repository at this point in the history
Add namewrapper to ens-contracts
  • Loading branch information
Arachnid authored Oct 7, 2021
2 parents edc0320 + 0a95e7f commit 52d8297
Show file tree
Hide file tree
Showing 28 changed files with 7,868 additions and 2,287 deletions.
6 changes: 6 additions & 0 deletions .env.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PRIVATE_KEY=
ETHERSCAN_API_KEY=
INFURA_API_KEY=
METADATA_ADDRESS=
WRAPPER_ADDRESS=
RESOLVER_ADDRESS=
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
env: {
mocha: true,
},
plugins: ["babel"],
rules: {
"import/extensions": [
"error",
"ignorePackages",
{
js: "never",
ts: "never",
},
],
"import/prefer-default-export": "off",
"prefer-destructuring": "off",
"prefer-template": "off",
"no-console": "off",
"func-names": "off",
},
};
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
node_modules
artifacts
cache
gasreport-*
.env
*.DS_Store
node_modules
build

#Hardhat files
cache
artifacts
9 changes: 9 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "solium:all",
"rules": {
"indentation": ["error", 4],
"quotes": ["error", "double"],
"arg-overflow": "off",
"blank-lines": "off"
}
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ script:

notifications:
email: false

51 changes: 51 additions & 0 deletions contracts/wrapper/BytesUtil.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

library BytesUtils {
/*
* @dev Returns the keccak-256 hash of a byte range.
* @param self The byte string to hash.
* @param offset The position to start hashing at.
* @param len The number of bytes to hash.
* @return The hash of the byte range.
*/
function keccak(bytes memory self, uint offset, uint len) internal pure returns (bytes32 ret) {
require(offset + len <= self.length);
assembly {
ret := keccak256(add(add(self, 32), offset), len)
}
}

/**
* @dev Returns the ENS namehash of a DNS-encoded name.
* @param self The DNS-encoded name to hash.
* @param offset The offset at which to start hashing.
* @return The namehash of the name.
*/
function namehash(bytes memory self, uint offset) internal pure returns(bytes32) {
(bytes32 labelhash, uint newOffset) = readLabel(self, offset);
if(labelhash == bytes32(0)) {
require(offset == self.length - 1, "namehash: Junk at end of name");
return bytes32(0);
}
return keccak256(abi.encodePacked(namehash(self, newOffset), labelhash));
}

/**
* @dev Returns the keccak-256 hash of a DNS-encoded label, and the offset to the start of the next label.
* @param self The byte string to read a label from.
* @param idx The index to read a label at.
* @return labelhash The hash of the label at the specified index, or 0 if it is the last label.
* @return newIdx The index of the start of the next label.
*/
function readLabel(bytes memory self, uint256 idx) internal pure returns (bytes32 labelhash, uint newIdx) {
require(idx < self.length, "readLabel: Index out of bounds");
uint len = uint(uint8(self[idx]));
if(len > 0) {
labelhash = keccak(self, idx + 1, len);
} else {
labelhash = bytes32(0);
}
newIdx = idx + len + 1;
}
}
20 changes: 20 additions & 0 deletions contracts/wrapper/Controllable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/access/Ownable.sol";

contract Controllable is Ownable {
mapping(address=>bool) public controllers;

event ControllerChanged(address indexed controller, bool active);

function setController(address controller, bool active) onlyOwner() public {
controllers[controller] = active;
emit ControllerChanged(controller, active);
}

modifier onlyController() {
require(controllers[msg.sender], "Controllable: Caller is not a controller");
_;
}
}
Loading

0 comments on commit 52d8297

Please sign in to comment.