Port the simulator to a Rust workspace and document each crate

This commit is contained in:
2026-12-03 02:53:46 +08:00
parent b7579603f9
commit 2f3c699e9c
25 changed files with 1320 additions and 371 deletions
+22
View File
@@ -0,0 +1,22 @@
use anyhow::{ensure, Result};
use rusqlite::Transaction;
pub(crate) fn identifier(id: &str) -> Result<()> {
ensure!(
!id.trim().is_empty() && id.trim().chars().count() <= 256,
"invalid identifier"
);
Ok(())
}
pub(crate) fn amount(n: i64) -> Result<()> {
ensure!((1..=1_000_000_000).contains(&n), "invalid amount");
Ok(())
}
pub(crate) fn phase(tx: &Transaction, market: &str, allowed: &[&str]) -> Result<String> {
identifier(market)?;
let p: String = tx.query_row("SELECT phase FROM markets WHERE id=?", [market], |r| {
r.get(0)
})?;
ensure!(allowed.contains(&p.as_str()), "wrong market phase");
Ok(p)
}