BaseMessageLib
BaseMessage structure represents a base message sent via the Origin-Destination contracts.
- It only contains data relevant to the base message, the rest of data is encoded in the message header.
sender
andrecipient
for EVM chains are EVM addresses casted to bytes32, while preserving left-alignment.tips
andrequest
parameters are specified by a message sender
Origin will calculate minimum tips for given request and content length, and will reject messages with tips lower than that.
Memory layout of BaseMessage fields
Position | Field | Type | Bytes | Description |
---|---|---|---|---|
[000..032) | tips | uint256 | 32 | Encoded tips paid on origin chain |
[032..064) | sender | bytes32 | 32 | Sender address on origin chain |
[064..096) | recipient | bytes32 | 32 | Recipient address on destination chain |
[096..116) | request | uint160 | 20 | Encoded request for message execution |
[104..AAA) | content | bytes | ?? | Content to be passed to recipient |
State Variables
OFFSET_TIPS
The variables below are not supposed to be used outside of the library directly.
uint256 private constant OFFSET_TIPS = 0;
OFFSET_SENDER
uint256 private constant OFFSET_SENDER = 32;
OFFSET_RECIPIENT
uint256 private constant OFFSET_RECIPIENT = 64;
OFFSET_REQUEST
uint256 private constant OFFSET_REQUEST = OFFSET_RECIPIENT + TIPS_LENGTH;
OFFSET_CONTENT
uint256 private constant OFFSET_CONTENT = OFFSET_REQUEST + REQUEST_LENGTH;
Functions
formatBaseMessage
Returns a formatted BaseMessage payload with provided fields.
function formatBaseMessage(Tips tips_, bytes32 sender_, bytes32 recipient_, Request request_, bytes memory content_)
internal
pure
returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tips_ | Tips | Encoded tips information |
sender_ | bytes32 | Sender address on origin chain |
recipient_ | bytes32 | Recipient address on destination chain |
request_ | Request | Encoded request for message execution |
content_ | bytes | Raw content to be passed to recipient on destination chain |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Formatted base message |
castToBaseMessage
Returns a BaseMessage view over the given payload.
Will revert if the payload is not a base message.
function castToBaseMessage(bytes memory payload) internal pure returns (BaseMessage);
castToBaseMessage
Casts a memory view to a BaseMessage view.
Will revert if the memory view is not over a base message payload.
function castToBaseMessage(MemView memView) internal pure returns (BaseMessage);
isBaseMessage
Checks that a payload is a formatted BaseMessage.
function isBaseMessage(MemView memView) internal pure returns (bool);
unwrap
Convenience shortcut for unwrapping a view.
function unwrap(BaseMessage baseMessage) internal pure returns (MemView);
leaf
Returns baseMessage's hash: a leaf to be inserted in the "Message mini-Merkle tree".
function leaf(BaseMessage baseMessage) internal pure returns (bytes32);
bodyLeaf
Returns hash for the "everything but tips" part of the base message.
function bodyLeaf(BaseMessage baseMessage) internal pure returns (bytes32);
tips
Returns encoded tips paid on origin chain.
function tips(BaseMessage baseMessage) internal pure returns (Tips);
sender
Returns sender address on origin chain.
function sender(BaseMessage baseMessage) internal pure returns (bytes32);
recipient
Returns recipient address on destination chain.
function recipient(BaseMessage baseMessage) internal pure returns (bytes32);
request
Returns an encoded request for message execution on destination chain.
function request(BaseMessage baseMessage) internal pure returns (Request);
content
Returns an untyped memory view over the content to be passed to recipient.
function content(BaseMessage baseMessage) internal pure returns (MemView);