From 3b50928cb083b104043ac65433ed090c87731eb7 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 17:02:49 +0100 Subject: v2.0.0: reset plays audit to a generic per-game schema --- src/server/database.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/server/database.rs') diff --git a/src/server/database.rs b/src/server/database.rs index f6c8872..2a1fc40 100644 --- a/src/server/database.rs +++ b/src/server/database.rs @@ -24,9 +24,8 @@ pub fn init_db(conn: &Connection) { game_type TEXT NOT NULL, bet_amount INTEGER NOT NULL, winnings INTEGER NOT NULL, - reels TEXT NOT NULL DEFAULT '', - win_type TEXT NOT NULL DEFAULT '', balance_after INTEGER NOT NULL, + details TEXT NOT NULL DEFAULT '{}', created_at DATETIME DEFAULT CURRENT_TIMESTAMP )", [], @@ -111,20 +110,22 @@ pub fn get_balance(conn: &Connection, username: &str) -> Option { } } -/// Settle one spin and record its audit row in a single transaction. +/// Settle one play and record its audit row in a single transaction. /// -/// Returns the balance after the spin. All SQL is parameterized: usernames -/// are data, never part of the statement text. +/// `details` is a JSON object with game-specific fields (reels, cards, +/// winning number, crash point, ...). All SQL is parameterized: usernames are +/// data, never part of the statement text. +/// +/// Returns the balance after the play. #[allow(clippy::too_many_arguments)] -pub fn apply_spin( +pub fn apply_play( conn: &mut Connection, session_id: &str, username: &str, game_type: &str, bet_amount: i64, winnings: i64, - reels: &str, - win_type: &str, + details: &str, ) -> rusqlite::Result { let tx = conn.transaction()?; @@ -150,18 +151,17 @@ pub fn apply_spin( tx.execute( "INSERT INTO plays - (session_id, username, game_type, bet_amount, winnings, reels, - win_type, balance_after) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", + (session_id, username, game_type, bet_amount, winnings, + balance_after, details) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", params![ session_id, username, game_type, bet_amount, winnings, - reels, - win_type, - balance_after + balance_after, + details ], )?; -- cgit v1.2.3