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