Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
31 changes: 29 additions & 2 deletions lnbits/core/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from http import HTTPStatus
from io import BytesIO
from time import time
from typing import Dict, List
from typing import Any, Dict, List
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse

import httpx
Expand All @@ -15,6 +15,7 @@
from fastapi.exceptions import HTTPException
from starlette.responses import StreamingResponse

from lnbits.core.crud import get_user
from lnbits.core.models import (
BaseWallet,
ConversionData,
Expand All @@ -37,6 +38,8 @@
get_fiat_rate_satoshis,
satoshis_amount_as_fiat,
)
from lnbits.wallets import get_funding_source
from lnbits.wallets.base import StatusResponse

from ..services import create_user_account, perform_lnurlauth

Expand All @@ -52,10 +55,34 @@ async def health() -> dict:
return {
"server_time": int(time()),
"up_time": int(time() - settings.server_startup_time),
"version": settings.version,
}


@api_router.get("/api/v1/status", status_code=HTTPStatus.OK)
async def health_check(wallet: WalletTypeInfo = Depends(require_invoice_key)) -> dict:
stat: dict[str, Any] = {
"server_time": int(time()),
"up_time": int(time() - settings.server_startup_time),
}

user = await get_user(wallet.wallet.user)
if not user:
return stat

stat["version"] = settings.version
if not user.admin:
return stat

funding_source = get_funding_source()
stat["funding_source"] = funding_source.__class__.__name__

status: StatusResponse = await funding_source.status()
stat["funding_source_error"] = status.error_message
stat["funding_source_balance_msat"] = status.balance_msat

return stat


@api_router.get(
"/api/v1/wallets",
name="Wallets",
Expand Down
Loading