fix WALLET initialisation
This commit is contained in:
parent
030d3b34d8
commit
c845502f28
8 changed files with 23 additions and 11 deletions
|
|
@ -16,7 +16,7 @@ from fastapi.staticfiles import StaticFiles
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from lnbits.core.tasks import register_task_listeners
|
from lnbits.core.tasks import register_task_listeners
|
||||||
from lnbits.settings import WALLET, check_admin_settings, settings
|
from lnbits.settings import check_admin_settings, get_wallet_class, settings
|
||||||
|
|
||||||
from .commands import migrate_databases
|
from .commands import migrate_databases
|
||||||
from .core import core_app
|
from .core import core_app
|
||||||
|
|
@ -78,12 +78,15 @@ def create_app() -> FastAPI:
|
||||||
|
|
||||||
|
|
||||||
async def check_funding_source() -> None:
|
async def check_funding_source() -> None:
|
||||||
|
|
||||||
# original_sigint_handler = signal.getsignal(signal.SIGINT)
|
# original_sigint_handler = signal.getsignal(signal.SIGINT)
|
||||||
|
|
||||||
# def signal_handler(signal, frame):
|
# def signal_handler(signal, frame):
|
||||||
# logger.debug(f"SIGINT received, terminating LNbits.")
|
# logger.debug(f"SIGINT received, terminating LNbits.")
|
||||||
# sys.exit(1)
|
# sys.exit(1)
|
||||||
# signal.signal(signal.SIGINT, signal_handler)
|
# signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
WALLET = get_wallet_class()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
error_message, balance = await WALLET.status()
|
error_message, balance = await WALLET.status()
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
from lnbits.db import Connection
|
from lnbits.db import Connection
|
||||||
from lnbits.helpers import url_for
|
from lnbits.helpers import url_for
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import get_wallet_class
|
||||||
from lnbits.wallets.base import PaymentStatus
|
from lnbits.wallets.base import PaymentStatus
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -163,6 +163,7 @@ class Payment(BaseModel):
|
||||||
f"Checking {'outgoing' if self.is_out else 'incoming'} pending payment {self.checking_id}"
|
f"Checking {'outgoing' if self.is_out else 'incoming'} pending payment {self.checking_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
WALLET = get_wallet_class()
|
||||||
if self.is_out:
|
if self.is_out:
|
||||||
status = await WALLET.get_payment_status(self.checking_id)
|
status = await WALLET.get_payment_status(self.checking_id)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from lnbits.decorators import (
|
||||||
)
|
)
|
||||||
from lnbits.helpers import url_for, urlsafe_short_hash
|
from lnbits.helpers import url_for, urlsafe_short_hash
|
||||||
from lnbits.requestvars import g
|
from lnbits.requestvars import g
|
||||||
from lnbits.settings import FAKE_WALLET, WALLET, settings
|
from lnbits.settings import FAKE_WALLET, get_wallet_class, settings
|
||||||
from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
@ -65,7 +65,7 @@ async def create_invoice(
|
||||||
invoice_memo = None if description_hash else memo
|
invoice_memo = None if description_hash else memo
|
||||||
|
|
||||||
# use the fake wallet if the invoice is for internal use only
|
# use the fake wallet if the invoice is for internal use only
|
||||||
wallet = FAKE_WALLET if internal else WALLET
|
wallet = FAKE_WALLET if internal else get_wallet_class()
|
||||||
|
|
||||||
ok, checking_id, payment_request, error_message = await wallet.create_invoice(
|
ok, checking_id, payment_request, error_message = await wallet.create_invoice(
|
||||||
amount=amount,
|
amount=amount,
|
||||||
|
|
@ -193,6 +193,7 @@ async def pay_invoice(
|
||||||
else:
|
else:
|
||||||
logger.debug(f"backend: sending payment {temp_id}")
|
logger.debug(f"backend: sending payment {temp_id}")
|
||||||
# actually pay the external invoice
|
# actually pay the external invoice
|
||||||
|
WALLET = get_wallet_class()
|
||||||
payment: PaymentResponse = await WALLET.pay_invoice(
|
payment: PaymentResponse = await WALLET.pay_invoice(
|
||||||
payment_request, fee_reserve_msat
|
payment_request, fee_reserve_msat
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ from lnbits.decorators import (
|
||||||
require_invoice_key,
|
require_invoice_key,
|
||||||
)
|
)
|
||||||
from lnbits.helpers import url_for, urlsafe_short_hash
|
from lnbits.helpers import url_for, urlsafe_short_hash
|
||||||
from lnbits.settings import WALLET, settings
|
from lnbits.settings import get_wallet_class, settings
|
||||||
from lnbits.utils.exchange_rates import (
|
from lnbits.utils.exchange_rates import (
|
||||||
currencies,
|
currencies,
|
||||||
fiat_amount_as_satoshis,
|
fiat_amount_as_satoshis,
|
||||||
|
|
@ -682,7 +682,7 @@ async def api_auditor(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.FORBIDDEN, detail="Not an admin user"
|
status_code=HTTPStatus.FORBIDDEN, detail="Not an admin user"
|
||||||
)
|
)
|
||||||
|
WALLET = get_wallet_class()
|
||||||
total_balance = await get_total_balance()
|
total_balance = await get_total_balance()
|
||||||
error_message, node_balance = await WALLET.status()
|
error_message, node_balance = await WALLET.status()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from starlette.responses import HTMLResponse
|
||||||
from lnbits.core.models import User
|
from lnbits.core.models import User
|
||||||
from lnbits.decorators import check_admin
|
from lnbits.decorators import check_admin
|
||||||
from lnbits.requestvars import g
|
from lnbits.requestvars import g
|
||||||
from lnbits.settings import WALLET, settings
|
from lnbits.settings import get_wallet_class, settings
|
||||||
|
|
||||||
from . import admin_ext, admin_renderer
|
from . import admin_ext, admin_renderer
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
@admin_ext.get("/", response_class=HTMLResponse)
|
@admin_ext.get("/", response_class=HTMLResponse)
|
||||||
async def index(request: Request, user: User = Depends(check_admin)):
|
async def index(request: Request, user: User = Depends(check_admin)):
|
||||||
|
WALLET = get_wallet_class()
|
||||||
error, balance = await WALLET.status()
|
error, balance = await WALLET.status()
|
||||||
|
|
||||||
return admin_renderer().TemplateResponse(
|
return admin_renderer().TemplateResponse(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ from lnbits import bolt11
|
||||||
from lnbits.core.crud import delete_expired_invoices, get_payments
|
from lnbits.core.crud import delete_expired_invoices, get_payments
|
||||||
from lnbits.core.services import create_invoice, pay_invoice
|
from lnbits.core.services import create_invoice, pay_invoice
|
||||||
from lnbits.decorators import WalletTypeInfo
|
from lnbits.decorators import WalletTypeInfo
|
||||||
from lnbits.settings import WALLET, settings
|
from lnbits.settings import get_wallet_class, settings
|
||||||
|
|
||||||
from . import lndhub_ext
|
from . import lndhub_ext
|
||||||
from .decorators import check_wallet, require_admin_key
|
from .decorators import check_wallet, require_admin_key
|
||||||
|
|
@ -175,6 +175,7 @@ async def lndhub_getuserinvoices(
|
||||||
offset=offset,
|
offset=offset,
|
||||||
exclude_uncheckable=True,
|
exclude_uncheckable=True,
|
||||||
):
|
):
|
||||||
|
WALLET = get_wallet_class()
|
||||||
await invoice.set_pending(
|
await invoice.set_pending(
|
||||||
(await WALLET.get_invoice_status(invoice.checking_id)).pending
|
(await WALLET.get_invoice_status(invoice.checking_id)).pending
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,9 @@ async def check_admin_settings():
|
||||||
|
|
||||||
|
|
||||||
wallets_module = importlib.import_module("lnbits.wallets")
|
wallets_module = importlib.import_module("lnbits.wallets")
|
||||||
wallet_class = getattr(wallets_module, settings.lnbits_backend_wallet_class)
|
|
||||||
WALLET = wallet_class()
|
|
||||||
FAKE_WALLET = getattr(wallets_module, "FakeWallet")()
|
FAKE_WALLET = getattr(wallets_module, "FakeWallet")()
|
||||||
|
|
||||||
|
|
||||||
|
def get_wallet_class():
|
||||||
|
wallet_class = getattr(wallets_module, settings.lnbits_backend_wallet_class)
|
||||||
|
return wallet_class()
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from lnbits.core.crud import (
|
||||||
get_standalone_payment,
|
get_standalone_payment,
|
||||||
)
|
)
|
||||||
from lnbits.core.services import redeem_lnurl_withdraw
|
from lnbits.core.services import redeem_lnurl_withdraw
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import get_wallet_class
|
||||||
|
|
||||||
from .core import db
|
from .core import db
|
||||||
|
|
||||||
|
|
@ -79,6 +79,7 @@ async def webhook_handler():
|
||||||
"""
|
"""
|
||||||
Returns the webhook_handler for the selected wallet if present. Used by API.
|
Returns the webhook_handler for the selected wallet if present. Used by API.
|
||||||
"""
|
"""
|
||||||
|
WALLET = get_wallet_class()
|
||||||
handler = getattr(WALLET, "webhook_listener", None)
|
handler = getattr(WALLET, "webhook_listener", None)
|
||||||
if handler:
|
if handler:
|
||||||
return await handler()
|
return await handler()
|
||||||
|
|
@ -108,6 +109,7 @@ async def invoice_listener():
|
||||||
|
|
||||||
Called by the app startup sequence.
|
Called by the app startup sequence.
|
||||||
"""
|
"""
|
||||||
|
WALLET = get_wallet_class()
|
||||||
async for checking_id in WALLET.paid_invoices_stream():
|
async for checking_id in WALLET.paid_invoices_stream():
|
||||||
logger.info("> got a payment notification", checking_id)
|
logger.info("> got a payment notification", checking_id)
|
||||||
asyncio.create_task(invoice_callback_dispatcher(checking_id))
|
asyncio.create_task(invoice_callback_dispatcher(checking_id))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue