Publish settlement clarifications and atomically clear affected orders

This commit is contained in:
2026-12-03 10:42:35 +08:00
parent fe69e31929
commit 3495e8de3c
12 changed files with 319 additions and 3 deletions
+13 -2
View File
@@ -109,6 +109,11 @@ pub(crate) fn apply(
}
Ok(result)
}
Command::PublishClarification {
market,
content,
clear_book,
} => crate::clarifications::publish(tx, &market, &content, clear_book),
Command::Clarify {
market,
name,
@@ -381,17 +386,23 @@ pub(crate) fn apply(
pub(crate) fn close_market(tx: &Transaction, market: &str) -> Result<()> {
phase(tx, market, &["preopen", "continuous"])?;
clear_orders(tx, market)?;
tx.execute("UPDATE markets SET phase='closed' WHERE id=?", [market])?;
Ok(())
}
pub(crate) fn clear_orders(tx: &Transaction, market: &str) -> Result<usize> {
let mut stmt = tx.prepare("SELECT seq,account FROM orders WHERE market=? AND status='live'")?;
let orders = stmt
.query_map([market], |r| {
Ok((r.get::<_, i64>(0)?, r.get::<_, String>(1)?))
})?
.collect::<rusqlite::Result<Vec<_>>>()?;
let count = orders.len();
for (seq, account) in orders {
book::release(tx, seq, &account, book::CancelReason::Cancelled)?;
}
tx.execute("UPDATE markets SET phase='closed' WHERE id=?", [market])?;
Ok(())
Ok(count)
}
pub(crate) fn finalize(tx: &Transaction, market: &str, winner: &str) -> Result<i64> {