aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 997867c..93781e4 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -742,8 +742,7 @@ pub async fn propose_transaction(
742 )); 742 ));
743 } 743 }
744 744
745 let transaction_id = calculate_transaction_id(&new_transaction.source, &new_transaction.target); 745 // Is this a duplicate transaction
746
747 { 746 {
748 let transactions = db.pending_transactions.read(); 747 let transactions = db.pending_transactions.read();
749 debug!( 748 debug!(
@@ -751,19 +750,22 @@ pub async fn propose_transaction(
751 new_transaction.source, new_transaction.target, 750 new_transaction.source, new_transaction.target,
752 ); 751 );
753 752
754 if transactions.contains_key(&transaction_id) { 753 for tx in transactions.values() {
755 debug!( 754 if tx.source == new_transaction.source && tx.target == new_transaction.target {
756 "this source/target combination {} already has a pending transaction", 755 debug!(
757 transaction_id 756 "There is already a transaction from {} to {}",
758 ); 757 new_transaction.source, new_transaction.target
759 758 );
760 return Ok(warp::reply::with_status( 759 return Ok(warp::reply::with_status(
761 warp::reply::json(&UserFeedback { 760 warp::reply::json(&UserFeedback {
762 res: ResponseType::Error, 761 res: ResponseType::Error,
763 message: "This user already has another pending transaction".to_owned(), 762 message:
764 }), 763 "This user already has another pending transaction with this recipient"
765 StatusCode::BAD_REQUEST, 764 .to_owned(),
766 )); 765 }),
766 StatusCode::BAD_REQUEST,
767 ));
768 }
767 } 769 }
768 } 770 }
769 771
@@ -841,6 +843,7 @@ pub async fn propose_transaction(
841 843
842 let mut transactions = db.pending_transactions.write(); 844 let mut transactions = db.pending_transactions.write();
843 845
846 let transaction_id = calculate_transaction_id(&new_transaction.source, &new_transaction.target);
844 transactions.insert(transaction_id, new_transaction); 847 transactions.insert(transaction_id, new_transaction);
845 848
846 Ok(warp::reply::with_status( 849 Ok(warp::reply::with_status(