Example contracts
Every node runs Mandala's standard library. Read these in the source repository under contracts/, or in Data, where each shows its fields, queries and actions.
Personal (std.personal)
| Contract | Teaches |
|---|---|
std.personal.shopping_list | A small record with owner and writer, commutes and last_writer merges, a paged query |
std.personal.shopping_item | Additions as their own records, so concurrent adds never collide |
std.personal.finance_transaction, finance_account, finance_budget | Money in minor units; owner, writer and delegation |
std.personal.health_measurement | Records written by an importer (Apple Health), one per metric per day |
std.personal.appointment, health_medication, home_asset, home_maintenance, travel_trip, travel_booking | The same pattern for the rest of life |
Business (std.business)
std.business.payable is the best single example: a workflow from received to reviewed, approved and paid (or rejected), each step checking the previous status, recording who took it, and checking a delegation for the organisation. Approve and Pay are exclusive, so two devices cannot both pay one invoice. Its Upgrade action shows a signed upgrade from version 1.0.0.
action Pay(owner: Identity, writer: Identity, payment_reference: Text(len=200), delegation: SubjectRef<Delegation>, delegation_scope: Text(len=200), delegation_ends_ms: Int)
api authenticated
authorize dhl
observe delegation where active == true
observe delegation where party == arg.owner
observe delegation where delegate == arg.writer
observe delegation where scope == arg.delegation_scope
observe delegation where ends_ms == arg.delegation_ends_ms
validate
state.revision > 0
state.status == "approved"
context.signer == writer
delegation_scope == "*" or delegation_scope == "std.business.payable" or delegation_scope == "std.business.payable.Pay"
delegation_ends_ms == 0 or delegation_ends_ms > context.clock.milliseconds
owner == state.owner
payment_reference.len > 0
apply
state.delegation = delegation
state.status = "paid"
state.paid_by = writer
state.payment_reference = payment_reference
state.revision = state.revision + 1
Identity and exchange
| Contract | Teaches |
|---|---|
std.identity.identity, ownership, membership, delegation, device, root | Records each signed by the key the contract requires |
std.exchange.relationship, std.exchange.document | Trust kept as your own records; signed documents routed or held |
Commerce (com.cmdv.btd)
A real online grocery's rules, in the repository: carts and cart lines, orders and order lines, stock lots, ordering calendars and sourcing.
| Contract | Teaches |
|---|---|
cart.dhl | requires to open child lines atomically; external datasets bounding a cart to 16 lines |
order.dhl | requires … for entry in entries: one checkout touching every line, all or nothing |
order_line.dhl | A line reserving stock from a lot through requires |
cart_line.dhl | agg totals over child records |
order.ui.md, product.ui.md | UI files: statuses, money, links, a two-step form, every rule explained |