aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 90cc8c4..a8c9947 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -420,7 +420,6 @@ pub async fn authorized_propose_block(
420/// * `token` - An Authorization header value such as `Bearer aaa.bbb.ccc` 420/// * `token` - An Authorization header value such as `Bearer aaa.bbb.ccc`
421/// * `db` - Global [`Db`] instance 421/// * `db` - Global [`Db`] instance
422/// 422///
423/// TODO This method should check if the user has enough balance for the transaction
424pub async fn authorized_propose_transaction( 423pub async fn authorized_propose_transaction(
425 new_transaction: Transaction, 424 new_transaction: Transaction,
426 token: String, 425 token: String,
@@ -459,17 +458,30 @@ pub async fn authorized_propose_transaction(
459 return Ok(warp::reply::with_status( 458 return Ok(warp::reply::with_status(
460 warp::reply::json(&GradeCoinResponse { 459 warp::reply::json(&GradeCoinResponse {
461 res: ResponseType::Error, 460 res: ResponseType::Error,
462 message: "User does not have enough balance in their account".to_owned(), 461 message:
462 "User does not have enough balance in their account for this transaction"
463 .to_owned(),
463 }), 464 }),
464 StatusCode::BAD_REQUEST, 465 StatusCode::BAD_REQUEST,
465 )); 466 ));
466 } 467 }
468 } else if new_transaction.by == new_transaction.target
469 && new_transaction.source
470 != "31415926535897932384626433832795028841971693993751058209749445923"
471 {
472 // Propose to transact with the bank
473 return Ok(warp::reply::with_status(
474 warp::reply::json(&GradeCoinResponse {
475 res: ResponseType::Error,
476 message: "Transactions cannot extort Gradecoin from unsuspecting users".to_owned(),
477 }),
478 StatusCode::BAD_REQUEST,
479 ));
467 } else { 480 } else {
468 // TODO: add bank mechanism <14-04-21, keles> //
469 return Ok(warp::reply::with_status( 481 return Ok(warp::reply::with_status(
470 warp::reply::json(&GradeCoinResponse { 482 warp::reply::json(&GradeCoinResponse {
471 res: ResponseType::Error, 483 res: ResponseType::Error,
472 message: "Invalid by field for the proposed transaction".to_owned(), 484 message: "Transactions cannot be proposed between two unrelated parties".to_owned(),
473 }), 485 }),
474 StatusCode::BAD_REQUEST, 486 StatusCode::BAD_REQUEST,
475 )); 487 ));