some code cleanup

This commit is contained in:
Ivan Folgueira Bande 2024-11-18 10:23:56 +01:00
parent 0bd6af6358
commit 603e8d9870
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7
3 changed files with 7 additions and 19 deletions

1
examples/Cargo.lock generated
View File

@ -4344,6 +4344,7 @@ dependencies = [
"ctrlc", "ctrlc",
"eframe", "eframe",
"egui", "egui",
"secp256k1 0.26.0",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",

View File

@ -1,18 +1,13 @@
use eframe::egui; use eframe::egui;
use secp256k1::SecretKey;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::cell::OnceCell;
use std::str::from_utf8; use std::str::from_utf8;
use std::sync::Arc; use std::sync::{Arc, Mutex};
use std::sync::Mutex; use std::time::{SystemTime, Duration};
use std::str::FromStr;
use std::time::SystemTime;
use std::time::{Duration, Instant};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use waku::{ use waku::{
waku_new, Encoding, Event, Initialized, LibwakuResponse, Multiaddr, Running, WakuContentTopic, waku_new, Encoding, Event, LibwakuResponse, WakuContentTopic,
WakuMessage, WakuNodeConfig, WakuNodeContext, WakuNodeHandle, WakuMessage, WakuNodeConfig, WakuNodeHandle,
}; };
#[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone)] #[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone)]
@ -28,13 +23,6 @@ struct GameState {
moves_left: usize, moves_left: usize,
} }
#[derive(Clone)]
struct MoveMessage {
row: usize,
col: usize,
player: Player,
}
struct TicTacToeApp { struct TicTacToeApp {
game_state: Arc<Mutex<GameState>>, game_state: Arc<Mutex<GameState>>,
waku: WakuNodeHandle, waku: WakuNodeHandle,
@ -95,7 +83,7 @@ impl TicTacToeApp {
}; };
// Establish a closure that handles the incoming messages // Establish a closure that handles the incoming messages
self.waku.ctx.waku_set_event_callback(my_closure); self.waku.ctx.waku_set_event_callback(my_closure).expect("set event call back working");
// Subscribe to desired topic // Subscribe to desired topic
self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe"); self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe");
@ -235,7 +223,6 @@ impl eframe::App for TicTacToeApp {
ui.label(format!("You are playing as: {:?}", player_role)); ui.label(format!("You are playing as: {:?}", player_role));
// Draw the game board and handle the game state // Draw the game board and handle the game state
let text_size = 32.0;
let board_size = ui.available_size(); let board_size = ui.available_size();
let cell_size = board_size.x / 4.0; let cell_size = board_size.x / 4.0;

View File

@ -59,7 +59,7 @@ impl WakuNodeContext {
/// which are used to react to asynchronous events in Waku /// which are used to react to asynchronous events in Waku
pub fn waku_set_event_callback<F: FnMut(LibwakuResponse) + 'static + Sync + Send>( pub fn waku_set_event_callback<F: FnMut(LibwakuResponse) + 'static + Sync + Send>(
&self, &self,
mut closure: F, closure: F,
) -> Result<(), String> { ) -> Result<(), String> {
if let Ok(mut boxed_closure) = self.msg_observer.lock() { if let Ok(mut boxed_closure) = self.msg_observer.lock() {
*boxed_closure = Box::new(closure); *boxed_closure = Box::new(closure);