making separate class for LWS API

master
lza_menace 2 years ago
parent 65e7e5c4e3
commit 89d6690e90

@ -1,3 +1,21 @@
import requests
from lws import config
class LWS:
def __init__(self, admin_key):
self.admin_key = admin_key
def list_accounts(self):
endpoint = f"{config.LWS_ADMIN_URL}/list_accounts"
data = {"auth": self.admin_key}
try:
req = requests.post(endpoint, json=data, timeout=5)
req.raise_for_status()
if req.ok:
return req.json()
return {}
except Exception as e:
print(f"Failed to list accounts: {e}")
return {}

@ -2,8 +2,8 @@ import monero.seed
from quart import Blueprint, redirect, request, flash, render_template
from quart_auth import login_required
from lws.factory import bcrypt
from lws.models import Wallet, User
from lws.helpers import LWS
from lws import config
@ -12,14 +12,16 @@ bp = Blueprint('meta', 'meta')
@bp.route("/")
@login_required
async def index():
admin_exists = User.select().first()
if not admin_exists:
admin = User.select().first()
if not admin:
return redirect("/setup")
wallets = Wallet.select().order_by(Wallet.date.desc())
lws = LWS(admin.view_key)
return await render_template(
"index.html",
config=config,
wallets=wallets
wallets=wallets,
lws_accounts=lws.list_accounts()
)

@ -6,6 +6,10 @@
<hr>
<p>LWS Admin: {{ config.LWS_ADMIN_URL }}</p>
<p>LWS RPC: {{ config.LWS_URL }}</p>
<p>{{ wallets.count() }} wallet{% if wallets.count() > 1 %}s{% endif %} being scanned by LWS</p>
<!-- <p>{{ wallets.count() }} wallet{% if wallets.count() > 1 %}s{% endif %} being scanned by LWS</p> -->
<h3>Active Accounts</h3>
{% for a in lws_accounts['active'] %}
<li>{{ a['address'] }} - {{ a['scan_height'] }}</li>
{% endfor %}
{% endblock %}

Loading…
Cancel
Save