Skip to content

Event System [legacy]

Matteo Ferretti edited this page Apr 10, 2024 · 1 revision

This document describes the Event System used in Rusk.

Event Target

enum Target {
    Contract(String), // 0x01
    Host(String).     // 0x02
    Debugger(String)  // 0x03
}

Event

struct Event<T> {
    data: T,
    target: Target,
    topic: &'static str.
}

Event's serialization

Field Type Description
target's type u8 The target's type
target's name length u32 little endian
target's name [u8] bytes represent the name of the target in utf-8
event's topic length u32 little endian
event's topic [u8] bytes represent the topic of the target in utf-8
data [u8] bytes represent the data of this event

Message

A message is sent from a consumer (e.g. wallets) to Rusk or from Rusk to a consumer. It contains the Event to dispatch plus Headers HTTP-like with additional information.

struct Message {
    headers: HashMap<String, String>,
    event: Event
}

Message's serialization

Field Type Description
headers' length u32 The length of the headers
headers [u8] bytes represent the headers of the request in JSON format
event [u8] See event's serialization

Headers

The headers are key / value struct, { String : String }.

  1. The key is case-insensitive
  2. The prefix Rusk- for the header name is reserved
  3. Any header starting with the prefix X- will be included back as-is from a request to a response.
  4. Any header not recognized by Rusk without the prefix X- will be ignored from a request and not included in the response.

List of header fields

Field Description
Content-Type Content-Type
Content-Length The length of the message body in octets (8-bit bytes).
Accept Media type(s) that is/are acceptable for a response message
Rusk-Version The required version for the rusk node to connect with, expressed in semver
Status Status code and optional text expressed as HTTP status code, e.g. "200; Good news everyone!"

Examples

{ 
    "Content-Type" : "application/json",
    "Rusk-Version" : "0.10.2",
    "X-Request-Id" : "12be34ef"
}