feat: update invoice status

This commit is contained in:
Vlad Stan 2022-10-07 15:18:09 +03:00 committed by dni ⚡
parent cf31d2729d
commit 2757ad2ea9

View File

@ -25,6 +25,7 @@ from .crud import (
get_lightning_invoice, get_lightning_invoice,
store_lightning_invoice, store_lightning_invoice,
store_promise, store_promise,
update_lightning_invoice,
) )
from .ledger import mint, request_mint from .ledger import mint, request_mint
from .mint import generate_promises, get_pubkeys from .mint import generate_promises, get_pubkeys
@ -279,8 +280,10 @@ async def mint_coins(
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Mint does not have this invoice." status_code=HTTPStatus.NOT_FOUND, detail="Mint does not have this invoice."
) )
# if invoice.issued == True: if invoice.issued == True:
# todo: give old tokens? raise HTTPException(
status_code=HTTPStatus.PAYMENT_REQUIRED, detail="Tokens already issued for this invoice."
)
status: PaymentStatus = await check_transaction_status( status: PaymentStatus = await check_transaction_status(
cashu.wallet, payment_hash cashu.wallet, payment_hash
@ -290,6 +293,8 @@ async def mint_coins(
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.PAYMENT_REQUIRED, detail="Invoice not paid." status_code=HTTPStatus.PAYMENT_REQUIRED, detail="Invoice not paid."
) )
try:
await update_lightning_invoice(cashu_id, payment_hash, True)
amounts = [] amounts = []
B_s = [] B_s = []
@ -297,10 +302,11 @@ async def mint_coins(
amounts.append(payload.amount) amounts.append(payload.amount)
B_s.append(PublicKey(bytes.fromhex(payload.B_), raw=True)) B_s.append(PublicKey(bytes.fromhex(payload.B_), raw=True))
try:
promises = await generate_promises(cashu.prvkey, amounts, B_s) promises = await generate_promises(cashu.prvkey, amounts, B_s)
for amount, B_, p in zip(amounts, B_s, promises): for amount, B_, p in zip(amounts, B_s, promises):
await store_promise(amount, B_.serialize().hex(), p.C_, cashu_id) await store_promise(amount, B_.serialize().hex(), p.C_, cashu_id)
return promises return promises
except Exception as exc: except Exception as exc:
return CashuError(error=str(exc)) return CashuError(error=str(exc))