Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lnbits/wallets/corelightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ def __init__(self):
self.supports_description_hash = "deschashonly" in command

# https://docs.corelightning.org/reference/lightning-pay
# -32602: Invalid bolt11: Prefix bc is not for regtest
# -1: Catchall nonspecific error.
# 201: Already paid
# 203: Permanent failure at destination.
# 205: Unable to find a route.
# 206: Route too expensive.
# 207: Invoice expired.
# 210: Payment timed out without a payment in progress.
self.pay_failure_error_codes = [201, 203, 205, 206, 207, 210]
self.pay_failure_error_codes = [-32602, 201, 203, 205, 206, 207, 210]

# check last payindex so we can listen from that point on
self.last_pay_index = 0
Expand Down Expand Up @@ -164,8 +166,8 @@ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse
except RpcError as exc:
logger.warning(exc)
try:
error_code = exc.error.get("code")
if error_code in self.pay_failure_error_codes: # type: ignore
error_code = exc.error.get("code") # type: ignore
if error_code in self.pay_failure_error_codes:
error_message = exc.error.get("message", error_code) # type: ignore
return PaymentResponse(
False, None, None, None, f"Payment failed: {error_message}"
Expand Down
7 changes: 5 additions & 2 deletions lnbits/wallets/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ def __init__(self):
}

# https://docs.corelightning.org/reference/lightning-pay
# -32602: Invalid bolt11: Prefix bc is not for regtest
# -1: Catchall nonspecific error.
# 201: Already paid
# 203: Permanent failure at destination.
# 205: Unable to find a route.
# 206: Route too expensive.
# 207: Invoice expired.
# 210: Payment timed out without a payment in progress.
self.pay_failure_error_codes = [201, 203, 205, 206, 207, 210]
self.pay_failure_error_codes = [-32602, 201, 203, 205, 206, 207, 210]

self.cert = settings.corelightning_rest_cert or False
self.client = httpx.AsyncClient(verify=self.cert, headers=headers)
Expand Down Expand Up @@ -204,7 +206,8 @@ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse
try:
logger.debug(exc)
data = exc.response.json()
if data["error"]["code"] in self.pay_failure_error_codes: # type: ignore
error_code = int(data["error"]["code"])
if error_code in self.pay_failure_error_codes:
error_message = f"Payment failed: {data['error']['message']}"
return PaymentResponse(False, None, None, None, error_message)
error_message = f"REST failed with {data['error']['message']}."
Expand Down