Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/data_types.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// src/data_types.rs

use std::borrow::Cow;
use std::hash::{Hash, Hasher, DefaultHasher};
use std::path::PathBuf;
use std::io::Write;
Expand Down Expand Up @@ -180,10 +181,24 @@ pub struct DataDirMnemonic<'a> {
pub deriv_index: u32,
}

fn normalize_challenge_id(challenge_id: &str) -> Cow<str> {
#[cfg(target_os = "windows")]
{
// Directories with '*' are not supported on windows
challenge_id.replace("*", "")
}
#[cfg(not(target_os = "windows"))]
{
Cow::from(challenge_id)
}
}

impl<'a> DataDir<'a> {
pub fn challenge_dir(&'a self, base_dir: &str, challenge_id: &str) -> Result<PathBuf, String> {
let challenge_id_normalized = normalize_challenge_id(challenge_id);

let mut path = PathBuf::from(base_dir);
path.push(challenge_id);
path.push(challenge_id_normalized.as_ref());
Ok(path)
}

Expand Down Expand Up @@ -263,7 +278,7 @@ impl<'a> DataDir<'a> {
.map_err(|e| format!("Could not create pending_submissions directory: {}", e))?;

// Use a unique file name based on challenge, address, and nonce
path.push(format!("{}_{}_{}.json", solution.address, solution.challenge_id, solution.nonce));
path.push(format!("{}_{}_{}.json", solution.address, normalize_challenge_id(&solution.challenge_id), solution.nonce));

let solution_json = serde_json::to_string(solution)
.map_err(|e| format!("Could not serialize pending solution: {}", e))?;
Expand Down Expand Up @@ -320,7 +335,7 @@ pub fn is_solution_pending_in_queue(base_dir: &str, address: &str, challenge_id:
if let Some(filename) = entry.file_name().to_str() {
// Check if the filename starts with the required prefix and is a JSON file
// The filename format is: address_challenge_id_nonce.json
if filename.starts_with(&format!("{}_{}_", address, challenge_id)) && filename.ends_with(".json") {
if filename.starts_with(&format!("{}_{}_", address, normalize_challenge_id(&challenge_id))) && filename.ends_with(".json") {
return Ok(true);
}
}
Expand Down