mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-01 02:51:29 +02:00
blacked
This commit is contained in:
@ -31,9 +31,7 @@ async def create_scrub_link(data: CreateScrubLink) -> ScrubLink:
|
|||||||
|
|
||||||
|
|
||||||
async def get_scrub_link(link_id: str) -> Optional[ScrubLink]:
|
async def get_scrub_link(link_id: str) -> Optional[ScrubLink]:
|
||||||
row = await db.fetchone(
|
row = await db.fetchone("SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
||||||
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
|
|
||||||
)
|
|
||||||
return ScrubLink(**row) if row else None
|
return ScrubLink(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
@ -58,14 +56,14 @@ async def update_scrub_link(link_id: int, **kwargs) -> Optional[ScrubLink]:
|
|||||||
f"UPDATE scrub.scrub_links SET {q} WHERE id = ?",
|
f"UPDATE scrub.scrub_links SET {q} WHERE id = ?",
|
||||||
(*kwargs.values(), link_id),
|
(*kwargs.values(), link_id),
|
||||||
)
|
)
|
||||||
row = await db.fetchone(
|
row = await db.fetchone("SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
||||||
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
|
|
||||||
)
|
|
||||||
return ScrubLink(**row) if row else None
|
return ScrubLink(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def delete_scrub_link(link_id: int) -> None:
|
async def delete_scrub_link(link_id: int) -> None:
|
||||||
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
||||||
|
|
||||||
|
|
||||||
async def get_scrub_by_wallet(wallet_id) -> Optional[ScrubLink]:
|
async def get_scrub_by_wallet(wallet_id) -> Optional[ScrubLink]:
|
||||||
row = await db.fetchone(
|
row = await db.fetchone(
|
||||||
"SELECT * from scrub.scrub_links WHERE wallet = ?",
|
"SELECT * from scrub.scrub_links WHERE wallet = ?",
|
||||||
@ -73,8 +71,9 @@ async def get_scrub_by_wallet(wallet_id) -> Optional[ScrubLink]:
|
|||||||
)
|
)
|
||||||
return ScrubLink(**row) if row else None
|
return ScrubLink(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def unique_scrubed_wallet(wallet_id):
|
async def unique_scrubed_wallet(wallet_id):
|
||||||
row, = await db.fetchone(
|
(row,) = await db.fetchone(
|
||||||
"SELECT COUNT(wallet) FROM scrub.scrub_links WHERE wallet = ?",
|
"SELECT COUNT(wallet) FROM scrub.scrub_links WHERE wallet = ?",
|
||||||
(wallet_id,),
|
(wallet_id,),
|
||||||
)
|
)
|
||||||
|
@ -11,4 +11,4 @@ async def m001_initial(db):
|
|||||||
payoraddress TEXT NOT NULL
|
payoraddress TEXT NOT NULL
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
scrub_link = await get_scrub_by_wallet(payment.wallet_id)
|
scrub_link = await get_scrub_by_wallet(payment.wallet_id)
|
||||||
|
|
||||||
if not scrub_link:
|
if not scrub_link:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -38,8 +38,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
|
|
||||||
# DECODE LNURLP OR LNADDRESS
|
# DECODE LNURLP OR LNADDRESS
|
||||||
data = await api_lnurlscan(scrub_link.payoraddress)
|
data = await api_lnurlscan(scrub_link.payoraddress)
|
||||||
|
|
||||||
|
|
||||||
# I REALLY HATE THIS DUPLICATION OF CODE!! CORE/VIEWS/API.PY, LINE 267
|
# I REALLY HATE THIS DUPLICATION OF CODE!! CORE/VIEWS/API.PY, LINE 267
|
||||||
domain = urlparse(data["callback"]).netloc
|
domain = urlparse(data["callback"]).netloc
|
||||||
|
|
||||||
@ -64,14 +63,14 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=f"{domain} said: '{params.get('reason', '')}'",
|
detail=f"{domain} said: '{params.get('reason', '')}'",
|
||||||
)
|
)
|
||||||
|
|
||||||
invoice = bolt11.decode(params["pr"])
|
invoice = bolt11.decode(params["pr"])
|
||||||
if invoice.amount_msat != payment.amount:
|
if invoice.amount_msat != payment.amount:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=f"{domain} returned an invalid invoice. Expected {payment.amount} msat, got {invoice.amount_msat}.",
|
detail=f"{domain} returned an invalid invoice. Expected {payment.amount} msat, got {invoice.amount_msat}.",
|
||||||
)
|
)
|
||||||
|
|
||||||
payment_hash = await pay_invoice(
|
payment_hash = await pay_invoice(
|
||||||
wallet_id=payment.wallet_id,
|
wallet_id=payment.wallet_id,
|
||||||
payment_request=params["pr"],
|
payment_request=params["pr"],
|
||||||
|
@ -33,10 +33,7 @@ async def api_links(
|
|||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return [
|
return [link.dict() for link in await get_scrub_links(wallet_ids)]
|
||||||
link.dict()
|
|
||||||
for link in await get_scrub_links(wallet_ids)
|
|
||||||
]
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -44,6 +41,7 @@ async def api_links(
|
|||||||
detail="No SCRUB links made yet",
|
detail="No SCRUB links made yet",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
@scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||||
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)
|
||||||
@ -63,8 +61,6 @@ async def api_link_retrieve(
|
|||||||
return link
|
return link
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@scrub_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
@scrub_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
||||||
@scrub_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
@scrub_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||||
async def api_scrub_create_or_update(
|
async def api_scrub_create_or_update(
|
||||||
@ -90,7 +86,8 @@ async def api_scrub_create_or_update(
|
|||||||
wallet_has_scrub = await unique_scrubed_wallet(wallet_id=data.wallet)
|
wallet_has_scrub = await unique_scrubed_wallet(wallet_id=data.wallet)
|
||||||
if wallet_has_scrub > 0:
|
if wallet_has_scrub > 0:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
detail="Wallet is already being Scrubbed", status_code=HTTPStatus.FORBIDDEN
|
detail="Wallet is already being Scrubbed",
|
||||||
|
status_code=HTTPStatus.FORBIDDEN,
|
||||||
)
|
)
|
||||||
link = await create_scrub_link(data=data)
|
link = await create_scrub_link(data=data)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user