fix: check invoice amount against blinded message amount

This commit is contained in:
Vlad Stan
2022-10-07 20:27:40 +03:00
committed by dni ⚡
parent e842c3df52
commit f27632eb8e
2 changed files with 12 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ from typing import List, Union
from pydantic import BaseModel
class CashuError(BaseModel):
class CashuError(BaseException):
code = "000"
error = "CashuError"

View File

@@ -284,6 +284,13 @@ async def mint_coins(
detail="Tokens already issued for this invoice.",
)
total_requested = sum([bm.amount for bm in data.blinded_messages])
if total_requested > invoice.amount:
# raise CashuError(error = f"Requested amount to high: {total_requested}. Invoice amount: {invoice.amount}")
raise HTTPException(
status_code=HTTPStatus.PAYMENT_REQUIRED, detail=f"Requested amount to high: {total_requested}. Invoice amount: {invoice.amount}"
)
status: PaymentStatus = await check_transaction_status(cashu.wallet, payment_hash)
# todo: revert to: status.paid != True:
if status.paid != True:
@@ -299,11 +306,11 @@ async def mint_coins(
amounts.append(payload.amount)
B_s.append(PublicKey(bytes.fromhex(payload.B_), raw=True))
promises = await generate_promises(cashu.prvkey, amounts, B_s)
for amount, B_, p in zip(amounts, B_s, promises):
await store_promise(amount, B_.serialize().hex(), p.C_, cashu_id)
promises = await generate_promises(cashu.prvkey, amounts, B_s)
for amount, B_, p in zip(amounts, B_s, promises):
await store_promise(amount, B_.serialize().hex(), p.C_, cashu_id)
return promises
return promises
except Exception as e:
logger.error(e)
raise HTTPException(