Apply black formatting to crypto files
This commit is contained in:
parent
d3f2c1caa4
commit
d292ab88e2
2 changed files with 76 additions and 42 deletions
|
|
@ -292,8 +292,10 @@ def auto_sweep_payment_doge(client, crypto_payment: CryptoPayment, dbsession=Non
|
|||
except Exception as e:
|
||||
# Fallback to min_sweep_balance if RPC call fails
|
||||
estimated_fee_doge = float(min_sweep_balance)
|
||||
logger.warning(f"Failed to get dynamic DOGE fee estimate, using fallback: {e}")
|
||||
|
||||
logger.warning(
|
||||
f"Failed to get dynamic DOGE fee estimate, using fallback: {e}"
|
||||
)
|
||||
|
||||
# Sweep balance minus estimated fee
|
||||
sweep_amount = balance - Decimal(str(estimated_fee_doge))
|
||||
if sweep_amount <= 0:
|
||||
|
|
@ -1223,42 +1225,67 @@ def run_once(env, interval):
|
|||
or {}
|
||||
)
|
||||
incoming = res.get("in", []) or []
|
||||
|
||||
|
||||
# Fallback: If no transfers found for subaddress, check all account transfers
|
||||
# This helps with mempool transactions that might not immediately show up
|
||||
# This helps with mempool transactions that might not immediately show up
|
||||
# in subaddress-filtered queries
|
||||
if not incoming:
|
||||
logger.debug(f"No transfers found for subaddress {crypto_payment.subaddress_index}, checking all account transfers")
|
||||
logger.debug(
|
||||
f"No transfers found for subaddress {crypto_payment.subaddress_index}, checking all account transfers"
|
||||
)
|
||||
try:
|
||||
# Check all transfers for this account (including mempool)
|
||||
all_transfers_result = client._call("get_transfers", {
|
||||
"in": True,
|
||||
"out": False,
|
||||
"pending": True,
|
||||
"failed": False,
|
||||
"pool": True, # Include mempool transactions
|
||||
"account_index": crypto_payment.account_index,
|
||||
# Don't filter by subaddr_indices - get all transfers
|
||||
})
|
||||
|
||||
all_incoming = all_transfers_result.get("in", []) if all_transfers_result else []
|
||||
all_transfers_result = client._call(
|
||||
"get_transfers",
|
||||
{
|
||||
"in": True,
|
||||
"out": False,
|
||||
"pending": True,
|
||||
"failed": False,
|
||||
"pool": True, # Include mempool transactions
|
||||
"account_index": crypto_payment.account_index,
|
||||
# Don't filter by subaddr_indices - get all transfers
|
||||
},
|
||||
)
|
||||
|
||||
all_incoming = (
|
||||
all_transfers_result.get("in", [])
|
||||
if all_transfers_result
|
||||
else []
|
||||
)
|
||||
# Also check pool (mempool) transactions
|
||||
pool_incoming = all_transfers_result.get("pool", []) if all_transfers_result else []
|
||||
pool_incoming = (
|
||||
all_transfers_result.get("pool", [])
|
||||
if all_transfers_result
|
||||
else []
|
||||
)
|
||||
all_incoming.extend(pool_incoming)
|
||||
|
||||
|
||||
# Filter for our specific subaddress
|
||||
for tx in all_incoming:
|
||||
if (tx.get("subaddr_index", {}).get("minor") == crypto_payment.subaddress_index and
|
||||
tx.get("subaddr_index", {}).get("major") == crypto_payment.account_index):
|
||||
if (
|
||||
tx.get("subaddr_index", {}).get("minor")
|
||||
== crypto_payment.subaddress_index
|
||||
and tx.get("subaddr_index", {}).get("major")
|
||||
== crypto_payment.account_index
|
||||
):
|
||||
incoming.append(tx)
|
||||
logger.debug(f"Found transfer for our subaddress in all-account query: {tx.get('txid', 'unknown')[:8]}...")
|
||||
logger.debug(
|
||||
f"Found transfer for our subaddress in all-account query: {tx.get('txid', 'unknown')[:8]}..."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to query all account transfers for mempool fallback: {e}")
|
||||
|
||||
logger.warning(
|
||||
f"Failed to query all account transfers for mempool fallback: {e}"
|
||||
)
|
||||
|
||||
if incoming:
|
||||
logger.debug(f"Found {len(incoming)} transfers for payment {crypto_payment.id}")
|
||||
logger.debug(
|
||||
f"Found {len(incoming)} transfers for payment {crypto_payment.id}"
|
||||
)
|
||||
else:
|
||||
logger.debug(f"No transfers found for payment {crypto_payment.id} (subaddress {crypto_payment.subaddress_index})")
|
||||
logger.debug(
|
||||
f"No transfers found for payment {crypto_payment.id} (subaddress {crypto_payment.subaddress_index})"
|
||||
)
|
||||
elif coin_type == "DOGE":
|
||||
# Dogecoin: Query received by address
|
||||
incoming = get_dogecoin_incoming_transfers(client, crypto_payment)
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ def crypto_xmr_start(request):
|
|||
|
||||
# Get dynamic fee estimate - we need the processor config first
|
||||
from ..models.crypto_processor import CryptoProcessor
|
||||
|
||||
processor = (
|
||||
request.dbsession.query(CryptoProcessor)
|
||||
.filter(
|
||||
|
|
@ -161,7 +162,7 @@ def crypto_xmr_start(request):
|
|||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
|
||||
if processor and processor.sweep_to_address:
|
||||
# Use dynamic fee estimation with the actual sweep address
|
||||
fee_buffer_xmr = estimate_monero_fee_for_quote(
|
||||
|
|
@ -170,7 +171,7 @@ def crypto_xmr_start(request):
|
|||
else:
|
||||
# Fallback to hardcoded fee if no processor configured yet
|
||||
fee_buffer_xmr = Decimal(settings.get("monero.fee_buffer", "0.0001"))
|
||||
|
||||
|
||||
xmr_amount_with_fee = Decimal(str(xmr_amount)) + fee_buffer_xmr
|
||||
expected_piconero = int(xmr_amount_with_fee * 1_000_000_000_000)
|
||||
|
||||
|
|
@ -861,22 +862,28 @@ def estimate_monero_fee_for_quote(settings, shop_sweep_to_address, amount_picone
|
|||
"""Estimate Monero transaction fee for quote creation using dynamic RPC call."""
|
||||
try:
|
||||
client = get_client_from_settings(settings)
|
||||
|
||||
|
||||
# We need a dummy subaddress for the test - use index 0 which should exist
|
||||
# This is just for fee estimation, not actual transaction
|
||||
test_transfer_result = client._call("transfer", {
|
||||
"destinations": [{
|
||||
"address": shop_sweep_to_address,
|
||||
"amount": amount_piconero
|
||||
}],
|
||||
"account_index": 0, # Use account 0 for estimation
|
||||
"priority": 1,
|
||||
"do_not_relay": True, # Don't broadcast, just estimate
|
||||
"get_tx_metadata": True
|
||||
})
|
||||
|
||||
estimated_fee_piconero = int(test_transfer_result.get("fee", 100000000000)) # Fallback to 0.0001 XMR
|
||||
return Decimal(estimated_fee_piconero) / Decimal('1000000000000') # Convert to XMR
|
||||
test_transfer_result = client._call(
|
||||
"transfer",
|
||||
{
|
||||
"destinations": [
|
||||
{"address": shop_sweep_to_address, "amount": amount_piconero}
|
||||
],
|
||||
"account_index": 0, # Use account 0 for estimation
|
||||
"priority": 1,
|
||||
"do_not_relay": True, # Don't broadcast, just estimate
|
||||
"get_tx_metadata": True,
|
||||
},
|
||||
)
|
||||
|
||||
estimated_fee_piconero = int(
|
||||
test_transfer_result.get("fee", 100000000000)
|
||||
) # Fallback to 0.0001 XMR
|
||||
return Decimal(estimated_fee_piconero) / Decimal(
|
||||
"1000000000000"
|
||||
) # Convert to XMR
|
||||
except Exception as e:
|
||||
# Fallback to hardcoded fee if RPC call fails
|
||||
fallback_fee = float(settings.get("monero.fee_buffer", "0.0001"))
|
||||
|
|
@ -887,7 +894,7 @@ def estimate_dogecoin_fee_for_quote(settings):
|
|||
"""Estimate Dogecoin transaction fee for quote creation using estimatesmartfee."""
|
||||
try:
|
||||
client = get_dogecoin_client_from_settings(settings)
|
||||
|
||||
|
||||
# Use estimatesmartfee to get current network fee estimate
|
||||
fee_estimate_result = client._call("estimatesmartfee", [2]) # 2 block target
|
||||
if fee_estimate_result and "feerate" in fee_estimate_result:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue