do not chcek melt status before payment attempt (#443)

This commit is contained in:
callebtc
2024-02-18 23:26:55 +01:00
committed by GitHub
parent c4e8618cad
commit a3145a93d5
2 changed files with 12 additions and 8 deletions

View File

@@ -287,7 +287,8 @@ class BlinkWallet(LightningBackend):
return PaymentResponse(ok=False, error_message=str(e)) return PaymentResponse(ok=False, error_message=str(e))
resp: dict = r.json() resp: dict = r.json()
# no result found
# no result found, this payment has not been attempted before
if ( if (
not resp.get("data", {}) not resp.get("data", {})
.get("me", {}) .get("me", {})
@@ -305,7 +306,7 @@ class BlinkWallet(LightningBackend):
.get("transactionsByPaymentHash") .get("transactionsByPaymentHash")
) )
# Blink API edge case: for a failed payment attempt, it returns two payments with the same hash # Blink API edge case: for a previously failed payment attempt, it returns the two payments with the same hash
# if there are two payments with the same hash with "direction" == "SEND" and "RECEIVE" # if there are two payments with the same hash with "direction" == "SEND" and "RECEIVE"
# it means that the payment previously failed and we can ignore the attempt and return # it means that the payment previously failed and we can ignore the attempt and return
# PaymentStatus(paid=None) # PaymentStatus(paid=None)

View File

@@ -521,15 +521,18 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
expiry=quote.expiry, expiry=quote.expiry,
) )
async def get_melt_quote(self, quote_id: str) -> MeltQuote: async def get_melt_quote(
self, quote_id: str, check_quote_with_backend: bool = False
) -> MeltQuote:
"""Returns a melt quote. """Returns a melt quote.
If melt quote is not paid yet, checks with the backend for the state of the payment request. If melt quote is not paid yet and `check_quote_with_backend` is set to `True`,
checks with the backend for the state of the payment request. If the backend
If the quote has been paid, updates the melt quote in the database. says that the quote has been paid, updates the melt quote in the database.
Args: Args:
quote_id (str): ID of the melt quote. quote_id (str): ID of the melt quote.
check_quote_with_backend (bool, optional): Whether to check the state of the payment request with the backend. Defaults to False.
Raises: Raises:
Exception: Quote not found. Exception: Quote not found.
@@ -549,7 +552,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
checking_id=melt_quote.checking_id, db=self.db checking_id=melt_quote.checking_id, db=self.db
) )
if not melt_quote.paid and not mint_quote: if not melt_quote.paid and not mint_quote and check_quote_with_backend:
logger.trace( logger.trace(
"Lightning: checking outgoing Lightning payment" "Lightning: checking outgoing Lightning payment"
f" {melt_quote.checking_id}" f" {melt_quote.checking_id}"
@@ -643,7 +646,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
Returns: Returns:
Tuple[str, List[BlindedMessage]]: Proof of payment and signed outputs for returning overpaid fees to wallet. Tuple[str, List[BlindedMessage]]: Proof of payment and signed outputs for returning overpaid fees to wallet.
""" """
# get melt quote and check if it is paid # get melt quote and check if it was already paid
melt_quote = await self.get_melt_quote(quote_id=quote) melt_quote = await self.get_melt_quote(quote_id=quote)
method = Method[melt_quote.method] method = Method[melt_quote.method]
unit = Unit[melt_quote.unit] unit = Unit[melt_quote.unit]