fix: use a fee reserve and actual wallet fees
This commit is contained in:
parent
4995ab5aaf
commit
efd2cb7170
|
@ -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…
Reference in New Issue
Block a user