From 307680dd7cb7601b0617c63fb6d7acb2334071c3 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sat, 27 Sep 2025 15:55:44 -0400 Subject: [PATCH] Add auto-sweep to duplicate detection path for confirmed payments CRITICAL FIX: Auto-sweep was being skipped when payments moved to CONFIRMED status via the duplicate detection path due to early return. - Add auto-sweep logic to duplicate detection path before return - Check if payment is CONFIRMED, has sweep address, and hasn't been swept - Ensures funds are swept to cold storage even when duplicates are detected - Maintains same sweep logic as normal payment processing path This fixes the issue where payment 37ae9bf3-9bcf-11f0-a140-02dfe05770ee moved to confirmed status but funds were never swept because the duplicate detection path returned early before reaching auto-sweep logic. --- make_post_sell/lib/crypto_watcher.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index ca8528e..42473dd 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -1610,6 +1610,25 @@ def process_payment( f"Failed to send sales email for payment {crypto_payment.id}: {e}" ) + # Auto-sweep confirmed payments that haven't been swept yet + if ( + client + and crypto_payment.status == CryptoPayment.STATUS_CONFIRMED + and crypto_payment.shop_sweep_to_address + and not crypto_payment.is_swept + ): + logger.info(f"Payment {crypto_payment.id} confirmed - attempting sweep") + try: + sweep_success = auto_sweep_payment( + client, crypto_payment, env_request.dbsession + ) + if sweep_success and crypto_payment.is_swept: + logger.info(f"Payment {crypto_payment.id} swept successfully") + except Exception as e: + logger.error( + f"Auto-sweep failed for confirmed payment {crypto_payment.id}: {e}" + ) + env_request.dbsession.add(crypto_payment) return