Skip to content

Commit

Permalink
Added checks and set boltz swap payment
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Oct 22, 2024
1 parent 5ce260f commit ed125d3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ async def get_lnurldevice_payment_boltz(
assert lnurldevicepayment
if lnurldevicepayment == "ERROR":
return lnurldevicepayment

if lnurldevicepayment.payload == lnurldevicepayment.payhash:
return {"status": "ERROR", "reason": "Payment already claimed."}
if lnurldevicepayment.payhash == "pending":
return {
"status": "ERROR",
"reason": "Pending. If you are unable to withdraw contact vendor",
}
wallet = await get_wallet(lnurldevice.wallet)
if not wallet:
raise HTTPException(
Expand All @@ -273,14 +279,28 @@ async def get_lnurldevice_payment_boltz(

try:
lnurldevicepayment.payload = payload
await update_lnurldevicepayment(lnurldevicepayment)
lnurldevicepayment.payhash = "pending"
lnurldevicepayment_updated = await update_lnurldevicepayment(
lnurldevicepayment
)
assert lnurldevicepayment_updated
async with httpx.AsyncClient() as client:
response = await client.post(
url=f"http://{settings.host}:{settings.port}/boltz/api/v1/swap/reverse",
headers={"X-API-KEY": wallet.adminkey},
json=data,
)
lnurldevicepayment.payhash = lnurldevicepayment.payload
lnurldevicepayment_updated = await update_lnurldevicepayment(
lnurldevicepayment
)
assert lnurldevicepayment_updated
resp = response.json()
return resp
except Exception as exc:
lnurldevicepayment.payhash = "payment_hash"
lnurldevicepayment_updated = await update_lnurldevicepayment(
lnurldevicepayment
)
assert lnurldevicepayment_updated
return {"status": "ERROR", "reason": str(exc)}

0 comments on commit ed125d3

Please sign in to comment.