aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authoralpaylan2021-04-16 03:29:30 +0300
committeralpaylan2021-04-16 03:29:30 +0300
commit752b05888c3309538a9a8fd3b87b8dd6b510e37e (patch)
treed1ebd84190555fd14c863ee837ef8d43213d298f /src/handlers.rs
parentef2e7f59d13e3767a13f7aa10fb1422b319713cb (diff)
downloadgradecoin-752b05888c3309538a9a8fd3b87b8dd6b510e37e.tar.gz
gradecoin-752b05888c3309538a9a8fd3b87b8dd6b510e37e.tar.bz2
gradecoin-752b05888c3309538a9a8fd3b87b8dd6b510e37e.zip
handle double transaction.
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs12
1 files changed, 12 insertions, 0 deletions
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(
332 db: Db, 332 db: Db,
333) -> Result<impl warp::Reply, warp::Rejection> { 333) -> Result<impl warp::Reply, warp::Rejection> {
334 debug!("POST request to /block, authorized_propose_block"); 334 debug!("POST request to /block, authorized_propose_block");
335 println!("Hi");
335 336
336 let users_store = db.users.upgradable_read(); 337 let users_store = db.users.upgradable_read();
337 338
@@ -625,6 +626,17 @@ pub async fn authorized_propose_transaction(
625 debug!("clear for transaction proposal"); 626 debug!("clear for transaction proposal");
626 627
627 let mut transactions = db.pending_transactions.write(); 628 let mut transactions = db.pending_transactions.write();
629
630 if transactions.contains_key(&*new_transaction.source.to_owned()) {
631 return Ok(warp::reply::with_status(
632 warp::reply::json(&GradeCoinResponse {
633 res: ResponseType::Error,
634 message: "This user already has another pending transaction".to_owned(),
635 }),
636 StatusCode::BAD_REQUEST,
637 ));
638 }
639
628 transactions.insert(new_transaction.source.to_owned(), new_transaction); 640 transactions.insert(new_transaction.source.to_owned(), new_transaction);
629 Ok(warp::reply::with_status( 641 Ok(warp::reply::with_status(
630 warp::reply::json(&GradeCoinResponse { 642 warp::reply::json(&GradeCoinResponse {