From 3ec12ea0fdf179dc9f45a550fd6e60c9501790d5 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sat, 23 Apr 2022 21:50:03 +0300 Subject: Separate duplicate tx check from tx ids Use source and target instead --- src/handlers.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src') 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( )); } - let transaction_id = calculate_transaction_id(&new_transaction.source, &new_transaction.target); - + // Is this a duplicate transaction { let transactions = db.pending_transactions.read(); debug!( @@ -751,19 +750,22 @@ pub async fn propose_transaction( new_transaction.source, new_transaction.target, ); - if transactions.contains_key(&transaction_id) { - debug!( - "this source/target combination {} already has a pending transaction", - transaction_id - ); - - return Ok(warp::reply::with_status( - warp::reply::json(&UserFeedback { - res: ResponseType::Error, - message: "This user already has another pending transaction".to_owned(), - }), - StatusCode::BAD_REQUEST, - )); + for tx in transactions.values() { + if tx.source == new_transaction.source && tx.target == new_transaction.target { + debug!( + "There is already a transaction from {} to {}", + new_transaction.source, new_transaction.target + ); + return Ok(warp::reply::with_status( + warp::reply::json(&UserFeedback { + res: ResponseType::Error, + message: + "This user already has another pending transaction with this recipient" + .to_owned(), + }), + StatusCode::BAD_REQUEST, + )); + } } } @@ -841,6 +843,7 @@ pub async fn propose_transaction( let mut transactions = db.pending_transactions.write(); + let transaction_id = calculate_transaction_id(&new_transaction.source, &new_transaction.target); transactions.insert(transaction_id, new_transaction); Ok(warp::reply::with_status( -- cgit v1.2.3-70-g09d2