Chromia
Start Building

03 / 07Advanced

Define messages

Here is the sequence of events when someone orders a product through the system:

  1. The user places an order, and its details go to the Order Chain (OC).
  2. The OC passes the production requirements on to the Factory Chain (FC).
  3. The OC also sends the delivery details to the Delivery Chain (DC).
  4. The factory produces the ordered items.
  5. Delivery gets ready to ship the items as soon as they are finished.
  6. The FC tells the DC that the order is ready to ship.
  7. Delivery brings the order to the user. This step happens off-chain.
  8. The user confirms that the delivery arrived.

To represent this flow in Rell, you define three topics, one per message passed between the chains, along with the payload each message carries. In the src directory, create a file named messages.rell and add this code:

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;    }}
Written for this site from Chromia’s public course. Code samples are the course’s own.