Merge pull request #476 from mrbitcoiner/main

2% reserve only for external payments
This commit is contained in:
Arc 2021-12-30 17:11:37 +00:00 committed by GitHub
commit 57a2dffe52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,8 +96,6 @@ async def pay_invoice(
raise ValueError("Amount in invoice is too high.")
wallet = await get_wallet(wallet_id, conn=conn)
if invoice.amount_msat > wallet.balance_msat - (wallet.balance_msat / 100 * 2):
raise PermissionError("LNbits requires you keep at least 2% reserve to cover potential routing fees.")
# put all parameters that don't change here
PaymentKwargs = TypedDict(
@ -141,11 +139,17 @@ async def pay_invoice(
**payment_kwargs,
)
# do the balance check
wallet = await get_wallet(wallet_id, conn=conn)
assert wallet
if wallet.balance_msat < 0:
raise PermissionError("Insufficient balance.")
# do the balance check if internal payment
if internal_checking_id:
wallet = await get_wallet(wallet_id, conn=conn)
assert wallet
if wallet.balance_msat < 0:
raise PermissionError("Insufficient balance.")
# do the balance check if external payment
else:
if invoice.amount_msat > wallet.balance_msat - (wallet.balance_msat / 100 * 2):
raise PermissionError("LNbits requires you keep at least 2% reserve to cover potential routing fees.")
if internal_checking_id:
# mark the invoice from the other side as not pending anymore