From bac50f2150df8f0075be1d051464095ec4c40a0b Mon Sep 17 00:00:00 2001 From: redshift <213178690+sh1ftred@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:25:02 +0000 Subject: [PATCH 1/2] Fixed the 503 mint service unavailable bug This flag fetch all keysets from the db into the wallet, which is wrong given that we're initiating it for a mint. And load_mint sets the first keyset from all the keysets from the db, irrespective of the unit and the mint. Fixes #175 --- routstr/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routstr/wallet.py b/routstr/wallet.py index c00b5b82..d9c35666 100644 --- a/routstr/wallet.py +++ b/routstr/wallet.py @@ -153,7 +153,7 @@ async def get_wallet(mint_url: str, unit: str = "sat", load: bool = True) -> Wal id = f"{mint_url}_{unit}" if id not in _wallets: _wallets[id] = await Wallet.with_db( - mint_url, db=".wallet", load_all_keysets=True, unit=unit + mint_url, db=".wallet", unit=unit ) if load: From 729f00caa2496eb257e5e3824fcea270648879ee Mon Sep 17 00:00:00 2001 From: redshift <213178690+sh1ftred@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:55:16 +0000 Subject: [PATCH 2/2] Fixed the bug where refund amount is below 1 sat for a sat mint --- routstr/balance.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/routstr/balance.py b/routstr/balance.py index 76e87498..23c41f55 100644 --- a/routstr/balance.py +++ b/routstr/balance.py @@ -152,14 +152,19 @@ async def refund_wallet_endpoint( key: ApiKey = await validate_bearer_key(bearer_value, session) remaining_balance_msats: int = key.balance - if remaining_balance_msats <= 0: + if key.refund_currency == "sat": + remaining_balance = remaining_balance_msats // 1000 + else: + remaining_balance = remaining_balance_msats + + if remaining_balance_msats > 0 and remaining_balance <= 0: + raise HTTPException(status_code=400, detail="Balance too small to refund") + elif remaining_balance <= 0: raise HTTPException(status_code=400, detail="No balance to refund") # Perform refund operation first, before modifying balance try: if key.refund_address: - if key.refund_currency == "sat": - remaining_balance = remaining_balance_msats // 1000 from .core.settings import settings as global_settings await send_to_lnurl( @@ -170,14 +175,9 @@ async def refund_wallet_endpoint( ) result = {"recipient": key.refund_address} else: - refund_amount = ( - remaining_balance_msats // 1000 - if key.refund_currency == "sat" - else remaining_balance_msats - ) refund_currency = key.refund_currency or "sat" token = await send_token( - refund_amount, refund_currency, key.refund_mint_url + remaining_balance, refund_currency, key.refund_mint_url ) result = {"token": token}