diff --git a/lnbits/extensions/cashu/core/base.py b/lnbits/extensions/cashu/core/base.py index 0aa02442..4943ee24 100644 --- a/lnbits/extensions/cashu/core/base.py +++ b/lnbits/extensions/cashu/core/base.py @@ -87,10 +87,11 @@ class Invoice(BaseModel): @classmethod def from_row(cls, row: Row): return cls( - amount=int(row[0]), - pr=str(row[1]), - hash=str(row[2]), - issued=bool(row[3]), + cashu_id=str(row[0]), + amount=int(row[1]), + pr=str(row[2]), + hash=str(row[3]), + issued=bool(row[4]), ) diff --git a/lnbits/extensions/cashu/crud.py b/lnbits/extensions/cashu/crud.py index 448614ac..733f4737 100644 --- a/lnbits/extensions/cashu/crud.py +++ b/lnbits/extensions/cashu/crud.py @@ -157,7 +157,7 @@ async def store_lightning_invoice(cashu_id: str, invoice: Invoice): async def get_lightning_invoice(cashu_id: str, hash: str): row = await db.fetchone( """ - SELECT * from invoices + SELECT * from cashu.invoices WHERE cashu_id =? AND hash = ? """, ( @@ -170,7 +170,7 @@ async def get_lightning_invoice(cashu_id: str, hash: str): async def update_lightning_invoice(cashu_id: str, hash: str, issued: bool): await db.execute( - "UPDATE invoices SET issued = ? WHERE cashu_id = ? AND hash = ?", + "UPDATE cashu.invoices SET issued = ? WHERE cashu_id = ? AND hash = ?", ( issued, cashu_id, diff --git a/lnbits/extensions/cashu/models.py b/lnbits/extensions/cashu/models.py index 570387a2..8b5a3417 100644 --- a/lnbits/extensions/cashu/models.py +++ b/lnbits/extensions/cashu/models.py @@ -1,5 +1,5 @@ from sqlite3 import Row -from typing import List, Optional +from typing import List, Union from fastapi import Query from pydantic import BaseModel @@ -146,3 +146,8 @@ class MeltPayload(BaseModel): proofs: List[Proof] amount: int invoice: str + +class CreateTokens(BaseModel): + # cashu_id: str = Query(None) + payloads: MintPayloads + payment_hash: Union[str, None] = None \ No newline at end of file diff --git a/lnbits/extensions/cashu/views_api.py b/lnbits/extensions/cashu/views_api.py index 36a9d105..6f1e161a 100644 --- a/lnbits/extensions/cashu/views_api.py +++ b/lnbits/extensions/cashu/views_api.py @@ -30,6 +30,7 @@ from .mint import get_pubkeys from .models import ( Cashu, CheckPayload, + CreateTokens, Invoice, MeltPayload, MintPayloads, @@ -251,12 +252,11 @@ async def mint_pay_request( return {"pr": payment_request, "hash": payment_hash} -@cashu_ext.post("/mint") +@cashu_ext.post("/api/v1/mint/{cashu_id}") async def mint_coins( - payloads: MintPayloads, - payment_hash: Union[str, None] = None, + data: CreateTokens, cashu_id: str = Query(None), - wallet: WalletTypeInfo = Depends(get_key_type), + wallet: WalletTypeInfo = Depends(require_admin_key), ): """ Requests the minting of tokens belonging to a paid payment request. @@ -268,14 +268,20 @@ async def mint_coins( raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="Mint does not exist." ) - invoice: Invoice = get_lightning_invoice(cashu_id, payment_hash) + invoice: Invoice = ( + None + if data.payment_hash == None + else await get_lightning_invoice(cashu_id, data.payment_hash) + ) if invoice is None: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="Mint does not have this invoice." ) + # if invoice.issued == True: + # todo: give old tokens? - status: PaymentStatus = check_transaction_status(cashu.wallet, payment_hash) - if status.paid == False: + status: PaymentStatus = await check_transaction_status(cashu.wallet, data.payment_hash) + if status.paid != True: raise HTTPException( status_code=HTTPStatus.PAYMENT_REQUIRED, detail="Invoice not paid." )