pragma solidity 0.5.17; /** * ENS registry test contract. */ contract EnsRegistry { struct Record { address owner; address resolver; uint64 ttl; } mapping(bytes32=>Record) records; // Logged when the owner of a node assigns a new owner to a subnode. event NewOwner(bytes32 indexed _node, bytes32 indexed _label, address _owner); // Logged when the owner of a node transfers ownership to a new account. event Transfer(bytes32 indexed _node, address _owner); // Logged when the resolver for a node changes. event NewResolver(bytes32 indexed _node, address _resolver); // Logged when the TTL of a node changes event NewTTL(bytes32 indexed _node, uint64 _ttl); // Permits modifications only by the owner of the specified node. modifier only_owner(bytes32 _node) { require(records[_node].owner == msg.sender, "ENSTest: this method needs to be called by the owner of the node"); _; } /** * Constructs a new ENS registrar. */ constructor() public { records[bytes32(0)].owner = msg.sender; } /** * Returns the address that owns the specified node. */ function owner(bytes32 _node) public view returns (address) { return records[_node].owner; } /** * Returns the address of the resolver for the specified node. */ function resolver(bytes32 _node) public view returns (address) { return records[_node].resolver; } /** * Returns the TTL of a node, and any records associated with it. */ function ttl(bytes32 _node) public view returns (uint64) { return records[_node].ttl; } /** * 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) public only_owner(_node) { emit Transfer(_node, _owner); records[_node].owner = _owner; } /** * Transfers ownership of a subnode sha3(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) public only_owner(_node) { bytes32 subnode = keccak256(abi.encodePacked(_node, _label)); emit NewOwner(_node, _label, _owner); records[subnode].owner = _owner; } /** * 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) public only_owner(_node) { emit NewResolver(_node, _resolver); records[_node].resolver = _resolver; } /** * 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) public only_owner(_node) { emit NewTTL(_node, _ttl); records[_node].ttl = _ttl; } }