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.
This commit is contained in:
parent
bc46e960a5
commit
4f34d0079c
1 changed files with 32 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue