Example of Message Listener Service (Rust)

After integrating the message contract, both sending messages and chain confirmation messages will generate events. You need to listen to these events to complete the subsequent business logic.

  1. Structure of the message payload:

struct Message {
    MessageHeader msg_header; // Message Header
    bytes msg_body; // Message Content
}

struct MessageHeader {
    uint8 msg_type; // 0 means bridge message
    uint64 nonce; // Message nonce, used to prevent replay attacks.
    Chain from_chain; // Chain from which the message is sent
    bytes32 sender; // Sender contract address
    Chain to_chain; // Chain to which the message is sent
    bytes32 receiver; // Receiver contract address
    uint128 upload_gas_fee; // Gas fee for uploading the message
}
  1. Structure of the execution message payload:

struct ConfirmMsg(

address executor;// Executor address
Chain from_chain;// Chain from which the message was sent
uint64 nonce;// Message nonce (to prevent replay)
bytes mbody; // Message body (content)
)
  1. Rust Implementation of Block Scanning Logic and On-Chain Event Handling — EVM Chain Listening:

  1. Rust Implementation of Block Scanning Logic and On-Chain Event Handling — Endless Chain Listening:

\

Last updated