Skip to content

Commit

Permalink
return paid
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Apr 20, 2024
1 parent 8516c46 commit 35a4c4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cashu/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cashu/gateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 5 additions & 6 deletions cashu/gateway/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from loguru import logger

from ..core.base import (
PostMeltQuoteResponse,
PostMeltResponse,
)
from .models import (
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 35a4c4e

Please sign in to comment.