aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-18 21:53:17 +0300
committerYigit Sever2021-04-18 21:53:17 +0300
commit7e16965b37a1b125994fa85b97924f0ed4ea48ad (patch)
tree78a99d388d29605927927003f5101a6e7e3a33af /src/handlers.rs
parenta9dbfe9a2a11f9614e9618d8d2895eb1ca33db7f (diff)
downloadgradecoin-7e16965b37a1b125994fa85b97924f0ed4ea48ad.tar.gz
gradecoin-7e16965b37a1b125994fa85b97924f0ed4ea48ad.tar.bz2
gradecoin-7e16965b37a1b125994fa85b97924f0ed4ea48ad.zip
Transaction hashing should be easier
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs11
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 ));