From efd2cb71708e065855db433f2b7b9701c3a25d1b Mon Sep 17 00:00:00 2001 From: Eneko Illarramendi Date: Fri, 24 Apr 2020 19:30:20 +0200 Subject: [PATCH] fix: use a fee reserve and actual wallet fees --- lnbits/core/services.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 12183aa4..6e43aca4 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -34,15 +34,27 @@ def pay_invoice(*, wallet_id: str, bolt11: str, max_sat: Optional[int] = None) - if max_sat and invoice.amount_msat > max_sat * 1000: raise ValueError("Amount in invoice is too high.") - if invoice.amount_msat > get_wallet(wallet_id).balance_msat: + fee_reserve = max(1000, invoice.amount_msat * 0.01) + create_payment( + wallet_id=wallet_id, + checking_id=temp_id, + amount=-invoice.amount_msat, + fee=-fee_reserve, + memo=temp_id, + ) + + if get_wallet(wallet_id).balance_msat < 0: raise PermissionError("Insufficient balance.") - create_payment(wallet_id=wallet_id, checking_id=temp_id, amount=-invoice.amount_msat, memo=temp_id) ok, checking_id, fee_msat, error_message = WALLET.pay_invoice(bolt11) if ok: create_payment( - wallet_id=wallet_id, checking_id=checking_id, amount=-invoice.amount_msat, memo=invoice.description + wallet_id=wallet_id, + checking_id=checking_id, + amount=-invoice.amount_msat, + fee=fee_msat, + memo=invoice.description, ) except Exception as e: