From 35a4c4e729281eb1e7a81de978c6ad28940f37ad Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:48:12 +0200 Subject: [PATCH] return paid --- cashu/gateway/gateway.py | 6 +++--- cashu/gateway/models.py | 1 + cashu/gateway/router.py | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cashu/gateway/gateway.py b/cashu/gateway/gateway.py index fd2f0f77..ac203d86 100644 --- a/cashu/gateway/gateway.py +++ b/cashu/gateway/gateway.py @@ -156,6 +156,7 @@ async def melt_quote( quote=melt_quote.quote, amount=melt_quote.amount, expiry=melt_quote.expiry, + paid=melt_quote.paid, ) async def get_melt_quote( @@ -166,9 +167,7 @@ async def get_melt_quote( raise TransactionError("quote not found") if not melt_quote.expiry: raise TransactionError("quote does not have expiry") - if check_quote_with_backend: - if melt_quote.paid: - raise TransactionError("quote is already paid") + if check_quote_with_backend and not melt_quote.paid: unit = Unit[melt_quote.unit] if unit not in self.backends[Method.bolt11]: raise Exception("unit not supported by backend") @@ -187,6 +186,7 @@ async def get_melt_quote( quote=melt_quote.quote, amount=melt_quote.amount, expiry=melt_quote.expiry, + paid=melt_quote.paid, ) def _verify_input_spending_conditions( diff --git a/cashu/gateway/models.py b/cashu/gateway/models.py index a7f51950..4668a3bd 100644 --- a/cashu/gateway/models.py +++ b/cashu/gateway/models.py @@ -21,6 +21,7 @@ class GatewayMeltQuoteResponse(BaseModel): pubkey: str # P2PK pubkey of the gateway amount: int # input amount expiry: int # expiry of the quote + paid: bool # whether the quote has been paid class GatewayMeltRequest(BaseModel): diff --git a/cashu/gateway/router.py b/cashu/gateway/router.py index 19b9aedb..5fc60444 100644 --- a/cashu/gateway/router.py +++ b/cashu/gateway/router.py @@ -2,7 +2,6 @@ from loguru import logger from ..core.base import ( - PostMeltQuoteResponse, PostMeltResponse, ) from .models import ( @@ -37,19 +36,19 @@ async def get_melt_quote( @router.get( "/v1/melt/quote/bolt11/{quote}", summary="Get melt quote", - response_model=PostMeltQuoteResponse, + response_model=GatewayMeltQuoteResponse, response_description="Get an existing melt quote to check its status.", ) -async def melt_quote(request: Request, quote: str) -> PostMeltQuoteResponse: +async def melt_quote(request: Request, quote: str) -> GatewayMeltQuoteResponse: """ Get melt quote state. """ logger.trace(f"> GET /v1/melt/quote/bolt11/{quote}") - melt_quote = await gateway.get_melt_quote(quote) - resp = PostMeltQuoteResponse( + melt_quote = await gateway.get_melt_quote(quote, check_quote_with_backend=True) + resp = GatewayMeltQuoteResponse( + pubkey=melt_quote.pubkey, quote=melt_quote.quote, amount=melt_quote.amount, - fee_reserve=melt_quote.fee_reserve, paid=melt_quote.paid, expiry=melt_quote.expiry, )