Orders and Actions

June 26, 2026 · View on GitHub

Summary of order lifecycle and key handlers.

Core Types

  • Messages/Actions: mostro_core::message::{Message, Action}
  • Orders: mostro_core::order::Order persisted via mostro_core::db::Crud.

Handlers (entries)

  • New Order: src/app/order.rs
  • Take Buy: src/app/take_buy.rs:11
  • Take Sell: src/app/take_sell.rs
  • Add Invoice: src/app/add_invoice.rs:21
  • Fiat Sent: src/app/fiat_sent.rs
  • Release: src/app/release.rs:94
  • Cancel: src/app/cancel.rs
  • Dispute: src/app/dispute.rs
  • Rate User: src/app/rate_user.rs
  • Orders List: src/app/orders.rs
  • Trade Pubkey: src/app/trade_pubkey.rs
  • Restore Session: src/app/restore_session.rs

Action → Handler Map

ActionHandler FileResponsibility
new-orderhttps://github.com/MostroP2P/mostro/blob/main/src/app/order.rsValidate and create a new order; emit listing event
take-buyhttps://github.com/MostroP2P/mostro/blob/main/src/app/take_buy.rs#L12Taker accepts sell; validate status, set amounts, reserve
take-sellhttps://github.com/MostroP2P/mostro/blob/main/src/app/take_sell.rsTaker accepts buy; mirror of take-buy for sell side
add-invoicehttps://github.com/MostroP2P/mostro/blob/main/src/app/add_invoice.rs#L34Store buyer invoice or create hold invoice; notify parties
fiat-senthttps://github.com/MostroP2P/mostro/blob/main/src/app/fiat_sent.rsBuyer signals fiat transfer; move to FiatSent
releasehttps://github.com/MostroP2P/mostro/blob/main/src/app/release.rs#L160Seller releases; settle hold invoice and finalize
cancelhttps://github.com/MostroP2P/mostro/blob/main/src/app/cancel.rs#L319Cancel pending order; cancel hold if present
disputehttps://github.com/MostroP2P/mostro/blob/main/src/app/dispute.rs#L141Open dispute and notify admin/solver
rate-userhttps://github.com/MostroP2P/mostro/blob/main/src/app/rate_user.rsRecord post-trade reputation update
ordershttps://github.com/MostroP2P/mostro/blob/main/src/app/orders.rsReturn order lists/history to requester
trade-pubkeyhttps://github.com/MostroP2P/mostro/blob/main/src/app/trade_pubkey.rsExchange or update per-trade pubkeys
restore-sessionhttps://github.com/MostroP2P/mostro/blob/main/src/app/restore_session.rsRehydrate client session and state
admin-cancelhttps://github.com/MostroP2P/mostro/blob/main/src/app/admin_cancel.rsAdmin cancel; optionally cancel hold invoice. Assigned solver must have read-write permission
admin-settlehttps://github.com/MostroP2P/mostro/blob/main/src/app/admin_settle.rsAdmin settlement; settle/cancel holds, finalize. Assigned solver must have read-write permission
admin-add-solverhttps://github.com/MostroP2P/mostro/blob/main/src/app/admin_add_solver.rsRegister dispute solver key. admin-add-solver accepts a bare pubkey (defaults to read-write), pubkey:read, pubkey:write (alias for read-write), or pubkey:read-write; see the parser in admin_add_solver.rs for the accepted forms
admin-take-disputehttps://github.com/MostroP2P/mostro/blob/main/src/app/admin_take_dispute.rsAssign or take ownership of dispute
last-trade-indexhttps://github.com/MostroP2P/mostro/blob/main/src/app/last_trade_index.rsRetrieve user's last trade index from database

Typical Flow

  1. Maker posts New Order (GiftWrap message).
  2. Taker executes Take Buy/Sell; DB validates and reserves.
  3. Buyer Add Invoice; Mostro creates hold invoice if needed.
  4. Buyer Fiat Sent; seller later Release.
  5. Mostro settles hold invoice, pays buyer (minus fees), and requests ratings.

Error Handling

  • MostroError::MostroCantDo(CantDoReason) → user notifications (invalid peer, status, amount, signature, trade index).
  • MostroError::MostroInternalErr(ServiceError) → logged; may generate “can’t do” fallback.

Diagram

sequenceDiagram
  participant Maker
  participant Taker
  participant Mostro
  participant DB
  participant LND

  Maker->>Mostro: NewOrder
  Taker->>Mostro: TakeBuy/TakeSell
  Mostro->>DB: validate + reserve
  Taker->>Mostro: AddInvoice
  Mostro->>LND: create_hold_invoice
  Taker->>Mostro: FiatSent
  Maker->>Mostro: Release
  Mostro->>LND: settle_hold_invoice
  Mostro->>DB: finalize