diff options
Diffstat (limited to 'src/handlers.rs')
-rw-r--r-- | src/handlers.rs | 15 |
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)); |