Skip to content

Commit

Permalink
wip CLN
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Mar 31, 2024
1 parent 1201b83 commit 11d68fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 9 additions & 5 deletions cashu/lightning/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,21 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
r.raise_for_status()
data = r.json()

if r.is_error or "error" in data or not data.get("pays"):
raise Exception("error in corelightning-rest response")
if not data.get("pays"):
# payment not found
logger.error(f"payment not found: {data.get('pays')}")
return PaymentStatus(paid=False)

if r.is_error or "error" in data:
message = data.get("error") or data
raise Exception(f"error in corelightning-rest response: {message}")

pay = data["pays"][0]

fee_msat, preimage = None, None
if self.statuses[pay["status"]]:
# cut off "msat" and convert to int
fee_msat = -int(pay["amount_sent_msat"][:-4]) - int(
pay["amount_msat"][:-4]
)
fee_msat = -int(pay["amount_sent_msat"]) - int(pay["amount_msat"])
preimage = pay["preimage"]

return PaymentStatus(
Expand Down
11 changes: 10 additions & 1 deletion cashu/lightning/lndrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,23 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
async for json_line in r.aiter_lines():
try:
line = json.loads(json_line)

# check for errors
if line.get("error"):
logger.error(
message = (
line["error"]["message"]
if "message" in line["error"]
else line["error"]
)
logger.error(f"LND get_payment_status error: {message}")
if "payment isn't initiated" in message:
# payment has not been initiated yet, return False
return PaymentStatus(paid=False)
return PaymentStatus(paid=None)

payment = line.get("result")

# payment exists
if payment is not None and payment.get("status"):
return PaymentStatus(
paid=statuses[payment["status"]],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mint_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def create_pending_melts(ledger: Ledger) -> Proof:
proof=pending_proof,
quote_id=quote_id,
)
# expect that no pending tokens are in db anymore
# expect a pending melt quote
melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs(
db=ledger.db
)
Expand Down

0 comments on commit 11d68fb

Please sign in to comment.