mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-19 12:01:12 +02:00
[REFACTOR] proper create_invoice responses for descriptions (#1863)
* [REFACTOR] proper create_invoice responses for descriptions return a exception per error it is description hash or unhashed_description keep types * Update lnbits/core/views/api.py Co-authored-by: michael1011 <me@michael1011.at> * Update lnbits/core/views/api.py Co-authored-by: michael1011 <me@michael1011.at> --------- Co-authored-by: michael1011 <me@michael1011.at>
This commit is contained in:
@@ -187,30 +187,29 @@ async def api_payments_paginated(
|
|||||||
|
|
||||||
|
|
||||||
async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
|
async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
|
||||||
extra = data.extra or {}
|
data.extra = data.extra or {}
|
||||||
|
description_hash = b""
|
||||||
|
unhashed_description = b""
|
||||||
|
memo = data.memo or settings.lnbits_site_title
|
||||||
if data.description_hash or data.unhashed_description:
|
if data.description_hash or data.unhashed_description:
|
||||||
try:
|
if data.description_hash:
|
||||||
description_hash = (
|
try:
|
||||||
bytes.fromhex(data.description_hash) if data.description_hash else b""
|
description_hash = bytes.fromhex(data.description_hash)
|
||||||
)
|
except ValueError:
|
||||||
unhashed_description = (
|
raise HTTPException(
|
||||||
bytes.fromhex(data.unhashed_description)
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
if data.unhashed_description
|
detail="'description_hash' must be a valid hex string",
|
||||||
else b""
|
)
|
||||||
)
|
if data.unhashed_description:
|
||||||
except ValueError:
|
try:
|
||||||
raise HTTPException(
|
unhashed_description = bytes.fromhex(data.unhashed_description)
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
except ValueError:
|
||||||
detail=(
|
raise HTTPException(
|
||||||
"'description_hash' and 'unhashed_description' "
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
"must be a valid hex strings"
|
detail="'unhashed_description' must be a valid hex string",
|
||||||
),
|
)
|
||||||
)
|
# do not save memo if description_hash or unhashed_description is set
|
||||||
memo = ""
|
memo = ""
|
||||||
else:
|
|
||||||
description_hash = b""
|
|
||||||
unhashed_description = b""
|
|
||||||
memo = data.memo or settings.lnbits_site_title
|
|
||||||
|
|
||||||
if data.unit == "sat":
|
if data.unit == "sat":
|
||||||
amount = int(data.amount)
|
amount = int(data.amount)
|
||||||
@@ -218,7 +217,7 @@ async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
|
|||||||
assert data.unit is not None, "unit not set"
|
assert data.unit is not None, "unit not set"
|
||||||
price_in_sats = await fiat_amount_as_satoshis(data.amount, data.unit)
|
price_in_sats = await fiat_amount_as_satoshis(data.amount, data.unit)
|
||||||
amount = price_in_sats
|
amount = price_in_sats
|
||||||
extra.update({"fiat_amount": data.amount, "fiat_currency": data.unit})
|
data.extra.update({"fiat_amount": data.amount, "fiat_currency": data.unit})
|
||||||
|
|
||||||
async with db.connect() as conn:
|
async with db.connect() as conn:
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user