From 797b0c5a686df7483540f4cb6baaeed6d5147ee8 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:27:41 +0300 Subject: Implement the bank account --- src/handlers.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/handlers.rs') 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( /// * `token` - An Authorization header value such as `Bearer aaa.bbb.ccc` /// * `db` - Global [`Db`] instance /// -/// TODO This method should check if the user has enough balance for the transaction pub async fn authorized_propose_transaction( new_transaction: Transaction, token: String, @@ -459,17 +458,30 @@ pub async fn authorized_propose_transaction( return Ok(warp::reply::with_status( warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "User does not have enough balance in their account".to_owned(), + message: + "User does not have enough balance in their account for this transaction" + .to_owned(), }), StatusCode::BAD_REQUEST, )); } + } else if new_transaction.by == new_transaction.target + && new_transaction.source + != "31415926535897932384626433832795028841971693993751058209749445923" + { + // Propose to transact with the bank + return Ok(warp::reply::with_status( + warp::reply::json(&GradeCoinResponse { + res: ResponseType::Error, + message: "Transactions cannot extort Gradecoin from unsuspecting users".to_owned(), + }), + StatusCode::BAD_REQUEST, + )); } else { - // TODO: add bank mechanism <14-04-21, keles> // return Ok(warp::reply::with_status( warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "Invalid by field for the proposed transaction".to_owned(), + message: "Transactions cannot be proposed between two unrelated parties".to_owned(), }), StatusCode::BAD_REQUEST, )); -- cgit v1.2.3-70-g09d2