From 752b05888c3309538a9a8fd3b87b8dd6b510e37e Mon Sep 17 00:00:00 2001 From: alpaylan Date: Fri, 16 Apr 2021 03:29:30 +0300 Subject: handle double transaction. --- src/handlers.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/handlers.rs b/src/handlers.rs index e63933d..88f9a80 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -332,6 +332,7 @@ pub async fn authorized_propose_block( db: Db, ) -> Result { debug!("POST request to /block, authorized_propose_block"); + println!("Hi"); let users_store = db.users.upgradable_read(); @@ -625,6 +626,17 @@ pub async fn authorized_propose_transaction( debug!("clear for transaction proposal"); let mut transactions = db.pending_transactions.write(); + + if transactions.contains_key(&*new_transaction.source.to_owned()) { + return Ok(warp::reply::with_status( + warp::reply::json(&GradeCoinResponse { + res: ResponseType::Error, + message: "This user already has another pending transaction".to_owned(), + }), + StatusCode::BAD_REQUEST, + )); + } + transactions.insert(new_transaction.source.to_owned(), new_transaction); Ok(warp::reply::with_status( warp::reply::json(&GradeCoinResponse { -- cgit v1.2.3-70-g09d2