bugfixes and fix topup wallet
This commit is contained in:
parent
91a5f7d214
commit
c9ead25d50
7 changed files with 60 additions and 41 deletions
|
|
@ -84,6 +84,7 @@ async def check_funding_source() -> None:
|
|||
def signal_handler(signal, frame):
|
||||
logger.debug(f"SIGINT received, terminating LNbits.")
|
||||
sys.exit(1)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
WALLET = get_wallet_class()
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@
|
|||
<p>Funding Source Info</p>
|
||||
<ul>
|
||||
{%raw%}
|
||||
<li>
|
||||
Funding Source: {{settings.lnbits_backend_wallet_class}}
|
||||
</li>
|
||||
<li>Funding Source: {{settings.lnbits_backend_wallet_class}}</li>
|
||||
<li>Balance: {{balance / 1000}} sats</li>
|
||||
{%endraw%}
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,13 @@
|
|||
<div class="row q-col-gutter-md justify-center">
|
||||
<div class="col q-gutter-y-md q-my-md">
|
||||
<q-btn label="Save" color="primary" @click="updateSettings">
|
||||
<q-badge v-if="checkChanges" color="red" rounded floating style="padding: 6px; border-radius: 6px"/>
|
||||
<q-badge
|
||||
v-if="checkChanges"
|
||||
color="red"
|
||||
rounded
|
||||
floating
|
||||
style="padding: 6px; border-radius: 6px"
|
||||
/>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
label="Restart server"
|
||||
|
|
@ -140,9 +146,7 @@
|
|||
},
|
||||
removeAdminUser(user) {
|
||||
let admin_users = this.settings.lnbits_admin_users
|
||||
this.settings.lnbits_admin_users = admin_users.filter(
|
||||
u => u !== user
|
||||
)
|
||||
this.settings.lnbits_admin_users = admin_users.filter(u => u !== user)
|
||||
},
|
||||
addAllowedUser() {
|
||||
let addUser = this.formData.allowed_users_add
|
||||
|
|
@ -155,7 +159,9 @@
|
|||
},
|
||||
removeAllowedUser(user) {
|
||||
let allowed_users = this.settings.lnbits_allowed_users
|
||||
this.settings.lnbits_allowed_users = allowed_users.filter(u => u !== user)
|
||||
this.settings.lnbits_allowed_users = allowed_users.filter(
|
||||
u => u !== user
|
||||
)
|
||||
},
|
||||
addAdSpace() {
|
||||
let adSpace = this.formData.ad_space_add
|
||||
|
|
@ -187,10 +193,10 @@
|
|||
topupWallet() {
|
||||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'PUT',
|
||||
'/admin/api/v1/topup/?usr=' + this.g.user.id,
|
||||
this.wallet.id,
|
||||
this.wallet.amount
|
||||
this.g.user.wallets[0].adminkey,
|
||||
this.wallet
|
||||
)
|
||||
.then(response => {
|
||||
this.$q.notify({
|
||||
|
|
@ -262,7 +268,7 @@
|
|||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from fastapi import Body, Depends, Request
|
||||
from loguru import logger
|
||||
from fastapi import Body, Depends, Query
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits.core.crud import get_wallet
|
||||
|
|
@ -9,47 +8,50 @@ from lnbits.core.models import User
|
|||
from lnbits.decorators import check_admin
|
||||
from lnbits.extensions.admin import admin_ext
|
||||
from lnbits.extensions.admin.models import UpdateSettings
|
||||
from lnbits.requestvars import g
|
||||
from lnbits.server import server_restart
|
||||
from lnbits.settings import settings
|
||||
|
||||
from .crud import delete_settings, update_settings, update_wallet_balance
|
||||
|
||||
|
||||
@admin_ext.get("/api/v1/restart/", status_code=HTTPStatus.OK)
|
||||
async def api_restart_server(user: User = Depends(check_admin)):
|
||||
@admin_ext.get(
|
||||
"/api/v1/restart/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||
)
|
||||
async def api_restart_server() -> dict[str, str]:
|
||||
server_restart.set()
|
||||
return {"status": "Success"}
|
||||
|
||||
|
||||
@admin_ext.put("/api/v1/topup/", status_code=HTTPStatus.OK)
|
||||
@admin_ext.put(
|
||||
"/api/v1/topup/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||
)
|
||||
async def api_update_balance(
|
||||
wallet_id, topup_amount: int, user: User = Depends(check_admin)
|
||||
):
|
||||
id: str = Body(...), amount: int = Body(...)
|
||||
) -> dict[str, str]:
|
||||
try:
|
||||
wallet = await get_wallet(wallet_id)
|
||||
await get_wallet(id)
|
||||
except:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.FORBIDDEN, detail="wallet does not exist."
|
||||
)
|
||||
|
||||
await update_wallet_balance(wallet_id=wallet_id, amount=int(topup_amount))
|
||||
await update_wallet_balance(wallet_id=id, amount=int(amount))
|
||||
|
||||
return {"status": "Success"}
|
||||
|
||||
|
||||
@admin_ext.put("/api/v1/settings/", status_code=HTTPStatus.OK)
|
||||
@admin_ext.put(
|
||||
"/api/v1/settings/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||
)
|
||||
async def api_update_settings(
|
||||
user: User = Depends(check_admin),
|
||||
data: UpdateSettings = Body(...),
|
||||
):
|
||||
settings = await update_settings(data)
|
||||
return {"status": "Success", "settings": settings.dict()}
|
||||
|
||||
|
||||
@admin_ext.delete("/api/v1/settings/", status_code=HTTPStatus.OK)
|
||||
async def api_delete_settings(
|
||||
user: User = Depends(check_admin),
|
||||
):
|
||||
@admin_ext.delete(
|
||||
"/api/v1/settings/", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||
)
|
||||
async def api_delete_settings() -> dict[str, str]:
|
||||
await delete_settings()
|
||||
return {"status": "Success"}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ def main(ctx, port: int, host: str, ssl_keyfile: str, ssl_certfile: str, reload:
|
|||
port=port,
|
||||
host=host,
|
||||
reload=reload,
|
||||
forwarded_allow_ips="*",
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
ssl_certfile=ssl_certfile,
|
||||
**d
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
import importlib
|
||||
import json
|
||||
import subprocess
|
||||
import httpx
|
||||
from os import path
|
||||
from sqlite3 import Row
|
||||
from typing import List, Optional
|
||||
|
||||
import httpx
|
||||
from loguru import logger
|
||||
from pydantic import BaseSettings, Field, validator
|
||||
|
||||
|
||||
|
||||
def list_parse_fallback(v):
|
||||
try:
|
||||
return json.loads(v)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
replaced = v.replace(" ", "")
|
||||
if replaced:
|
||||
return replaced.split(",")
|
||||
|
|
@ -238,24 +237,36 @@ async def check_admin_settings():
|
|||
http = "https" if settings.lnbits_force_https else "http"
|
||||
user = settings.lnbits_admin_users[0]
|
||||
|
||||
admin_url = f"{http}://{settings.host}:{settings.port}/wallet?usr={user}"
|
||||
admin_url = (
|
||||
f"{http}://{settings.host}:{settings.port}/wallet?usr={user}"
|
||||
)
|
||||
logger.warning(f"✔️ Access admin user account at: {admin_url}")
|
||||
|
||||
if settings.lnbits_saas_callback and settings.lnbits_saas_secret and settings.lnbits_saas_instance_id:
|
||||
if (
|
||||
settings.lnbits_saas_callback
|
||||
and settings.lnbits_saas_secret
|
||||
and settings.lnbits_saas_instance_id
|
||||
):
|
||||
with httpx.Client() as client:
|
||||
headers = {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"X-API-KEY": settings.lnbits_saas_secret
|
||||
"X-API-KEY": settings.lnbits_saas_secret,
|
||||
}
|
||||
payload = {
|
||||
"instance_id": settings.lnbits_saas_instance_id,
|
||||
"adminuser": user
|
||||
"adminuser": user,
|
||||
}
|
||||
try:
|
||||
r = client.post(settings.lnbits_saas_callback, headers=headers, json=payload)
|
||||
client.post(
|
||||
settings.lnbits_saas_callback,
|
||||
headers=headers,
|
||||
json=payload,
|
||||
)
|
||||
logger.warning("sent admin user to saas application")
|
||||
except:
|
||||
logger.error(f"error sending admin user to saas: {settings.lnbits_saas_callback}")
|
||||
logger.error(
|
||||
f"error sending admin user to saas: {settings.lnbits_saas_callback}"
|
||||
)
|
||||
|
||||
except:
|
||||
logger.error("admin.settings tables does not exist.")
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ from .base import (
|
|||
|
||||
|
||||
class FakeWallet(Wallet):
|
||||
queue: asyncio.Queue = asyncio.Queue(0)
|
||||
secret: str = settings.fake_wallet_secret
|
||||
privkey: str = hashlib.pbkdf2_hmac(
|
||||
"sha256",
|
||||
|
|
@ -98,6 +97,7 @@ class FakeWallet(Wallet):
|
|||
return PaymentStatus(None)
|
||||
|
||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||
self.queue: asyncio.Queue = asyncio.Queue(0)
|
||||
while True:
|
||||
value: Invoice = await self.queue.get()
|
||||
yield value.payment_hash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue