Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle hodl invoices asynchronously tasks.py #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ async def on_invoice_paid(payment: Payment) -> None:
logger.trace(f"splitpayments: performing split payments to {len(targets)} targets")

for target in targets:

if target.percent > 0:

amount_msat = int(payment.amount * target.percent / 100)
memo = (
f"Split payment: {target.percent}% for {target.alias or target.wallet}"
)

if target.wallet.find("@") >= 0 or target.wallet.find("LNURL") >= 0:
if "@" in target.wallet or "LNURL" in target.wallet:
safe_amount_msat = amount_msat - fee_reserve(amount_msat)
payment_request = await get_lnurl_invoice(
target.wallet, payment.wallet_id, safe_amount_msat, memo
Expand All @@ -67,12 +65,23 @@ async def on_invoice_paid(payment: Payment) -> None:
extra = {**payment.extra, "splitted": True}

if payment_request:
await pay_invoice(
asyncio.create_task(pay_invoice_in_background(
payment_request=payment_request,
wallet_id=payment.wallet_id,
description=memo,
extra=extra,
)
extra=extra
))

async def pay_invoice_in_background(payment_request, wallet_id, description, extra):
try:
await pay_invoice(
payment_request=payment_request,
wallet_id=wallet_id,
description=description,
extra=extra,
)
except Exception as e:
logger.error(f"Failed to pay invoice: {e}")


async def get_lnurl_invoice(
Expand Down
Loading