diff options
author | alpaylan | 2021-04-16 03:29:30 +0300 |
---|---|---|
committer | alpaylan | 2021-04-16 03:29:30 +0300 |
commit | e923a69e503c81a38736f9eb3ea65e4c8551dee5 (patch) | |
tree | d6eb39f730a47778b4290d33059a7cf791628ae1 | |
parent | 166d80b7938970dae7d8cf24805a329e0770d77f (diff) | |
download | gradecoin-e923a69e503c81a38736f9eb3ea65e4c8551dee5.tar.gz gradecoin-e923a69e503c81a38736f9eb3ea65e4c8551dee5.tar.bz2 gradecoin-e923a69e503c81a38736f9eb3ea65e4c8551dee5.zip |
handle double transaction.
-rw-r--r-- | src/handlers.rs | 12 |
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 { |