CrosschainLink
Inherits: IERC7786Recipient, ICrosschainLink
Title: CrosschainLink
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Adapted for EIP-2535 from OpenZeppelin CrosschainLinked + ERC7786Recipient v5.6.1 (https://github.com/OpenZeppelin/openzeppelin-contracts)
Diamond facet that owns the single ERC-7786 receiveMessage selector. It authenticates the
calling gateway + source against a per-chain link registry, de-duplicates receiveId, and
routes the message to a handler registered for the payload's leading 4-byte tag. Also exposes
the send path (sendMessage) to a registered counterpart.
Stateless delegator — all logic and storage live in CrosschainLinkLib. Consumers inherit this
facet and add AccessControl + an initializer that calls CrosschainLinkLib.__CrosschainLink_init.
Notes:
- lattice-version: 0.1.0
- lattice-source: OpenZeppelin
Functions
receiveMessage
This function may be called directly by the gateway.
Endpoint for receiving cross-chain message.
function receiveMessage(bytes32 receiveId, bytes calldata sender, bytes calldata payload)
external
payable
virtual
override
returns (bytes4);Parameters
| Name | Type | Description |
|---|---|---|
| receiveId | bytes32 | |
| sender | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes4 |
getLink
Returns the gateway and counterpart registered for a source chain.
function getLink(bytes calldata chain)
external
view
virtual
override
returns (address gateway, bytes memory counterpart);Parameters
| Name | Type | Description |
|---|---|---|
| chain | bytes | A "chain-only" ERC-7930 interoperable address (empty address). |
Returns
| Name | Type | Description |
|---|---|---|
| gateway | address | The ERC-7786 gateway trusted for chain. |
| counterpart | bytes | The full interoperable address authorized to send from chain. |
getHandler
Returns the handler registered for a message tag (zero if none).
function getHandler(bytes4 tag) external view virtual override returns (address handler);Parameters
| Name | Type | Description |
|---|---|---|
| tag | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| handler | address |
isProcessed
Returns whether a receiveId from gateway has already been processed (keyed per-gateway,
as ERC-7786 only guarantees receiveId uniqueness for the calling gateway).
function isProcessed(address gateway, bytes32 receiveId) external view virtual override returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| gateway | address | |
| receiveId | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
setLink
Registers (or overrides) the gateway + counterpart for the counterpart's source chain.
Caller must hold DEFAULT_ADMIN_ROLE. Reverts CrosschainLinkAlreadyRegistered if a link
exists and allowOverride is false.
function setLink(address gateway, bytes calldata counterpart, bool allowOverride) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| gateway | address | The ERC-7786 gateway for this chain (must implement supportsAttribute). |
| counterpart | bytes | The full interoperable address of the remote counterpart. |
| allowOverride | bool | Whether to overwrite an existing link for the chain. |
setHandler
Registers a handler for inbound messages whose payload starts with tag (zero to clear).
Caller must hold DEFAULT_ADMIN_ROLE.
function setHandler(bytes4 tag, address handler) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| tag | bytes4 | |
| handler | address |
sendMessage
Sends a message to the counterpart registered for chain via its ERC-7786 gateway.
Caller must hold DEFAULT_ADMIN_ROLE.
function sendMessage(bytes calldata chain, bytes calldata payload, bytes[] calldata attributes)
external
virtual
override
returns (bytes32 sendId);Parameters
| Name | Type | Description |
|---|---|---|
| chain | bytes | A "chain-only" interoperable address selecting the destination link. |
| payload | bytes | The message payload (handlers expect a leading 4-byte tag on the receiving side). |
| attributes | bytes[] | ERC-7786 gateway attributes (may be empty). |
Returns
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 | The gateway-assigned send id (zero if no further processing is needed). |
exportSelectors
ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).
Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches
forge inspect CrosschainLink methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
getHandler(bytes4) 0x6dd99bde
getLink(bytes) 0x09b0b794
isProcessed(address,bytes32) 0xffe32a6e
receiveMessage(bytes32,bytes,bytes) 0x2432ef26
sendMessage(bytes,bytes,bytes[]) 0xcdfe7f5c
setHandler(bytes4,address) 0x42b26650
setLink(address,bytes,bool) 0xf54640d0
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |