Form works, check LNURL is valid url

This commit is contained in:
benarc
2021-12-02 22:56:31 +00:00
parent ccc52dc585
commit cacee8d072
3 changed files with 9 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ async def create_lnurlpayout(wallet_id: str, data: CreateLnurlPayoutData) -> lnu
INSERT INTO lnurlpayout.lnurlpayouts (id, wallet, lnurlpay, threshold) INSERT INTO lnurlpayout.lnurlpayouts (id, wallet, lnurlpay, threshold)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
""", """,
(lnurlpayout_id, wallet_id, data.name, data.currency), (lnurlpayout_id, wallet_id, data.lnurlpay, data.threshold),
) )
lnurlpayout = await get_lnurlpayout(lnurlpayout_id) lnurlpayout = await get_lnurlpayout(lnurlpayout_id)
@@ -23,8 +23,7 @@ async def create_lnurlpayout(wallet_id: str, data: CreateLnurlPayoutData) -> lnu
async def get_lnurlpayout(lnurlpayout_id: str) -> Optional[lnurlpayout]: async def get_lnurlpayout(lnurlpayout_id: str) -> Optional[lnurlpayout]:
row = await db.fetchone("SELECT * FROM lnurlpayout.lnurlpayouts WHERE id = ?", (lnurlpayout_id,)) row = await db.fetchone("SELECT * FROM lnurlpayout.lnurlpayouts WHERE id = ?", (lnurlpayout_id,))
return lnurlpayout.from_row(row) if row else None return lnurlpayout(**row) if row else None
async def get_lnurlpayouts(wallet_ids: Union[str, List[str]]) -> List[lnurlpayout]: async def get_lnurlpayouts(wallet_ids: Union[str, List[str]]) -> List[lnurlpayout]:
if isinstance(wallet_ids, str): if isinstance(wallet_ids, str):
@@ -35,7 +34,7 @@ async def get_lnurlpayouts(wallet_ids: Union[str, List[str]]) -> List[lnurlpayou
f"SELECT * FROM lnurlpayout.lnurlpayouts WHERE wallet IN ({q})", (*wallet_ids,) f"SELECT * FROM lnurlpayout.lnurlpayouts WHERE wallet IN ({q})", (*wallet_ids,)
) )
return [lnurlpayout.from_row(row) for row in rows] return [lnurlpayout(**row) if row else None for row in rows]
async def delete_lnurlpayout(lnurlpayout_id: str) -> None: async def delete_lnurlpayout(lnurlpayout_id: str) -> None:

View File

@@ -3,7 +3,6 @@ from sqlite3 import Row
from pydantic import BaseModel from pydantic import BaseModel
class CreateLnurlPayoutData(BaseModel): class CreateLnurlPayoutData(BaseModel):
wallet: str
lnurlpay: str lnurlpay: str
threshold: int threshold: int

View File

@@ -6,7 +6,7 @@ from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment, api_payments_decode
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from . import lnurlpayout_ext from . import lnurlpayout_ext
@@ -29,9 +29,11 @@ async def api_lnurlpayouts(
async def api_lnurlpayout_create( async def api_lnurlpayout_create(
data: CreateLnurlPayoutData, wallet: WalletTypeInfo = Depends(get_key_type) data: CreateLnurlPayoutData, wallet: WalletTypeInfo = Depends(get_key_type)
): ):
print("data") url = api_payments_decode(data.lnurlpay)
# lnurlpayout = await create_lnurlpayout(wallet_id=wallet.wallet.id, data=data) if url[0:4] != "http":
return #lnurlpayout.dict() raise PermissionError("Not valid LNURL")
lnurlpayout = await create_lnurlpayout(wallet_id=wallet.wallet.id, data=data)
return lnurlpayout.dict()
@lnurlpayout_ext.delete("/api/v1/lnurlpayouts/{lnurlpayout_id}") @lnurlpayout_ext.delete("/api/v1/lnurlpayouts/{lnurlpayout_id}")