This commit is contained in:
Tiago vasconcelos
2022-07-05 16:21:49 +01:00
parent c8a6caa4e3
commit 42d342cd0d
4 changed files with 15 additions and 20 deletions

View File

@ -31,9 +31,7 @@ async def create_scrub_link(data: CreateScrubLink) -> ScrubLink:
async def get_scrub_link(link_id: str) -> Optional[ScrubLink]:
row = await db.fetchone(
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
)
row = await db.fetchone("SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,))
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 = ?",
(*kwargs.values(), link_id),
)
row = await db.fetchone(
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
)
row = await db.fetchone("SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,))
return ScrubLink(**row) if row else None
async def delete_scrub_link(link_id: int) -> None:
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
async def get_scrub_by_wallet(wallet_id) -> Optional[ScrubLink]:
row = await db.fetchone(
"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
async def unique_scrubed_wallet(wallet_id):
row, = await db.fetchone(
(row,) = await db.fetchone(
"SELECT COUNT(wallet) FROM scrub.scrub_links WHERE wallet = ?",
(wallet_id,),
)

View File

@ -11,4 +11,4 @@ async def m001_initial(db):
payoraddress TEXT NOT NULL
);
"""
)
)

View File

@ -30,7 +30,7 @@ async def on_invoice_paid(payment: Payment) -> None:
return
scrub_link = await get_scrub_by_wallet(payment.wallet_id)
if not scrub_link:
return
@ -38,8 +38,7 @@ async def on_invoice_paid(payment: Payment) -> None:
# DECODE LNURLP OR LNADDRESS
data = await api_lnurlscan(scrub_link.payoraddress)
# I REALLY HATE THIS DUPLICATION OF CODE!! CORE/VIEWS/API.PY, LINE 267
domain = urlparse(data["callback"]).netloc
@ -64,14 +63,14 @@ async def on_invoice_paid(payment: Payment) -> None:
status_code=HTTPStatus.BAD_REQUEST,
detail=f"{domain} said: '{params.get('reason', '')}'",
)
invoice = bolt11.decode(params["pr"])
if invoice.amount_msat != payment.amount:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=f"{domain} returned an invalid invoice. Expected {payment.amount} msat, got {invoice.amount_msat}.",
)
payment_hash = await pay_invoice(
wallet_id=payment.wallet_id,
payment_request=params["pr"],

View File

@ -33,10 +33,7 @@ async def api_links(
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
try:
return [
link.dict()
for link in await get_scrub_links(wallet_ids)
]
return [link.dict() for link in await get_scrub_links(wallet_ids)]
except:
raise HTTPException(
@ -44,6 +41,7 @@ async def api_links(
detail="No SCRUB links made yet",
)
@scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
async def api_link_retrieve(
r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type)
@ -63,8 +61,6 @@ async def api_link_retrieve(
return link
@scrub_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
@scrub_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
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)
if wallet_has_scrub > 0:
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)