Contracts
ERSRegistry

Solidity API

ERSRegistry

Fork of ENSRegistry with adapted data structures and accessiblity logic in order to conform to needs of ERS. Node owners can create any subnode. A node tracks the owner of the node and the address the node resolves to. Within the context of ERS a resolver represents either a smart contract OR a chip. The owner has the ability to create any subnodes of its choosing, however only the TSMRegistry is able to change both the owner and the resolver for a given node once created. The ChipRegistry is able to change the owner of a node (signifying a transfer of a chip) but is not able to change the resolver. These permissions are put in place in order to maintain a track record of authenticity for chips while allowing the TSMRegistry to re-assign sub-domains to new TSMRegistrars. Note that if a TSMRegistry's subnode is reassigned to a new TSMRegistrar the new TSMRegistrar CANNOT overwrite the nodes created by the previous node owner.

NewOwner

event NewOwner(bytes32 node, bytes32 subnode, bytes32 nameHash, address owner)

Transfer

event Transfer(bytes32 node, address owner)

NewResolver

event NewResolver(bytes32 node, address resolver)

Record

struct Record {
  address owner;
  address resolver;
}

authorised

modifier authorised(bytes32 _node)

chipRegistry

contract IChipRegistry chipRegistry

tsmRegistry

contract ITSMRegistry tsmRegistry

records

mapping(bytes32 => struct ERSRegistry.Record) records

constructor

constructor(contract IChipRegistry _chipRegistry, contract ITSMRegistry _tsmRegistry) public

Constructs a new ERS registry.

createSubnodeRecord

function createSubnodeRecord(bytes32 _node, bytes32 _nameHash, address _owner, address _resolver) external virtual returns (bytes32)

_Sets the record for a new subnode. May only be called by owner of node (checked in setSubnodeOwner).

Parameters

NameTypeDescription
_nodebytes32The parent node.
_nameHashbytes32The hash of the nameHash specifying the subnode.
_owneraddressThe address of the new owner.
_resolveraddressThe address of the resolver.

Return Values

NameTypeDescription
[0]bytes32The newly created subnode hash

deleteSubnodeRecord

function deleteSubnodeRecord(bytes32 _node, bytes32 _nameHash) external virtual

ONLY TSM REGISTRY: Deletes the record for an already created subnode. TSM Registry must be the owner of the node so as to not accidentally delete a non TSMRegistrar subnode.

Parameters

NameTypeDescription
_nodebytes32The parent node.
_nameHashbytes32The hash of the nameHash specifying the subnode.

setNodeOwner

function setNodeOwner(bytes32 _node, address _newOwner) external virtual

ONLY CHIP REGISTRY: Transfers ownership of a node to a new address. Owner cannot directly call (unless root node), ChipRegistry must manage ownership changes for chips in order to keep state consistent between ChipRegistry and ERS.

Parameters

NameTypeDescription
_nodebytes32The node to transfer ownership of.
_newOwneraddressThe address of the new owner.

isValidChipState

function isValidChipState(bytes32 _node, address _chipId, address _owner) external view virtual returns (bool)

Validate that state has been correctly set for a chip. Used by ChipRegistry to validate that a ProjectRegistrar has set the correct state for a chip.

Parameters

NameTypeDescription
_nodebytes32The specified node.
_chipIdaddressThe specified chipId.
_owneraddressThe specified owner.

Return Values

NameTypeDescription
[0]boolbool indicating whether state is valid

getOwner

function getOwner(bytes32 _node) public view virtual returns (address)

Returns the address that owns the specified node.

Parameters

NameTypeDescription
_nodebytes32The specified node.

Return Values

NameTypeDescription
[0]addressaddress of the owner.

getSubnodeOwner

function getSubnodeOwner(bytes32 _node, bytes32 _nameHash) external view virtual returns (address)

Returns the address that owns the specified subnode.

Parameters

NameTypeDescription
_nodebytes32The specified node.
_nameHashbytes32The specified nameHash.

Return Values

NameTypeDescription
[0]addressaddress of the owner.

getResolver

function getResolver(bytes32 _node) external view virtual returns (address)

Returns the address of the resolver for the specified node.

Parameters

NameTypeDescription
_nodebytes32The specified node.

Return Values

NameTypeDescription
[0]addressaddress of the resolver.

recordExists

function recordExists(bytes32 _node) public view virtual returns (bool)

Returns whether a record has been written to the registry for that node.

Parameters

NameTypeDescription
_nodebytes32The specified node.

Return Values

NameTypeDescription
[0]boolBool if record exists

getSubnodeHash

function getSubnodeHash(bytes32 _node, bytes32 _nameHash) external pure returns (bytes32)

Returns the subnode hash of node + nameHash. This is the keccak256 hash of node + nameHash.

Parameters

NameTypeDescription
_nodebytes32The specified node.
_nameHashbytes32The specified nameHash.

_calculateSubnode

function _calculateSubnode(bytes32 _node, bytes32 _nameHash) internal pure returns (bytes32)

_setOwner

function _setOwner(bytes32 node, address owner) internal virtual

_setResolver

function _setResolver(bytes32 _node, address _resolver) internal virtual