mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-02-03 15:54:20 +01:00
Melt quotes use case-insensitive request (#479)
* use lowerstr melt quote * case insensitive melt quotes
This commit is contained in:
@@ -348,6 +348,10 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
# get invoice expiry time
|
||||
invoice_obj = bolt11.decode(invoice_response.payment_request)
|
||||
|
||||
# NOTE: we normalize the request to lowercase to avoid case sensitivity
|
||||
# This works with Lightning but might not work with other methods
|
||||
request = invoice_response.payment_request.lower()
|
||||
|
||||
expiry = None
|
||||
if invoice_obj.expiry is not None:
|
||||
expiry = invoice_obj.date + invoice_obj.expiry
|
||||
@@ -355,7 +359,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
quote = MintQuote(
|
||||
quote=random_hash(),
|
||||
method=method.name,
|
||||
request=invoice_response.payment_request,
|
||||
request=request,
|
||||
checking_id=invoice_response.checking_id,
|
||||
unit=quote_request.unit,
|
||||
amount=quote_request.amount,
|
||||
@@ -469,6 +473,9 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
"""
|
||||
unit = Unit[melt_quote.unit]
|
||||
method = Method.bolt11
|
||||
# NOTE: we normalize the request to lowercase to avoid case sensitivity
|
||||
# This works with Lightning but might not work with other methods
|
||||
request = melt_quote.request.lower()
|
||||
invoice_obj = bolt11.decode(melt_quote.request)
|
||||
assert invoice_obj.amount_msat, "invoice has no amount."
|
||||
|
||||
@@ -476,7 +483,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
# so that we can handle the transaction internally without lightning
|
||||
# and respond with zero fees
|
||||
mint_quote = await self.crud.get_mint_quote_by_request(
|
||||
request=melt_quote.request, db=self.db
|
||||
request=request, db=self.db
|
||||
)
|
||||
if mint_quote:
|
||||
# internal transaction, validate and return amount from
|
||||
@@ -485,9 +492,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
Amount(unit, mint_quote.amount).to(Unit.msat).amount
|
||||
== invoice_obj.amount_msat
|
||||
), "amounts do not match"
|
||||
assert (
|
||||
melt_quote.request == mint_quote.request
|
||||
), "bolt11 requests do not match"
|
||||
assert request == mint_quote.request, "bolt11 requests do not match"
|
||||
assert mint_quote.unit == melt_quote.unit, "units do not match"
|
||||
assert mint_quote.method == method.name, "methods do not match"
|
||||
assert not mint_quote.paid, "mint quote already paid"
|
||||
@@ -499,14 +504,12 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
fee=Amount(unit=Unit.msat, amount=0),
|
||||
)
|
||||
logger.info(
|
||||
f"Issuing internal melt quote: {melt_quote.request} ->"
|
||||
f"Issuing internal melt quote: {request} ->"
|
||||
f" {mint_quote.quote} ({mint_quote.amount} {mint_quote.unit})"
|
||||
)
|
||||
else:
|
||||
# not internal, get quote by backend
|
||||
payment_quote = await self.backends[method][unit].get_payment_quote(
|
||||
melt_quote.request
|
||||
)
|
||||
payment_quote = await self.backends[method][unit].get_payment_quote(request)
|
||||
assert payment_quote.checking_id, "quote has no checking id"
|
||||
|
||||
expiry = None
|
||||
@@ -516,9 +519,9 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
quote = MeltQuote(
|
||||
quote=random_hash(),
|
||||
method=method.name,
|
||||
request=melt_quote.request,
|
||||
request=request,
|
||||
checking_id=payment_quote.checking_id,
|
||||
unit=melt_quote.unit,
|
||||
unit=unit.name,
|
||||
amount=payment_quote.amount.to(unit).amount,
|
||||
paid=False,
|
||||
fee_reserve=payment_quote.fee.to(unit).amount,
|
||||
|
||||
Reference in New Issue
Block a user