From 764bc3d7e8254e2c9b52cb0ba6aec8839da67f36 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Mon, 22 Sep 2025 17:54:28 +0100 Subject: [PATCH] fix periodic payouts --- routstr/payment/lnurl.py | 15 ++++++++++++++- routstr/wallet.py | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/routstr/payment/lnurl.py b/routstr/payment/lnurl.py index 49bc8d65..04395311 100644 --- a/routstr/payment/lnurl.py +++ b/routstr/payment/lnurl.py @@ -230,7 +230,11 @@ async def get_lnurl_invoice( async def raw_send_to_lnurl( - wallet: Wallet, proofs: list[Proof], lnurl: str, unit: str + wallet: Wallet, + proofs: list[Proof], + lnurl: str, + unit: str, + amount: int | None = None, ) -> int: """Send funds to an LNURL address. @@ -255,6 +259,11 @@ async def raw_send_to_lnurl( paid = await wallet.send_to_lnurl("user@getalby.com", 50, unit="usd") """ total_balance = sum(proof.amount for proof in proofs) + if amount and total_balance < amount: + raise ValueError("Amount to send is higher than available proofs.") + else: + assert isinstance(amount, int) + total_balance = amount lnurl_data = await get_lnurl_data(lnurl) if unit == "sat": @@ -285,6 +294,10 @@ async def raw_send_to_lnurl( melt_quote_resp = await wallet.melt_quote( invoice=bolt11_invoice, amount_msat=final_amount ) + + if amount: + proofs, _ = await wallet.select_to_send(proofs, amount, set_reserved=True) + _ = await wallet.melt( proofs=proofs, invoice=bolt11_invoice, diff --git a/routstr/wallet.py b/routstr/wallet.py index d9c35666..c2bd83d0 100644 --- a/routstr/wallet.py +++ b/routstr/wallet.py @@ -299,7 +299,7 @@ async def periodic_payout() -> None: logger.error("RECEIVE_LN_ADDRESS is not set, skipping payout") return while True: - await asyncio.sleep(60 * 5) + await asyncio.sleep(60 * 15) try: async with db.create_session() as session: for mint_url in settings.cashu_mints: @@ -319,7 +319,11 @@ async def periodic_payout() -> None: min_amount = 210 if unit == "sat" else 210000 if available_balance > min_amount: amount_received = await raw_send_to_lnurl( - wallet, proofs, settings.receive_ln_address, unit + wallet, + proofs, + settings.receive_ln_address, + unit, + amount=available_balance, ) logger.info( "Payout sent successfully",