Fix hardcoded confirmation requirements in crypto payment rescue

- Use coin-specific confirmation requirements from get_coin_config
- DOGE refunds now process at 2 confirmations instead of 10
- Improve logging to show correct coin type and atomic units
- Still need to implement DOGE-specific refund mechanism (currently uses XMR transfer RPC)
This commit is contained in:
Russell Ballestrini 2025-09-29 10:18:44 -04:00
parent 3d7289d517
commit 5df297eade

View file

@ -167,26 +167,38 @@ class PaymentRescue:
logger = logging.getLogger(__name__)
refund_amount_xmr = refund_details["refund_amount"]
refund_amount_piconero = int(refund_amount_xmr * Decimal("1e12"))
refund_amount_coin = refund_details["refund_amount"]
# Get coin type and atomic units for proper logging
coin_type = payment.coin_type if payment else "XMR"
from .crypto_watcher import get_coin_config
coin_config = get_coin_config(coin_type)
atomic_units = int(coin_config["atomic_units"])
refund_amount_atomic = int(refund_amount_coin * atomic_units)
atomic_unit_name = "piconero" if coin_type == "XMR" else "koinu" if coin_type == "DOGE" else "atomic units"
logger.info(f"Attempting to refund payment {refund_details['payment_id']}")
logger.info(
f"Refund amount: {refund_amount_xmr} XMR ({refund_amount_piconero} piconero)"
f"Refund amount: {refund_amount_coin} {coin_type} ({refund_amount_atomic} {atomic_unit_name})"
)
logger.info(f"Refund address: {refund_details['refund_address']}")
logger.info(f"Refund reason: {refund_details['reason']}")
# Check if incoming payment has enough confirmations before allowing refund
if payment and payment.current_confirmations < 10:
from .crypto_watcher import get_coin_config
coin_config = get_coin_config(payment.coin_type if payment else "XMR")
required_confirmations = coin_config.get("confirmations_required", 10)
if payment and payment.current_confirmations < required_confirmations:
logger.info(
f"Refund delayed - incoming payment has {payment.current_confirmations}/10 confirmations"
f"Refund delayed - incoming payment has {payment.current_confirmations}/{required_confirmations} confirmations"
)
return {
"success": False,
"error": f"Incoming payment needs {10 - payment.current_confirmations} more confirmations before refund",
"error": f"Incoming payment needs {required_confirmations - payment.current_confirmations} more confirmations before refund",
"refund_details": refund_details,
"confirmations_needed": 10 - payment.current_confirmations,
"confirmations_needed": required_confirmations - payment.current_confirmations,
}
# Check wallet balance for the specific account before attempting refund
@ -221,7 +233,7 @@ class PaymentRescue:
"destinations": [
{
"address": refund_details["refund_address"],
"amount": refund_amount_piconero,
"amount": refund_amount_atomic,
}
],
"account_index": account_index, # Specify the account that received the funds