fix: more return types
This commit is contained in:
parent
d8d8c6b454
commit
63d0242685
|
@ -295,14 +295,14 @@ async def api_payment(payment_hash, wallet: WalletTypeInfo = Depends(get_key_typ
|
|||
payment = await wallet.wallet.get_payment(payment_hash)
|
||||
|
||||
if not payment:
|
||||
return {"message": "Payment does not exist."}, HTTPStatus.NOT_FOUND
|
||||
return {"message": "Payment does not exist."}
|
||||
elif not payment.pending:
|
||||
return {"paid": True, "preimage": payment.preimage}, HTTPStatus.OK
|
||||
return {"paid": True, "preimage": payment.preimage}
|
||||
|
||||
try:
|
||||
await payment.check_pending()
|
||||
except Exception:
|
||||
return {"paid": False}, HTTPStatus.OK
|
||||
return {"paid": False}
|
||||
|
||||
return {"paid": not payment.pending, "preimage": payment.preimage}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ async def lnurlwallet(request: Request):
|
|||
async def manifest(usr: str):
|
||||
user = await get_user(usr)
|
||||
if not user:
|
||||
return "", HTTPStatus.NOT_FOUND
|
||||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
|
||||
|
||||
return {
|
||||
"short_name": "LNbits",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
import datetime
|
||||
from http import HTTPStatus
|
||||
|
||||
from fastapi import HTTPException
|
||||
from lnbits import bolt11
|
||||
|
||||
from .. import core_app
|
||||
|
@ -14,17 +14,23 @@ async def api_public_payment_longpolling(payment_hash):
|
|||
payment = await get_standalone_payment(payment_hash)
|
||||
|
||||
if not payment:
|
||||
return {"message": "Payment does not exist."}, HTTPStatus.NOT_FOUND
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Payment does not exist."
|
||||
)
|
||||
elif not payment.pending:
|
||||
return {"status": "paid"}, HTTPStatus.OK
|
||||
return {"status": "paid"}
|
||||
|
||||
try:
|
||||
invoice = bolt11.decode(payment.bolt11)
|
||||
expiration = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
||||
if expiration < datetime.datetime.now():
|
||||
return {"status": "expired"}, HTTPStatus.OK
|
||||
return {"status": "expired"}
|
||||
except:
|
||||
return {"message": "Invalid bolt11 invoice."}, HTTPStatus.BAD_REQUEST
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Invalid bolt11 invoice."
|
||||
)
|
||||
|
||||
payment_queue = asyncio.Queue(0)
|
||||
|
||||
|
@ -37,7 +43,7 @@ async def api_public_payment_longpolling(payment_hash):
|
|||
async for payment in payment_queue.get():
|
||||
if payment.payment_hash == payment_hash:
|
||||
nonlocal response
|
||||
response = ({"status": "paid"}, HTTPStatus.OK)
|
||||
response = {"status": "paid"}
|
||||
cancel_scope.cancel()
|
||||
|
||||
async def timeouter(cancel_scope):
|
||||
|
@ -51,4 +57,7 @@ async def api_public_payment_longpolling(payment_hash):
|
|||
if response:
|
||||
return response
|
||||
else:
|
||||
return {"message": "timeout"}, HTTPStatus.REQUEST_TIMEOUT
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.REQUEST_TIMEOUT,
|
||||
detail="timeout"
|
||||
)
|
||||
|
|
|
@ -4,6 +4,8 @@ import traceback
|
|||
from http import HTTPStatus
|
||||
from typing import List, Callable
|
||||
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from lnbits.settings import WALLET
|
||||
from lnbits.core.crud import (
|
||||
get_payments,
|
||||
|
@ -61,7 +63,7 @@ async def webhook_handler():
|
|||
handler = getattr(WALLET, "webhook_listener", None)
|
||||
if handler:
|
||||
return await handler()
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
internal_invoice_queue = asyncio.Queue(0)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import asyncio
|
||||
from fastapi.exceptions import HTTPException
|
||||
import httpx
|
||||
from os import getenv
|
||||
from http import HTTPStatus
|
||||
|
@ -133,7 +134,7 @@ class LNPayWallet(Wallet):
|
|||
or "event" not in data
|
||||
or data["event"].get("name") != "wallet_receive"
|
||||
):
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
lntx_id = data["data"]["wtx"]["lnTx"]["id"]
|
||||
async with httpx.AsyncClient() as client:
|
||||
|
@ -145,4 +146,5 @@ class LNPayWallet(Wallet):
|
|||
if data["settled"]:
|
||||
await self.queue.put(lntx_id)
|
||||
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import asyncio
|
||||
|
||||
from fastapi.exceptions import HTTPException
|
||||
from lnbits.helpers import url_for
|
||||
import hmac
|
||||
import httpx
|
||||
|
@ -133,14 +135,16 @@ class OpenNodeWallet(Wallet):
|
|||
async def webhook_listener(self):
|
||||
data = await request.form
|
||||
if "status" not in data or data["status"] != "paid":
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
charge_id = data["id"]
|
||||
x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
|
||||
x.update(charge_id.encode("ascii"))
|
||||
if x.hexdigest() != data["hashed_order"]:
|
||||
print("invalid webhook, not from opennode")
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
await self.queue.put(charge_id)
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user