Browse Source

don't try to check payments that start with temp_ or internal_.

aiosqlite
fiatjaf 5 years ago
parent
commit
d2650d6e2c
  1. 4
      lnbits/core/models.py
  2. 4
      lnbits/core/services.py
  3. 8
      lnbits/core/views/api.py

4
lnbits/core/models.py

@ -96,6 +96,10 @@ class Payment(NamedTuple):
def is_out(self) -> bool: def is_out(self) -> bool:
return self.amount < 0 return self.amount < 0
@property
def is_uncheckable(self) -> bool:
return self.checking_id.startswith("temp_") or self.checking_id.startswith("internal_")
def set_pending(self, pending: bool) -> None: def set_pending(self, pending: bool) -> None:
from .crud import update_payment_status from .crud import update_payment_status

4
lnbits/core/services.py

@ -45,6 +45,8 @@ def pay_invoice(
*, wallet_id: str, payment_request: str, max_sat: Optional[int] = None, extra: Optional[Dict] = None *, wallet_id: str, payment_request: str, max_sat: Optional[int] = None, extra: Optional[Dict] = None
) -> str: ) -> str:
temp_id = f"temp_{urlsafe_short_hash()}" temp_id = f"temp_{urlsafe_short_hash()}"
internal_id = f"internal_{urlsafe_short_hash()}"
try: try:
invoice = bolt11.decode(payment_request) invoice = bolt11.decode(payment_request)
if invoice.amount_msat == 0: if invoice.amount_msat == 0:
@ -66,7 +68,7 @@ def pay_invoice(
internal = check_internal(invoice.payment_hash) internal = check_internal(invoice.payment_hash)
if internal: if internal:
# create a new payment from this wallet # create a new payment from this wallet
create_payment(checking_id=temp_id, fee=0, pending=False, **payment_kwargs) create_payment(checking_id=internal_id, fee=0, pending=False, **payment_kwargs)
else: else:
# create a temporary payment here so we can check if # create a temporary payment here so we can check if
# the balance is enough in the next step # the balance is enough in the next step

8
lnbits/core/views/api.py

@ -16,7 +16,9 @@ def api_payments():
g.wallet.delete_expired_payments() g.wallet.delete_expired_payments()
for payment in g.wallet.get_payments(complete=False, pending=True): for payment in g.wallet.get_payments(complete=False, pending=True):
if payment.is_out: if payment.is_uncheckable:
pass
elif payment.is_out:
payment.set_pending(WALLET.get_payment_status(payment.checking_id).pending) payment.set_pending(WALLET.get_payment_status(payment.checking_id).pending)
else: else:
payment.set_pending(WALLET.get_invoice_status(payment.checking_id).pending) payment.set_pending(WALLET.get_invoice_status(payment.checking_id).pending)
@ -104,7 +106,9 @@ def api_payment(payment_hash):
return jsonify({"paid": True}), HTTPStatus.OK return jsonify({"paid": True}), HTTPStatus.OK
try: try:
if payment.is_out: if payment.is_uncheckable:
pass
elif payment.is_out:
is_paid = not WALLET.get_payment_status(payment.checking_id).pending is_paid = not WALLET.get_payment_status(payment.checking_id).pending
elif payment.is_in: elif payment.is_in:
is_paid = not WALLET.get_invoice_status(payment.checking_id).pending is_paid = not WALLET.get_invoice_status(payment.checking_id).pending

Loading…
Cancel
Save