diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-08 03:36:26 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-08 03:36:26 +0100 |
| commit | c6c8ddb7e4117628549afdb382b0d46f830f242d (patch) | |
| tree | cd59ac8bf690c942bce3b226f5777d01fde4896b /gui | |
| parent | web: restore the balance on a refresh into history (diff) | |
| download | zagan-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 'gui')
| -rw-r--r-- | gui/src/crash.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gui/src/crash.rs b/gui/src/crash.rs index 08113a8..a73c3bd 100644 --- a/gui/src/crash.rs +++ b/gui/src/crash.rs | |||
| @@ -2,9 +2,18 @@ | |||
| 2 | 2 | ||
| 3 | use eframe::egui::{Align2, Color32, Pos2, Rect, Sense, Shape, Stroke, StrokeKind, Ui, pos2, vec2}; | 3 | use eframe::egui::{Align2, Color32, Pos2, Rect, Sense, Shape, Stroke, StrokeKind, Ui, pos2, vec2}; |
| 4 | use zagan_bet::client::view::{Command, CrashView}; | 4 | use zagan_bet::client::view::{Command, CrashView}; |
| 5 | use zagan_bet::crash::{crash_point_from_seed, seed_from_hex, verify_seed}; | ||
| 5 | 6 | ||
| 6 | use crate::{theme, widgets}; | 7 | use crate::{theme, widgets}; |
| 7 | 8 | ||
| 9 | fn short_hash(hash: &str) -> String { | ||
| 10 | hash.char_indices() | ||
| 11 | .nth(12) | ||
| 12 | .map(|(index, _)| &hash[..index]) | ||
| 13 | .unwrap_or(hash) | ||
| 14 | .to_string() | ||
| 15 | } | ||
| 16 | |||
| 8 | /// One sample of the running curve. | 17 | /// One sample of the running curve. |
| 9 | struct Sample { | 18 | struct Sample { |
| 10 | seconds: f32, | 19 | seconds: f32, |
| @@ -136,6 +145,31 @@ fn sidebar(ui: &mut Ui, view: &CrashView, fx: &mut Fx) -> Option<Command> { | |||
| 136 | theme::GOLD, | 145 | theme::GOLD, |
| 137 | ); | 146 | ); |
| 138 | 147 | ||
| 148 | if let Some(commit) = &view.commit { | ||
| 149 | widgets::row(ui, "Commit", &short_hash(commit), theme::TEXT_FAINT); | ||
| 150 | } | ||
| 151 | if let Some(seed) = &view.seed { | ||
| 152 | let commit_ok = view | ||
| 153 | .commit | ||
| 154 | .as_deref() | ||
| 155 | .map(|commit| verify_seed(seed, commit)) | ||
| 156 | .unwrap_or(false); | ||
| 157 | let point_ok = seed_from_hex(seed) | ||
| 158 | .map(|bytes| { | ||
| 159 | view.crash_point | ||
| 160 | .map(|point| { | ||
| 161 | (crash_point_from_seed(&bytes) - point).abs() < 1e-9 | ||
| 162 | }) | ||
| 163 | .unwrap_or(false) | ||
| 164 | }) | ||
| 165 | .unwrap_or(false); | ||
| 166 | if commit_ok && point_ok { | ||
| 167 | widgets::row(ui, "Seed ✓", &short_hash(seed), theme::WIN); | ||
| 168 | } else { | ||
| 169 | widgets::row(ui, "Seed ✗", &short_hash(seed), theme::LOSS); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 139 | ui.add_space(theme::SPACE_3); | 173 | ui.add_space(theme::SPACE_3); |
| 140 | status(ui, view); | 174 | status(ui, view); |
| 141 | 175 | ||
