From 5d41e0c50e3b8c7d2c10298b1610c43440a8bd68 Mon Sep 17 00:00:00 2001 From: padreug Date: Sun, 6 Jul 2025 01:15:26 +0200 Subject: [PATCH] Refine distribution logic in transaction processing: Updated the LamassuTransactionProcessor to only create distributions for clients with positive allocated sats. Enhanced logging to indicate when clients are skipped due to zero amounts, improving clarity and accuracy in transaction reporting. --- transaction_processor.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/transaction_processor.py b/transaction_processor.py index a32a32c..7b08ac9 100644 --- a/transaction_processor.py +++ b/transaction_processor.py @@ -749,22 +749,26 @@ class LamassuTransactionProcessor: else: client_calculations[i % len(client_calculations)]['allocated_sats'] -= 1 - # Second pass: create distributions with final amounts + # Second pass: create distributions with final amounts (only for clients with positive allocations) for calc in client_calculations: client_id = calc['client_id'] client_sats_amount = calc['allocated_sats'] proportion = calc['proportion'] - # Calculate equivalent fiat value in GTQ for tracking purposes - client_fiat_amount = round(client_sats_amount / exchange_rate, 2) if exchange_rate > 0 else 0.0 - - distributions[client_id] = { - "fiat_amount": client_fiat_amount, - "sats_amount": client_sats_amount, - "exchange_rate": exchange_rate - } - - logger.info(f"Client {client_id[:8]}... gets {client_sats_amount} sats (≈{client_fiat_amount:.2f} GTQ, {proportion:.2%} share)") + # Only create distributions for clients with positive sats amounts + if client_sats_amount > 0: + # Calculate equivalent fiat value in GTQ for tracking purposes + client_fiat_amount = round(client_sats_amount / exchange_rate, 2) if exchange_rate > 0 else 0.0 + + distributions[client_id] = { + "fiat_amount": client_fiat_amount, + "sats_amount": client_sats_amount, + "exchange_rate": exchange_rate + } + + logger.info(f"Client {client_id[:8]}... gets {client_sats_amount} sats (≈{client_fiat_amount:.2f} GTQ, {proportion:.2%} share)") + else: + logger.info(f"Client {client_id[:8]}... gets {client_sats_amount} sats (≈0.00 GTQ, {proportion:.2%} share) - SKIPPED (zero amount)") # Verification: ensure total distribution equals base amount total_distributed = sum(dist["sats_amount"] for dist in distributions.values()) @@ -796,8 +800,8 @@ class LamassuTransactionProcessor: # In a production system, you might want to recalculate the entire distribution logger.warning("Proceeding with original distribution despite balance warnings - manual review recommended") - logger.info(f"Distribution verified: {total_distributed} sats distributed across {len(final_distributions)} clients") - return final_distributions + logger.info(f"Distribution verified: {total_distributed} sats distributed across {len(distributions)} clients (clients with positive allocations only)") + return distributions except Exception as e: logger.error(f"Error calculating distribution amounts: {e}")