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