mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 12:26:19 +02:00
Merge pull request #377 from arcbtc/FastAPI
restored create invoice api endpoint
This commit is contained in:
@@ -50,11 +50,12 @@ async def create_invoice(
|
||||
webhook: Optional[str] = None,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> Tuple[str, str]:
|
||||
invoice_memo = None if description_hash else memo
|
||||
storeable_memo = memo or "LN payment"
|
||||
|
||||
if not memo:
|
||||
memo = "LN payment"
|
||||
# invoice_memo = None if description_hash else memo
|
||||
# storeable_memo = memo
|
||||
ok, checking_id, payment_request, error_message = await WALLET.create_invoice(
|
||||
amount=amount, memo=invoice_memo, description_hash=description_hash
|
||||
amount=amount, memo=memo, description_hash=description_hash
|
||||
)
|
||||
if not ok:
|
||||
raise InvoiceFailure(error_message or "Unexpected backend error.")
|
||||
|
@@ -1,20 +1,21 @@
|
||||
import time
|
||||
from base64 import urlsafe_b64encode
|
||||
from pydantic import BaseModel
|
||||
from http import HTTPStatus
|
||||
|
||||
from lnbits.core.services import pay_invoice, create_invoice
|
||||
from lnbits.core.crud import get_payments, delete_expired_invoices
|
||||
from fastapi.param_functions import Query
|
||||
from fastapi.params import Depends
|
||||
from pydantic import BaseModel
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits import bolt11
|
||||
from lnbits.core.crud import delete_expired_invoices, get_payments
|
||||
from lnbits.core.services import create_invoice, pay_invoice
|
||||
from lnbits.decorators import WalletTypeInfo
|
||||
from lnbits.settings import WALLET
|
||||
from lnbits import bolt11
|
||||
|
||||
from . import lndhub_ext
|
||||
from .decorators import check_wallet, require_admin_key
|
||||
from .utils import to_buffer, decoded_as_lndhub
|
||||
from http import HTTPStatus
|
||||
from starlette.exceptions import HTTPException
|
||||
from fastapi.params import Depends
|
||||
from fastapi.param_functions import Query
|
||||
from .utils import decoded_as_lndhub, to_buffer
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/getinfo")
|
||||
@@ -41,8 +42,8 @@ async def lndhub_auth(data: AuthData):
|
||||
|
||||
|
||||
class AddInvoice(BaseModel):
|
||||
amt: str = Query(None)
|
||||
memo: str = Query(None)
|
||||
amt: str = Query(...)
|
||||
memo: str = Query(...)
|
||||
preimage: str = Query(None)
|
||||
|
||||
|
||||
@@ -54,7 +55,7 @@ async def lndhub_addinvoice(
|
||||
_, pr = await create_invoice(
|
||||
wallet_id=wallet.wallet.id,
|
||||
amount=int(data.amt),
|
||||
memo=data.memo,
|
||||
memo=data.memo or "received sats",
|
||||
extra={"tag": "lndhub"},
|
||||
)
|
||||
except:
|
||||
@@ -73,7 +74,7 @@ async def lndhub_addinvoice(
|
||||
|
||||
|
||||
class Invoice(BaseModel):
|
||||
invoice: str
|
||||
invoice: str = Query(...)
|
||||
|
||||
|
||||
@lndhub_ext.post("/ext/payinvoice")
|
||||
@@ -90,7 +91,7 @@ async def lndhub_payinvoice(
|
||||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Payment failed")
|
||||
|
||||
invoice: bolt11.Invoice = bolt11.decode(r_invoice.invoice)
|
||||
print("INV2", invoice)
|
||||
|
||||
return {
|
||||
"payment_error": "",
|
||||
"payment_preimage": "0" * 64,
|
||||
|
@@ -82,7 +82,6 @@ async def api_lnurl_callback(request: Request, link_id):
|
||||
return LnurlErrorResponse(
|
||||
reason=f"Got a comment with {len(comment)} characters, but can only accept {link.comment_chars}"
|
||||
).dict()
|
||||
|
||||
payment_hash, payment_request = await create_invoice(
|
||||
wallet_id=link.wallet,
|
||||
amount=int(amount_received / 1000),
|
||||
|
Reference in New Issue
Block a user