mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 02:24:20 +01:00
Mint: lookup internal quote settlement by request (#478)
This commit is contained in:
@@ -155,10 +155,10 @@ class LedgerCrud(ABC):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def get_mint_quote_by_checking_id(
|
||||
async def get_mint_quote_by_request(
|
||||
self,
|
||||
*,
|
||||
checking_id: str,
|
||||
request: str,
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> Optional[MintQuote]:
|
||||
@@ -403,19 +403,19 @@ class LedgerCrudSqlite(LedgerCrud):
|
||||
)
|
||||
return MintQuote.from_row(row) if row else None
|
||||
|
||||
async def get_mint_quote_by_checking_id(
|
||||
async def get_mint_quote_by_request(
|
||||
self,
|
||||
*,
|
||||
checking_id: str,
|
||||
request: str,
|
||||
db: Database,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> Optional[MintQuote]:
|
||||
row = await (conn or db).fetchone(
|
||||
f"""
|
||||
SELECT * from {table_with_schema(db, 'mint_quotes')}
|
||||
WHERE checking_id = ?
|
||||
WHERE request = ?
|
||||
""",
|
||||
(checking_id,),
|
||||
(request,),
|
||||
)
|
||||
return MintQuote.from_row(row) if row else None
|
||||
|
||||
|
||||
@@ -475,8 +475,8 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
# check if there is a mint quote with the same payment request
|
||||
# so that we can handle the transaction internally without lightning
|
||||
# and respond with zero fees
|
||||
mint_quote = await self.crud.get_mint_quote_by_checking_id(
|
||||
checking_id=invoice_obj.payment_hash, db=self.db
|
||||
mint_quote = await self.crud.get_mint_quote_by_request(
|
||||
request=melt_quote.request, db=self.db
|
||||
)
|
||||
if mint_quote:
|
||||
# internal transaction, validate and return amount from
|
||||
@@ -561,8 +561,8 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
|
||||
# we only check the state with the backend if there is no associated internal
|
||||
# mint quote for this melt quote
|
||||
mint_quote = await self.crud.get_mint_quote_by_checking_id(
|
||||
checking_id=melt_quote.checking_id, db=self.db
|
||||
mint_quote = await self.crud.get_mint_quote_by_request(
|
||||
request=melt_quote.request, db=self.db
|
||||
)
|
||||
|
||||
if not melt_quote.paid and not mint_quote and check_quote_with_backend:
|
||||
@@ -600,8 +600,8 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
"""
|
||||
# first we check if there is a mint quote with the same payment request
|
||||
# so that we can handle the transaction internally without the backend
|
||||
mint_quote = await self.crud.get_mint_quote_by_checking_id(
|
||||
checking_id=melt_quote.checking_id, db=self.db
|
||||
mint_quote = await self.crud.get_mint_quote_by_request(
|
||||
request=melt_quote.request, db=self.db
|
||||
)
|
||||
if not mint_quote:
|
||||
return melt_quote
|
||||
|
||||
@@ -46,6 +46,22 @@ async def test_mint_quote(wallet1: Wallet, ledger: Ledger):
|
||||
assert quote.created_time
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_mint_quote_by_request(wallet1: Wallet, ledger: Ledger):
|
||||
invoice = await wallet1.request_mint(128)
|
||||
assert invoice is not None
|
||||
quote = await ledger.crud.get_mint_quote_by_request(
|
||||
request=invoice.bolt11, db=ledger.db
|
||||
)
|
||||
assert quote is not None
|
||||
assert quote.quote == invoice.id
|
||||
assert quote.amount == 128
|
||||
assert quote.unit == "sat"
|
||||
assert not quote.paid
|
||||
assert quote.paid_time is None
|
||||
assert quote.created_time
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_melt_quote(wallet1: Wallet, ledger: Ledger):
|
||||
invoice = await wallet1.request_mint(128)
|
||||
|
||||
Reference in New Issue
Block a user