forked from cerc-io/plugeth
e7d1867964
* contracts/ens: update public resolver solidity code * contracts/ens: update public resolver, update go bindings * update build * fix ens.sol * contracts/ens: change contract interface * contracts/ens: implement public resolver changes * contracts/ens: added ENSRegistry contract * contracts/ens: reinstate old contract code * contracts/ens: update README.md * contracts/ens: added test coverage for fallback contract * contracts/ens: added support for fallback contract * contracts/ens: removed unused contract code * contracts/ens: add todo and decode multicodec stub * add encode * vendor: add ipfs cid libraries * contracts/ens: cid sanity tests * contracts/ens: more cid sanity checks * contracts/ens: wip integration * wip * Revert "vendor: add ipfs cid libraries" This reverts commit 29d9b6b294ded903a1065d96c8149119713cfd12. * contracts/ens: removed multiformats dependencies * contracts/ens: added decode tests * contracts/ens: added eip spec test, minor changes to exiting tests * contracts/ens: moved cid decoding to own file * contracts/ens: added unit test to encode hash to content hash * contracts/ens: removed unused code * contracts/ens: fix ens tests to use cid decode and encode * contracts/ens: adjust swarm multicodecs after pr merge * contracts/ens: fix linter error * constracts/ens: address PR comments * cmd, contracts: make peoples lives easier * contracts/ens: fix linter error * contracts/ens: address PR comments
99 lines
2.9 KiB
Solidity
99 lines
2.9 KiB
Solidity
pragma solidity ^0.5.0;
|
|
|
|
import "./ENS.sol";
|
|
|
|
/**
|
|
* The ENS registry contract.
|
|
*/
|
|
contract ENSRegistry is ENS {
|
|
struct Record {
|
|
address owner;
|
|
address resolver;
|
|
uint64 ttl;
|
|
}
|
|
|
|
mapping (bytes32 => Record) records;
|
|
|
|
// Permits modifications only by the owner of the specified node.
|
|
modifier only_owner(bytes32 node) {
|
|
require(records[node].owner == msg.sender);
|
|
_;
|
|
}
|
|
|
|
/**
|
|
* @dev Constructs a new ENS registrar.
|
|
*/
|
|
constructor() public {
|
|
records[0x0].owner = msg.sender;
|
|
}
|
|
|
|
/**
|
|
* @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.
|
|
* @param node The node to transfer ownership of.
|
|
* @param owner The address of the new owner.
|
|
*/
|
|
function setOwner(bytes32 node, address owner) external only_owner(node) {
|
|
emit Transfer(node, owner);
|
|
records[node].owner = owner;
|
|
}
|
|
|
|
/**
|
|
* @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
|
|
* @param node The parent node.
|
|
* @param label The hash of the label specifying the subnode.
|
|
* @param owner The address of the new owner.
|
|
*/
|
|
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) external only_owner(node) {
|
|
bytes32 subnode = keccak256(abi.encodePacked(node, label));
|
|
emit NewOwner(node, label, owner);
|
|
records[subnode].owner = owner;
|
|
}
|
|
|
|
/**
|
|
* @dev Sets the resolver address for the specified node.
|
|
* @param node The node to update.
|
|
* @param resolver The address of the resolver.
|
|
*/
|
|
function setResolver(bytes32 node, address resolver) external only_owner(node) {
|
|
emit NewResolver(node, resolver);
|
|
records[node].resolver = resolver;
|
|
}
|
|
|
|
/**
|
|
* @dev Sets the TTL for the specified node.
|
|
* @param node The node to update.
|
|
* @param ttl The TTL in seconds.
|
|
*/
|
|
function setTTL(bytes32 node, uint64 ttl) external only_owner(node) {
|
|
emit NewTTL(node, ttl);
|
|
records[node].ttl = ttl;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the address that owns the specified node.
|
|
* @param node The specified node.
|
|
* @return address of the owner.
|
|
*/
|
|
function owner(bytes32 node) external view returns (address) {
|
|
return records[node].owner;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the address of the resolver for the specified node.
|
|
* @param node The specified node.
|
|
* @return address of the resolver.
|
|
*/
|
|
function resolver(bytes32 node) external view returns (address) {
|
|
return records[node].resolver;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the TTL of a node, and any records associated with it.
|
|
* @param node The specified node.
|
|
* @return ttl of the node.
|
|
*/
|
|
function ttl(bytes32 node) external view returns (uint64) {
|
|
return records[node].ttl;
|
|
}
|
|
|
|
} |