diff options
author | Yigit Sever | 2021-04-18 21:53:17 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-18 21:53:17 +0300 |
commit | 4c855e5bb82cdc470d8dd915121a2e033324d5b1 (patch) | |
tree | d8700627e6618079aa8fa9486c9d99fbfd1e0f9a /src/handlers.rs | |
parent | 5f066ada307881e08e61ee9a94a9fc65440bc64f (diff) | |
download | gradecoin-4c855e5bb82cdc470d8dd915121a2e033324d5b1.tar.gz gradecoin-4c855e5bb82cdc470d8dd915121a2e033324d5b1.tar.bz2 gradecoin-4c855e5bb82cdc470d8dd915121a2e033324d5b1.zip |
Transaction hashing should be easier
Diffstat (limited to 'src/handlers.rs')
-rw-r--r-- | src/handlers.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index ead6828..a5070a4 100644 --- a/src/handlers.rs +++ b/src/handlers.rs | |||
@@ -656,14 +656,17 @@ pub async fn propose_transaction( | |||
656 | // this transaction was already checked for correctness at custom_filters, we can panic here if | 656 | // this transaction was already checked for correctness at custom_filters, we can panic here if |
657 | // it has been changed since | 657 | // it has been changed since |
658 | 658 | ||
659 | let hashed_transaction = | 659 | let serd_tx = serde_json::to_string(&new_transaction).unwrap(); |
660 | Md5::digest((&serde_json::to_string(&new_transaction).unwrap()).as_ref()); | 660 | |
661 | debug!("Taking the hash of {}", serd_tx); | ||
662 | |||
663 | let hashed_transaction = Md5::digest(&serd_tx.as_bytes()); | ||
661 | if token_payload.claims.tha != format!("{:x}", hashed_transaction) { | 664 | if token_payload.claims.tha != format!("{:x}", hashed_transaction) { |
662 | debug!("The hash of the transaction did not match with the hash given in JWT"); | ||
663 | return Ok(warp::reply::with_status( | 665 | return Ok(warp::reply::with_status( |
664 | warp::reply::json(&GradeCoinResponse { | 666 | warp::reply::json(&GradeCoinResponse { |
665 | res: ResponseType::Error, | 667 | res: ResponseType::Error, |
666 | message: "The hash of the transaction did not match the hash given in JWT".to_owned(), | 668 | message: "The hash of the transaction did not match the hash given in JWT" |
669 | .to_owned(), | ||
667 | }), | 670 | }), |
668 | StatusCode::BAD_REQUEST, | 671 | StatusCode::BAD_REQUEST, |
669 | )); | 672 | )); |