Skip to content

Commit

Permalink
Reverse claim if failed
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Sep 9, 2024
1 parent 9a1067f commit aebbd9a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions views_lnurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import bolt11
from fastapi import APIRouter, HTTPException, Query, Request
from lnbits.core.services import create_invoice
from lnbits.core.crud import get_wallet
from lnbits.core.views.api import pay_invoice
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis

Expand Down Expand Up @@ -218,6 +219,12 @@ async def lnurl_callback(
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Not valid payment request"
)
wallet = await get_wallet(device.wallet)
assert wallet
if wallet.balance_msat < (int(lnurldevicepayment.sats / 1000) + 100):
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Not enough funds"
)
else:
if lnurldevicepayment.payload != k1:
return {"status": "ERROR", "reason": "Bad K1"}
Expand All @@ -233,11 +240,13 @@ async def lnurl_callback(
max_sat=int(lnurldevicepayment_updated.sats / 1000),
extra={"tag": "withdraw"},
)
except Exception:
return {
"status": "ERROR",
"reason": "Payment failed, use a different wallet.",
}
except Exception as exc:
lnurldevicepayment.payhash = "payment_hash"
lnurldevicepayment_updated = await update_lnurldevicepayment(lnurldevicepayment)
assert lnurldevicepayment_updated
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Failed to make payment"
) from exc
return {"status": "OK"}
if device.device == "switch":
if not amount:
Expand Down

0 comments on commit aebbd9a

Please sign in to comment.