From 4f34d0079c6963dd98eec0feffda23903a8f1697 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 28 Sep 2025 12:13:44 -0400 Subject: [PATCH] Fix duplicate payment confirmation counting bug that prevented refunds The update_payment_confirmations_only function was using min() across ALL transactions to the same address instead of checking the specific transaction for duplicate payments. This caused duplicate payments with old, confirmed transactions to show 0 confirmations if there were newer unconfirmed transactions to the same address. Fixed by: - Checking if payment is STATUS_DOUBLEPAY_REFUND - Looking up the specific transaction ID from tx_hashes - Using confirmation count for that specific transaction only - Falling back to min() for regular payments This will allow stuck duplicate payment refunds to proceed once their specific transaction has 10+ confirmations. --- make_post_sell/lib/crypto_watcher.py | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index 83a21eb..5c5cdfc 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -2245,7 +2245,38 @@ def update_payment_confirmations_only(client, crypto_payment, coin_type): ) incoming = res.get("in", []) or [] - # Calculate total confirmations from incoming transfers + # For duplicate payments, find confirmation count for specific transaction + if ( + crypto_payment.status == CryptoPayment.STATUS_DOUBLEPAY_REFUND + and crypto_payment.tx_hashes + ): + try: + stored_txids = json.loads(crypto_payment.tx_hashes) + if stored_txids: + target_txid = stored_txids[ + 0 + ] # Duplicate payments store single txid + # Find the specific transaction + for tx in incoming: + tx_id = tx.get("txid") or tx.get("transaction_id") + if tx_id == target_txid: + old_confirmations = crypto_payment.current_confirmations + crypto_payment.current_confirmations = tx.get( + "confirmations", 0 + ) + logger.debug( + f"Updated SPECIFIC transaction confirmations for duplicate payment {crypto_payment.id}: {old_confirmations} → {crypto_payment.current_confirmations} (TX: {target_txid[:16]}...)" + ) + return + logger.warning( + f"Could not find specific transaction {target_txid[:16]}... for duplicate payment {crypto_payment.id}" + ) + except json.JSONDecodeError: + logger.warning( + f"Invalid tx_hashes JSON for payment {crypto_payment.id}" + ) + + # Calculate total confirmations from incoming transfers (for non-duplicate payments) if incoming: min_confirmations = min(tx.get("confirmations", 0) for tx in incoming) old_confirmations = crypto_payment.current_confirmations