Skip to main content

Define messages

Consider the following steps involved when ordering a product through our system:

  1. The user creates an order and sends the details to the Order Chain (OC).
  2. OC forwards the production requirements to the Factory Chain (FC).
  3. OC also communicates the delivery details to the Delivery Chain (DC).
  4. The factory manufactures the ordered products.
  5. Delivery prepares to deliver the products once ready.
  6. FC notifies DC that the order is prepared for shipping.
  7. Delivery completes the delivery of the order to the user (off-chain).
  8. The user confirms receipt of the delivery.

Let's model this in Rell by defining three topics, one for each message we want to send between the chains and the content for each message. Create a new file called messages.rell in the src directory and add the following code to it:

src/messages.rell
module;

namespace topic {
val PRODUCTION_ORDER = "L_production";
val NEW_DELIVERY = "L_delivery";
val SHIPMENT_READY = "L_shipment_ready";
}

namespace msg {
struct order_details {
customer_id: integer;
address: text;
products: list<product>;
}

struct product {
id: integer;
quantity: integer;
}

// Order -> Factory
struct production_details {
order_id: integer;
products: list<product>;
}

// Order -> Delivery
struct delivery_details {
order_id: integer;
shipping_address: text;
customer_id: integer;
}

// Factory -> Delivery
struct shipment_ready {
order_id: integer;
}
}
The prefix L_ is essential for ICMF, restricting message access to the sender's cluster. System blockchains

alone have the privilege to send global messages, denoted by the G_ prefix. :::