Skip to content
Merged
Changes from 1 commit
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
28 changes: 24 additions & 4 deletions views_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""https://github.com/BlueWallet/LndHub/blob/master/doc/Send-requirements.md"""

import asyncio
from base64 import urlsafe_b64encode

from bolt11 import decode as bolt11_decode
from fastapi import APIRouter, Depends, Query
from lnbits.core.crud import get_payments
from lnbits.core.crud import get_payments, get_standalone_payment
from lnbits.core.models import WalletTypeInfo
from lnbits.core.services import create_invoice, pay_invoice
from lnbits.settings import settings
Expand Down Expand Up @@ -59,14 +62,31 @@ async def lndhub_payinvoice(
invoice = bolt11_decode(r_invoice.invoice)
except Exception:
return {"payment_error": "Invalid invoice"}

try:
payment = await pay_invoice(
wallet_id=key_type.wallet.id,
payment_request=r_invoice.invoice,
extra={"tag": "lndhub"},
)
except Exception:
return {"payment_error": "Payment failed"}
except Exception as exc:
return {"payment_error": f"Payment failed. ({exc!s})"}

if not payment:
return {"payment_error": "Payment failed. (No payment created)"}

# lnbits has a payment timeout, but lndhub doesn't,
# so we need to wait until the payment is complete
pending = payment.pending
while pending:
payment = await get_standalone_payment(payment.checking_id)
if not payment:
return {"payment_error": "Payment failed. (No payment)"}
if payment.failed:
return {"payment_error": "Payment failed."}
if payment.success:
pending = False
await asyncio.sleep(3)

return {
"payment_error": "",
Expand Down Expand Up @@ -114,7 +134,7 @@ async def lndhub_gettxs(
for payment in reversed(
await get_payments(
wallet_id=key_type.wallet.id,
pending=True,
pending=False,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another issue, should /gettxs should onlyt return succesful payments taken from the docs. https://github.com/BlueWallet/LndHub/blob/master/doc/Send-requirements.md#get-gettxs

complete=True,
outgoing=True,
incoming=False,
Expand Down
Loading