Browse Source

fix: use a fee reserve and actual wallet fees

fee_issues
Eneko Illarramendi 5 years ago
parent
commit
efd2cb7170
  1. 18
      lnbits/core/services.py

18
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: if max_sat and invoice.amount_msat > max_sat * 1000:
raise ValueError("Amount in invoice is too high.") 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.") 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) ok, checking_id, fee_msat, error_message = WALLET.pay_invoice(bolt11)
if ok: if ok:
create_payment( 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: except Exception as e:

Loading…
Cancel
Save