diff --git a/lnbits/extensions/lnurlp/views_api.py b/lnbits/extensions/lnurlp/views_api.py index 94e15e3a..d01cf1b1 100644 --- a/lnbits/extensions/lnurlp/views_api.py +++ b/lnbits/extensions/lnurlp/views_api.py @@ -27,7 +27,6 @@ async def api_list_currencies_available(): @lnurlp_ext.get("/api/v1/links", status_code=HTTPStatus.OK) -# @api_check_wallet_key("invoice") async def api_links( req: Request, wallet: WalletTypeInfo = Depends(get_key_type), @@ -43,26 +42,15 @@ async def api_links( {**link.dict(), "lnurl": link.lnurl(req)} for link in await get_pay_links(wallet_ids) ] - # return [ - # {**link.dict(), "lnurl": link.lnurl} - # for link in await get_pay_links(wallet_ids) - # ] except LnurlInvalidUrl: raise HTTPException( status_code=HTTPStatus.UPGRADE_REQUIRED, detail="LNURLs need to be delivered over a publically accessible `https` domain or Tor.", ) - # return ( - # { - # "message": "LNURLs need to be delivered over a publically accessible `https` domain or Tor." - # }, - # HTTPStatus.UPGRADE_REQUIRED, - # ) @lnurlp_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK) -# @api_check_wallet_key("invoice") async def api_link_retrieve( r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type) ): @@ -72,20 +60,17 @@ async def api_link_retrieve( raise HTTPException( detail="Pay link does not exist.", status_code=HTTPStatus.NOT_FOUND ) - # return {"message": "Pay link does not exist."}, HTTPStatus.NOT_FOUND if link.wallet != wallet.wallet.id: raise HTTPException( detail="Not your pay link.", status_code=HTTPStatus.FORBIDDEN ) - # return {"message": "Not your pay link."}, HTTPStatus.FORBIDDEN return {**link._asdict(), **{"lnurl": link.lnurl(r)}} @lnurlp_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED) @lnurlp_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK) -# @api_check_wallet_key("invoice") async def api_link_create_or_update( data: CreatePayLinkData, link_id=None, @@ -95,7 +80,6 @@ async def api_link_create_or_update( raise HTTPException( detail="Min is greater than max.", status_code=HTTPStatus.BAD_REQUEST ) - # return {"message": "Min is greater than max."}, HTTPStatus.BAD_REQUEST if data.currency == None and ( round(data.min) != data.min or round(data.max) != data.max @@ -103,17 +87,12 @@ async def api_link_create_or_update( raise HTTPException( detail="Must use full satoshis.", status_code=HTTPStatus.BAD_REQUEST ) - # return {"message": "Must use full satoshis."}, HTTPStatus.BAD_REQUEST if "success_url" in data and data.success_url[:8] != "https://": raise HTTPException( detail="Success URL must be secure https://...", status_code=HTTPStatus.BAD_REQUEST, ) - # return ( - # {"message": "Success URL must be secure https://..."}, - # HTTPStatus.BAD_REQUEST, - # ) if link_id: link = await get_pay_link(link_id) @@ -122,18 +101,13 @@ async def api_link_create_or_update( raise HTTPException( detail="Pay link does not exist.", status_code=HTTPStatus.NOT_FOUND ) - # return ( - # {"message": "Pay link does not exist."}, - # HTTPStatus.NOT_FOUND, - # ) if link.wallet != wallet.wallet.id: raise HTTPException( detail="Not your pay link.", status_code=HTTPStatus.FORBIDDEN ) - # return {"message": "Not your pay link."}, HTTPStatus.FORBIDDEN - link = await update_pay_link(data, link_id=link_id) + link = await update_pay_link(**data.dict(), link_id=link_id) else: link = await create_pay_link(data, wallet_id=wallet.wallet.id) print("LINK", link) @@ -141,7 +115,6 @@ async def api_link_create_or_update( @lnurlp_ext.delete("/api/v1/links/{link_id}") -# @api_check_wallet_key("invoice") async def api_link_delete(link_id, wallet: WalletTypeInfo = Depends(get_key_type)): link = await get_pay_link(link_id) @@ -149,17 +122,14 @@ async def api_link_delete(link_id, wallet: WalletTypeInfo = Depends(get_key_type raise HTTPException( detail="Pay link does not exist.", status_code=HTTPStatus.NOT_FOUND ) - # return {"message": "Pay link does not exist."}, HTTPStatus.NOT_FOUND if link.wallet != wallet.wallet.id: raise HTTPException( detail="Not your pay link.", status_code=HTTPStatus.FORBIDDEN ) - # return {"message": "Not your pay link."}, HTTPStatus.FORBIDDEN await delete_pay_link(link_id) raise HTTPException(status_code=HTTPStatus.NO_CONTENT) - # return "", HTTPStatus.NO_CONTENT @lnurlp_ext.get("/api/v1/rate/{currency}", status_code=HTTPStatus.OK)