mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
* add expiry to quotes, closes #385 * fix wallet deprecated mock with expiry * expiry is an optional field
This commit is contained in:
@@ -230,6 +230,7 @@ class MeltQuote(BaseModel):
|
|||||||
paid_time: Union[int, None] = None
|
paid_time: Union[int, None] = None
|
||||||
fee_paid: int = 0
|
fee_paid: int = 0
|
||||||
proof: str = ""
|
proof: str = ""
|
||||||
|
expiry: Optional[int] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row):
|
def from_row(cls, row: Row):
|
||||||
@@ -269,7 +270,7 @@ class MintQuote(BaseModel):
|
|||||||
issued: bool
|
issued: bool
|
||||||
created_time: Union[int, None] = None
|
created_time: Union[int, None] = None
|
||||||
paid_time: Union[int, None] = None
|
paid_time: Union[int, None] = None
|
||||||
expiry: int = 0
|
expiry: Optional[int] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row):
|
def from_row(cls, row: Row):
|
||||||
@@ -295,7 +296,6 @@ class MintQuote(BaseModel):
|
|||||||
issued=row["issued"],
|
issued=row["issued"],
|
||||||
created_time=created_time,
|
created_time=created_time,
|
||||||
paid_time=paid_time,
|
paid_time=paid_time,
|
||||||
expiry=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ class PostMintQuoteResponse(BaseModel):
|
|||||||
quote: str # quote id
|
quote: str # quote id
|
||||||
request: str # input payment request
|
request: str # input payment request
|
||||||
paid: bool # whether the request has been paid
|
paid: bool # whether the request has been paid
|
||||||
expiry: int # expiry of the quote
|
expiry: Optional[int] # expiry of the quote
|
||||||
|
|
||||||
|
|
||||||
# ------- API: MINT -------
|
# ------- API: MINT -------
|
||||||
@@ -417,6 +417,7 @@ class PostMeltQuoteResponse(BaseModel):
|
|||||||
amount: int # input amount
|
amount: int # input amount
|
||||||
fee_reserve: int # input fee reserve
|
fee_reserve: int # input fee reserve
|
||||||
paid: bool # whether the request has been paid
|
paid: bool # whether the request has been paid
|
||||||
|
expiry: Optional[int] # expiry of the quote
|
||||||
|
|
||||||
|
|
||||||
# ------- API: MELT -------
|
# ------- API: MELT -------
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ class FakeWallet(LightningBackend):
|
|||||||
else:
|
else:
|
||||||
tags.add(TagChar.description, memo or "")
|
tags.add(TagChar.description, memo or "")
|
||||||
|
|
||||||
if expiry:
|
tags.add(TagChar.expire_time, expiry or 3600)
|
||||||
tags.add(TagChar.expire_time, expiry)
|
|
||||||
|
|
||||||
if payment_secret:
|
if payment_secret:
|
||||||
secret = payment_secret.hex()
|
secret = payment_secret.hex()
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
|||||||
issued=False,
|
issued=False,
|
||||||
paid=False,
|
paid=False,
|
||||||
created_time=int(time.time()),
|
created_time=int(time.time()),
|
||||||
expiry=invoice_obj.expiry or 0,
|
expiry=invoice_obj.expiry,
|
||||||
)
|
)
|
||||||
await self.crud.store_mint_quote(
|
await self.crud.store_mint_quote(
|
||||||
quote=quote,
|
quote=quote,
|
||||||
@@ -507,6 +507,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
|||||||
paid=False,
|
paid=False,
|
||||||
fee_reserve=payment_quote.fee.to(unit).amount,
|
fee_reserve=payment_quote.fee.to(unit).amount,
|
||||||
created_time=int(time.time()),
|
created_time=int(time.time()),
|
||||||
|
expiry=invoice_obj.expiry,
|
||||||
)
|
)
|
||||||
await self.crud.store_melt_quote(quote=quote, db=self.db)
|
await self.crud.store_melt_quote(quote=quote, db=self.db)
|
||||||
return PostMeltQuoteResponse(
|
return PostMeltQuoteResponse(
|
||||||
@@ -514,6 +515,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
|||||||
amount=quote.amount,
|
amount=quote.amount,
|
||||||
fee_reserve=quote.fee_reserve,
|
fee_reserve=quote.fee_reserve,
|
||||||
paid=quote.paid,
|
paid=quote.paid,
|
||||||
|
expiry=quote.expiry,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_melt_quote(self, quote_id: str) -> MeltQuote:
|
async def get_melt_quote(self, quote_id: str) -> MeltQuote:
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ async def melt_quote(quote: str) -> PostMeltQuoteResponse:
|
|||||||
amount=melt_quote.amount,
|
amount=melt_quote.amount,
|
||||||
fee_reserve=melt_quote.fee_reserve,
|
fee_reserve=melt_quote.fee_reserve,
|
||||||
paid=melt_quote.paid,
|
paid=melt_quote.paid,
|
||||||
|
expiry=melt_quote.expiry,
|
||||||
)
|
)
|
||||||
logger.trace(f"< GET /v1/melt/quote/bolt11/{quote}")
|
logger.trace(f"< GET /v1/melt/quote/bolt11/{quote}")
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ class LedgerAPI(LedgerAPIDeprecated, object):
|
|||||||
amount=invoice_obj.amount_msat // 1000,
|
amount=invoice_obj.amount_msat // 1000,
|
||||||
fee_reserve=ret.fee or 0,
|
fee_reserve=ret.fee or 0,
|
||||||
paid=False,
|
paid=False,
|
||||||
|
expiry=invoice_obj.expiry,
|
||||||
)
|
)
|
||||||
# END backwards compatibility < 0.15.0
|
# END backwards compatibility < 0.15.0
|
||||||
self.raise_on_error_request(resp)
|
self.raise_on_error_request(resp)
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ async def test_mint_quote(ledger: Ledger):
|
|||||||
assert result["request"]
|
assert result["request"]
|
||||||
invoice = bolt11.decode(result["request"])
|
invoice = bolt11.decode(result["request"])
|
||||||
assert invoice.amount_msat == 100 * 1000
|
assert invoice.amount_msat == 100 * 1000
|
||||||
|
assert result["expiry"] == invoice.expiry
|
||||||
|
|
||||||
# get mint quote again from api
|
# get mint quote again from api
|
||||||
response = httpx.get(
|
response = httpx.get(
|
||||||
@@ -243,6 +244,8 @@ async def test_melt_quote_internal(ledger: Ledger, wallet: Wallet):
|
|||||||
assert result["amount"] == 64
|
assert result["amount"] == 64
|
||||||
# TODO: internal invoice, fee should be 0
|
# TODO: internal invoice, fee should be 0
|
||||||
assert result["fee_reserve"] == 0
|
assert result["fee_reserve"] == 0
|
||||||
|
invoice_obj = bolt11.decode(request)
|
||||||
|
assert result["expiry"] == invoice_obj.expiry
|
||||||
|
|
||||||
# get melt quote again from api
|
# get melt quote again from api
|
||||||
response = httpx.get(
|
response = httpx.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user