aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authornecrashter2022-04-23 16:42:46 +0300
committerYigit Sever2022-04-23 18:10:12 +0300
commit92b37178167435027bb9e4db22b5c44977f341f9 (patch)
tree7170010cd9693a9976c5f71cfbf648ea7abef80f /src/handlers.rs
parent8d7a1c4337af570c691c3c16527b724ae57ed80f (diff)
downloadgradecoin-92b37178167435027bb9e4db22b5c44977f341f9.tar.gz
gradecoin-92b37178167435027bb9e4db22b5c44977f341f9.tar.bz2
gradecoin-92b37178167435027bb9e4db22b5c44977f341f9.zip
Configurable hash zero hexadecimal character count
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 44c5299..6619924 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -524,14 +524,19 @@ pub async fn propose_block(
524 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 524 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
525 } 525 }
526 526
527 // Are the 6 leftmost characters (=24 bits) zero? 527 // Are the n leftmost characters zero?
528 let should_zero = i32::from(hashvalue[0]) + i32::from(hashvalue[1]) + i32::from(hashvalue[2]); 528 let hash_correct = hash_string.chars()
529 .take(db.config.hash_zeros.into())
530 .all(|x| x == '0');
529 531
530 if should_zero != 0 { 532 if !hash_correct {
531 debug!("the hash does not have 6 rightmost zero bits"); 533 debug!("The hash does not have {} leftmost zero characters", db.config.hash_zeros);
532 let res_json = warp::reply::json(&GradeCoinResponse { 534 let res_json = warp::reply::json(&GradeCoinResponse {
533 res: ResponseType::Error, 535 res: ResponseType::Error,
534 message: "Given block hash is larger than target value".to_owned(), 536 message: format!(
537 "Given block hash does not start with {} zero hexadecimal characters",
538 db.config.hash_zeros
539 ),
535 }); 540 });
536 541
537 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 542 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));