Skip to content

Commit

Permalink
add expiry to quotes, closes #385
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Feb 16, 2024
1 parent ecad957 commit 846e998
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class MeltQuote(BaseModel):
paid_time: Union[int, None] = None
fee_paid: int = 0
proof: str = ""
expiry: int = 0

@classmethod
def from_row(cls, row: Row):
Expand Down Expand Up @@ -417,6 +418,7 @@ class PostMeltQuoteResponse(BaseModel):
amount: int # input amount
fee_reserve: int # input fee reserve
paid: bool # whether the request has been paid
expiry: int # expiry of the quote


# ------- API: MELT -------
Expand Down
3 changes: 1 addition & 2 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ async def create_invoice(
else:
tags.add(TagChar.description, memo or "")

if expiry:
tags.add(TagChar.expire_time, expiry)
tags.add(TagChar.expire_time, expiry or 3600)

if payment_secret:
secret = payment_secret.hex()
Expand Down
2 changes: 2 additions & 0 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,15 @@ async def melt_quote(
paid=False,
fee_reserve=payment_quote.fee.to(unit).amount,
created_time=int(time.time()),
expiry=invoice_obj.expiry or 0,
)
await self.crud.store_melt_quote(quote=quote, db=self.db)
return PostMeltQuoteResponse(
quote=quote.quote,
amount=quote.amount,
fee_reserve=quote.fee_reserve,
paid=quote.paid,
expiry=quote.expiry,
)

async def get_melt_quote(self, quote_id: str) -> MeltQuote:
Expand Down
1 change: 1 addition & 0 deletions cashu/mint/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def melt_quote(quote: str) -> PostMeltQuoteResponse:
amount=melt_quote.amount,
fee_reserve=melt_quote.fee_reserve,
paid=melt_quote.paid,
expiry=melt_quote.expiry,
)
logger.trace(f"< GET /v1/melt/quote/bolt11/{quote}")
return resp
Expand Down
3 changes: 3 additions & 0 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ async def test_mint_quote(ledger: Ledger):
assert result["request"]
invoice = bolt11.decode(result["request"])
assert invoice.amount_msat == 100 * 1000
assert result["expiry"] == invoice.expiry

# get mint quote again from api
response = httpx.get(
Expand Down Expand Up @@ -243,6 +244,8 @@ async def test_melt_quote_internal(ledger: Ledger, wallet: Wallet):
assert result["amount"] == 64
# TODO: internal invoice, fee should be 0
assert result["fee_reserve"] == 0
invoice_obj = bolt11.decode(request)
assert result["expiry"] == invoice_obj.expiry

# get melt quote again from api
response = httpx.get(
Expand Down

0 comments on commit 846e998

Please sign in to comment.