From 76c804a3ac297cfb3a4dd23a311a363677e3f98f Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 24 Sep 2025 13:40:36 -0400 Subject: [PATCH] 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 --- make_post_sell/lib/crypto_watcher.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index 9c597ea..f1969d5 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -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