Fix sweep logic to use subaddress isolation

- Change from sweep_all to sweep_single to only sweep funds from specific subaddress
- Prevents sweeping funds from other payments in the same account
- Each payment already uses its own subaddress for proper isolation
This commit is contained in:
Russell Ballestrini 2025-09-24 13:40:36 -04:00
parent 4796d83eae
commit 76c804a3ac

View file

@ -102,24 +102,30 @@ def auto_sweep_payment_xmr(client, crypto_payment: CryptoPayment, dbsession=None
# Don't mark as swept - funds are just locked!
return False
# Sweep all available balance minus a small buffer for fees
# Use "sweep_all" instead of exact amount to handle fees automatically
# Sweep funds from this specific subaddress only
logger.info(
f"Sweeping all funds from account {crypto_payment.account_index} for payment {crypto_payment.id} to {crypto_payment.shop_sweep_to_address}"
f"Sweeping funds from account {crypto_payment.account_index} subaddress {crypto_payment.subaddress_index} for payment {crypto_payment.id} to {crypto_payment.shop_sweep_to_address}"
)
# Use sweep_single to sweep only from the specific subaddress
result = client._call(
"sweep_all",
"sweep_single",
{
"address": crypto_payment.shop_sweep_to_address,
"account_index": crypto_payment.account_index,
"subaddr_indices": [crypto_payment.subaddress_index],
"priority": 1,
"get_tx_hex": False,
},
)
tx_hash = result.get("tx_hash")
fee = result.get("fee", 0) # Network fee in atomic units
# Monero returns tx_hash_list for sweep_all
tx_hash_list = result.get("tx_hash_list", [])
tx_hash = tx_hash_list[0] if tx_hash_list else result.get("tx_hash")
# Fee is in fee_list for sweep_all
fee_list = result.get("fee_list", [])
fee = fee_list[0] if fee_list else result.get("fee", 0)
if tx_hash:
# Mark this payment as swept