NodeRegistry
Inherits: INodeRegistry, Migratable, ERC721Upgradeable
This contract is responsible for minting NFTs and assigning them to node owners. Each node is minted as an NFT with a unique ID (starting at 100 and increasing by 100 with each new node). In addition to the standard ERC721 functionality, the contract supports node-specific features, including node property updates.
All nodes on the network periodically check this contract to determine which nodes they should connect to.
State Variables
NODE_INCREMENT
The increment for node IDs, which allows for 100 shard node IDs per node in the future (modulus 100).
uint32 public constant NODE_INCREMENT = 100;
_FORWARD_SLASH
bytes1 internal constant _FORWARD_SLASH = 0x2f;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_NODE_REGISTRY_STORAGE_LOCATION
bytes32 internal constant _NODE_REGISTRY_STORAGE_LOCATION =
0xd48713bc7b5e2644bcb4e26ace7d67dc9027725a9a1ee11596536cc6096a2000;
Functions
_getNodeRegistryStorage
function _getNodeRegistryStorage() internal pure returns (NodeRegistryStorage storage $);
onlyAdmin
modifier onlyAdmin();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry must not be the zero address.
The parameter registry is immutable so that it is inlined in the contract code, and has minimal gas cost.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() public initializer;
addNode
Adds a new node to the registry and mints its corresponding ERC721 token.
Node IDs start at 100 and increase by 100 for each new node.
function addNode(address owner_, bytes calldata signingPublicKey_, string calldata httpAddress_)
external
onlyAdmin
returns (uint32 nodeId_, address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The address that will own the new node node/NFT. |
signingPublicKey_ | bytes | The public key used for node signing/verification. |
httpAddress_ | string | The node’s HTTP address. |
Returns
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the newly added node. |
signer_ | address | The address derived by the signing public key, for convenience. |
addToNetwork
Adds a node to the canonical network.
function addToNetwork(uint32 nodeId_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
removeFromNetwork
Removes a node from the canonical network.
function removeFromNetwork(uint32 nodeId_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
setBaseURI
Set the base URI for the node NFTs.
function setBaseURI(string calldata baseURI_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
baseURI_ | string | The new base URI. Has to end with a trailing slash. |
setHttpAddress
Set the HTTP address of an existing node.
function setHttpAddress(uint32 nodeId_, string calldata httpAddress_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
httpAddress_ | string | The new HTTP address. |
updateAdmin
Updates the admin by referring to the admin parameter from the parameter registry.
function updateAdmin() external;
updateMaxCanonicalNodes
Updates the max canonical nodes by referring to the max canonical nodes parameter from the parameter registry.
function updateMaxCanonicalNodes() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
admin
The address of the admin.
function admin() external view returns (address admin_);
adminParameterKey
The parameter registry key used to fetch the admin.
function adminParameterKey() public pure returns (string memory key_);
maxCanonicalNodesParameterKey
The parameter registry key used to fetch the max canonical nodes.
function maxCanonicalNodesParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
maxCanonicalNodes
The maximum number of nodes that can be part of the canonical network.
function maxCanonicalNodes() external view returns (uint8 maxCanonicalNodes_);
canonicalNodesCount
The number of nodes that are part of the canonical network.
function canonicalNodesCount() external view returns (uint8 canonicalNodesCount_);
getAllNodes
Gets all nodes regardless of their health status.
function getAllNodes() external view returns (NodeWithId[] memory allNodes_);
Returns
| Name | Type | Description |
|---|---|---|
allNodes_ | NodeWithId[] | An array of all nodes in the registry. |
getAllNodesCount
Gets the total number of nodes in the registry.
function getAllNodesCount() external view returns (uint32 nodeCount_);
Returns
| Name | Type | Description |
|---|---|---|
nodeCount_ | uint32 | The total number of nodes. |
getCanonicalNodes
Gets all canonical nodes IDs.
function getCanonicalNodes() external view returns (uint32[] memory canonicalNodes_);
Returns
| Name | Type | Description |
|---|---|---|
canonicalNodes_ | uint32[] | An array of all canonical nodes. |
getNode
Retrieves the details of a given node.
function getNode(uint32 nodeId_) external view returns (Node memory node_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
node_ | Node | The Node struct containing the node's details. |
getIsCanonicalNode
Retrieves whether a node is part of the canonical network.
function getIsCanonicalNode(uint32 nodeId_) external view returns (bool isCanonicalNode_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
isCanonicalNode_ | bool | A boolean indicating whether the node is part of the canonical network. |
getSigner
Retrieves the signer of a node.
function getSigner(uint32 nodeId_) external view returns (address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
signer_ | address | The address of the signer. |
version
Returns semver version string
function version() external pure returns (string memory version_);
Returns
| Name | Type | Description |
|---|---|---|
version_ | string | The semver version string |
contractName
Returns contract name
function contractName() external pure returns (string memory contractName_);
Returns
| Name | Type | Description |
|---|---|---|
contractName_ | string | The contract name |
_baseURI
function _baseURI() internal view override returns (string memory baseURI_);
_getSignerFromPublicKey
Returns the signer address from a public key.
Validates uncompressed public key format: 0x04 + 32 bytes X + 32 bytes Y = 65 bytes total
function _getSignerFromPublicKey(bytes calldata publicKey_) internal pure returns (address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
publicKey_ | bytes | The public key. |
Returns
| Name | Type | Description |
|---|---|---|
signer_ | address | The signer address. |
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfNotAdmin
function _revertIfNotAdmin() internal view;
_revertIfNotNodeOwner
function _revertIfNotNodeOwner(uint32 nodeId_) internal view;
Structs
NodeRegistryStorage
The UUPS storage for the node registry.
Note: storage-location: erc7201:xmtp.storage.NodeRegistry
struct NodeRegistryStorage {
address admin;
uint8 maxCanonicalNodes;
uint8 canonicalNodesCount;
uint32 nodeCount;
mapping(uint32 tokenId => Node node) nodes;
string baseURI;
EnumerableSet.UintSet canonicalNodes;
}
Properties
| Name | Type | Description |
|---|---|---|
admin | address | The admin address. |
maxCanonicalNodes | uint8 | The maximum number of canonical nodes. |
canonicalNodesCount | uint8 | Not used, use canonicalNodes.length() instead. |
nodeCount | uint32 | The current number of nodes. |
nodes | mapping(uint32 tokenId => Node node) | A mapping of node/token IDs to nodes. |
baseURI | string | The base component of the token URI. |
canonicalNodes | EnumerableSet.UintSet | A set of the canonical node IDs. |