Port the simulator to a Rust workspace and document each crate
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user