mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-01-18 05:12:58 +01:00
feat: filter response fields for /api/v1/payments/decode
(#2612)
* feat: filter response fields * chore: `make format` * chore: comment * Update lnbits/helpers.py Co-authored-by: Pavol Rusnak <pavol@rusnak.io> * Update lnbits/helpers.py Co-authored-by: Pavol Rusnak <pavol@rusnak.io> * chore: code format --------- Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
parent
94caa2e1ba
commit
80e7b9639d
@ -356,6 +356,7 @@ class Callback(BaseModel):
|
||||
|
||||
class DecodePayment(BaseModel):
|
||||
data: str
|
||||
filter_fields: Optional[list[str]] = []
|
||||
|
||||
|
||||
class CreateLnurl(BaseModel):
|
||||
|
@ -40,7 +40,7 @@ from lnbits.decorators import (
|
||||
require_admin_key,
|
||||
require_invoice_key,
|
||||
)
|
||||
from lnbits.helpers import generate_filter_params_openapi
|
||||
from lnbits.helpers import filter_dict_keys, generate_filter_params_openapi
|
||||
from lnbits.lnurl import decode as lnurl_decode
|
||||
from lnbits.settings import settings
|
||||
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
|
||||
@ -433,7 +433,8 @@ async def api_payments_decode(data: DecodePayment) -> JSONResponse:
|
||||
return JSONResponse({"domain": url})
|
||||
else:
|
||||
invoice = bolt11.decode(payment_str)
|
||||
return JSONResponse(invoice.data)
|
||||
filtered_data = filter_dict_keys(invoice.data, data.filter_fields)
|
||||
return JSONResponse(filtered_data)
|
||||
except Exception as exc:
|
||||
return JSONResponse(
|
||||
{"message": f"Failed to decode: {exc!s}"},
|
||||
|
@ -223,3 +223,10 @@ def decrypt_internal_message(m: Optional[str] = None) -> Optional[str]:
|
||||
if not m:
|
||||
return None
|
||||
return AESCipher(key=settings.auth_secret_key).decrypt(m)
|
||||
|
||||
|
||||
def filter_dict_keys(data: dict, filter_keys: Optional[list[str]]) -> dict:
|
||||
if not filter_keys:
|
||||
# return shallow clone of the dict even if there are no filters
|
||||
return {**data}
|
||||
return {key: data[key] for key in filter_keys if key in data}
|
||||
|
Loading…
Reference in New Issue
Block a user