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