Mint: add expiry to quotes, closes #385 (#429)

* add expiry to quotes, closes #385

* fix wallet deprecated mock with expiry

* expiry is an optional field
This commit is contained in:
callebtc
2024-02-16 11:40:46 +01:00
committed by GitHub
parent ecad95715f
commit 3f090c1691
6 changed files with 13 additions and 6 deletions

View File

@@ -230,6 +230,7 @@ class MeltQuote(BaseModel):
paid_time: Union[int, None] = None
fee_paid: int = 0
proof: str = ""
expiry: Optional[int] = None
@classmethod
def from_row(cls, row: Row):
@@ -269,7 +270,7 @@ class MintQuote(BaseModel):
issued: bool
created_time: Union[int, None] = None
paid_time: Union[int, None] = None
expiry: int = 0
expiry: Optional[int] = None
@classmethod
def from_row(cls, row: Row):
@@ -295,7 +296,6 @@ class MintQuote(BaseModel):
issued=row["issued"],
created_time=created_time,
paid_time=paid_time,
expiry=0,
)
@@ -370,7 +370,7 @@ class PostMintQuoteResponse(BaseModel):
quote: str # quote id
request: str # input payment request
paid: bool # whether the request has been paid
expiry: int # expiry of the quote
expiry: Optional[int] # expiry of the quote
# ------- API: MINT -------
@@ -417,6 +417,7 @@ class PostMeltQuoteResponse(BaseModel):
amount: int # input amount
fee_reserve: int # input fee reserve
paid: bool # whether the request has been paid
expiry: Optional[int] # expiry of the quote
# ------- API: MELT -------

View File

@@ -66,8 +66,7 @@ class FakeWallet(LightningBackend):
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()

View File

@@ -353,7 +353,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
issued=False,
paid=False,
created_time=int(time.time()),
expiry=invoice_obj.expiry or 0,
expiry=invoice_obj.expiry,
)
await self.crud.store_mint_quote(
quote=quote,
@@ -507,6 +507,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
paid=False,
fee_reserve=payment_quote.fee.to(unit).amount,
created_time=int(time.time()),
expiry=invoice_obj.expiry,
)
await self.crud.store_melt_quote(quote=quote, db=self.db)
return PostMeltQuoteResponse(
@@ -514,6 +515,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
amount=quote.amount,
fee_reserve=quote.fee_reserve,
paid=quote.paid,
expiry=quote.expiry,
)
async def get_melt_quote(self, quote_id: str) -> MeltQuote:

View File

@@ -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

View File

@@ -543,6 +543,7 @@ class LedgerAPI(LedgerAPIDeprecated, object):
amount=invoice_obj.amount_msat // 1000,
fee_reserve=ret.fee or 0,
paid=False,
expiry=invoice_obj.expiry,
)
# END backwards compatibility < 0.15.0
self.raise_on_error_request(resp)

View File

@@ -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(
@@ -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(