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