diff --git a/.env.example b/.env.example index 39e2f355..e7576471 100644 --- a/.env.example +++ b/.env.example @@ -2,9 +2,10 @@ FLASK_APP=lnbits FLASK_ENV=development LNBITS_SITE_TITLE=LNbits -LNBITS_WITH_ONION=0 LNBITS_DEFAULT_WALLET_NAME="LNbits wallet" -LNBITS_FEE_RESERVE=0 +LNBITS_DATA_FOLDER="/your_custom_data_folder" +LNBITS_SERVICE_FEE="0.0" +LNBITS_WITH_ONION=0 # Choose from LNPayWallet, OpenNodeWallet, LntxbotWallet, LndWallet, CLightningWallet, LnbitsWallet LNBITS_BACKEND_WALLET_CLASS=LntxbotWallet diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 8eaf02e9..d31356fd 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -2,7 +2,7 @@ from typing import List, Optional from uuid import uuid4 from lnbits.db import open_db -from lnbits.settings import DEFAULT_WALLET_NAME, FEE_RESERVE +from lnbits.settings import DEFAULT_WALLET_NAME from .models import User, Wallet, Payment @@ -34,11 +34,11 @@ def get_user(user_id: str) -> Optional[User]: extensions = db.fetchall("SELECT extension FROM extensions WHERE user = ? AND active = 1", (user_id,)) wallets = db.fetchall( """ - SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) * ? AS balance_msat + SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) AS balance_msat FROM wallets WHERE user = ? """, - (1 - FEE_RESERVE, user_id), + (user_id,), ) return ( @@ -96,11 +96,11 @@ def get_wallet(wallet_id: str) -> Optional[Wallet]: with open_db() as db: row = db.fetchone( """ - SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) * ? AS balance_msat + SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) AS balance_msat FROM wallets WHERE id = ? """, - (1 - FEE_RESERVE, wallet_id), + (wallet_id,), ) return Wallet(**row) if row else None @@ -111,11 +111,11 @@ def get_wallet_for_key(key: str, key_type: str = "invoice") -> Optional[Wallet]: check_field = "adminkey" if key_type == "admin" else "inkey" row = db.fetchone( f""" - SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) * ? AS balance_msat + SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) AS balance_msat FROM wallets WHERE {check_field} = ? """, - (1 - FEE_RESERVE, key), + (key,), ) return Wallet(**row) if row else None diff --git a/lnbits/core/services.py b/lnbits/core/services.py index b191d595..7caa5b3f 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -1,7 +1,7 @@ from typing import Optional, Tuple from lnbits.bolt11 import decode as bolt11_decode -from lnbits.settings import WALLET, FEE_RESERVE +from lnbits.settings import WALLET from .crud import create_payment from .models import Wallet @@ -38,11 +38,7 @@ def pay_invoice(*, wallet: Wallet, bolt11: str, max_sat: Optional[int] = None) - if ok: create_payment( - wallet_id=wallet.id, - checking_id=checking_id, - amount=-invoice.amount_msat, - memo=invoice.description, - fee=-invoice.amount_msat * FEE_RESERVE, + wallet_id=wallet.id, checking_id=checking_id, amount=-invoice.amount_msat, memo=invoice.description ) except Exception as e: diff --git a/lnbits/settings.py b/lnbits/settings.py index c488796d..6bf35c1d 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -1,6 +1,8 @@ import importlib import os +from decimal import Decimal + wallets_module = importlib.import_module("lnbits.wallets") wallet_class = getattr(wallets_module, os.getenv("LNBITS_BACKEND_WALLET_CLASS", "LntxbotWallet")) @@ -10,4 +12,4 @@ LNBITS_DATA_FOLDER = os.getenv("LNBITS_DATA_FOLDER", os.path.join(LNBITS_PATH, " WALLET = wallet_class() DEFAULT_WALLET_NAME = os.getenv("LNBITS_DEFAULT_WALLET_NAME", "LNbits wallet") -FEE_RESERVE = float(os.getenv("LNBITS_FEE_RESERVE", 0)) +SERVICE_FEE = Decimal(os.getenv("LNBITS_SERVICE_FEE", "0.0"))