summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-08 03:36:26 +0100
committersalmonik <salmonik@tuta.io>2026-11-08 03:36:26 +0100
commitc6c8ddb7e4117628549afdb382b0d46f830f242d (patch)
treecd59ac8bf690c942bce3b226f5777d01fde4896b /src/client
parentweb: restore the balance on a refresh into history (diff)
downloadzagan-bet-c6c8ddb7e4117628549afdb382b0d46f830f242d.tar.gz
zagan-bet-c6c8ddb7e4117628549afdb382b0d46f830f242d.zip
crash: show and verify the revealed seed in the TUI and GUI
The crash board gained a fairness line: the short commit while the round runs, then the short seed marked verified when sha256(seed) and the recomputed crash point both match. The terminal board grew from six to seven lines and the GUI sidebar shows the same values.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/games/crash.rs45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/client/games/crash.rs b/src/client/games/crash.rs
index affb642..c6dbbd5 100644
--- a/src/client/games/crash.rs
+++ b/src/client/games/crash.rs
@@ -1,7 +1,8 @@
1use super::traits::{Game, GameState}; 1use super::traits::{Game, GameState};
2use crate::client::view::CrashView; 2use crate::client::view::CrashView;
3use crate::crash::{crash_point_from_seed, seed_from_hex, verify_seed};
3 4
4pub const CRASH_BOARD_LINES: usize = 6; 5pub const CRASH_BOARD_LINES: usize = 7;
5 6
6pub struct CrashGame; 7pub struct CrashGame;
7 8
@@ -29,6 +30,38 @@ impl CrashGame {
29 } 30 }
30 } 31 }
31 32
33 /// Commitment line. The seed is shown only after the round ends, and the
34 /// client recomputes both the hash and the crash point.
35 fn fairness_text(view: &CrashView) -> String {
36 let short = |hash: &str| {
37 hash.char_indices()
38 .nth(12)
39 .map(|(index, _)| &hash[..index])
40 .unwrap_or(hash)
41 .to_string()
42 };
43 let Some(commit) = view.commit.as_deref() else {
44 return "Commit: —".to_string();
45 };
46 let Some(seed) = view.seed.as_deref() else {
47 return format!("Commit {} Seed hidden until the round ends", short(commit));
48 };
49 let commit_ok = verify_seed(seed, commit);
50 let point_ok = seed_from_hex(seed)
51 .map(|bytes| {
52 let expected = crash_point_from_seed(&bytes);
53 view.crash_point
54 .map(|point| (expected - point).abs() < 1e-9)
55 .unwrap_or(false)
56 })
57 .unwrap_or(false);
58 if commit_ok && point_ok {
59 format!("Commit {} Seed {} verified", short(commit), short(seed))
60 } else {
61 format!("Commit {} Seed {} VERIFICATION FAILED", short(commit), short(seed))
62 }
63 }
64
32 fn controls(view: &CrashView) -> &'static str { 65 fn controls(view: &CrashView) -> &'static str {
33 if view.status == "running" { 66 if view.status == "running" {
34 "[C] Cash out [Q] Forfeit" 67 "[C] Cash out [Q] Forfeit"
@@ -46,19 +79,21 @@ impl CrashGame {
46 79
47 if let Some(error) = &view.error { 80 if let Some(error) = &view.error {
48 return format!( 81 return format!(
49 "=== CRASH ===\r\nBalance: {balance} Kr Bet: {} Kr\r\n\r\nERROR: {error}\r\n\r\n[SPACE] Play [+/=/-] Bet [Q] Quit", 82 "=== CRASH ===\r\nBalance: {balance} Kr Bet: {} Kr\r\n\r\nERROR: {error}\r\n\r\n{}\r\n[SPACE] Play [+/=/-] Bet [Q] Quit",
50 view.bet 83 view.bet,
84 Self::fairness_text(view)
51 ); 85 );
52 } 86 }
53 87
54 format!( 88 format!(
55 "=== CRASH ===\r\nBalance: {} Kr Bet: {} Kr\r\nMultiplier: {:.2}x\r\nPotential: {} Kr\r\n{}\r\n{}", 89 "=== CRASH ===\r\nBalance: {} Kr Bet: {} Kr\r\nMultiplier: {:.2}x\r\nPotential: {} Kr\r\n{}\r\n{}\r\n{}",
56 balance, 90 balance,
57 view.bet, 91 view.bet,
58 view.multiplier, 92 view.multiplier,
59 view.potential, 93 view.potential,
60 Self::status_text(view), 94 Self::status_text(view),
61 Self::controls(view) 95 Self::controls(view),
96 Self::fairness_text(view)
62 ) 97 )
63 } 98 }
64} 99}