feat: Add sync and fix emoji error

This commit is contained in:
Nathan Woodburn 2023-12-29 11:42:20 +11:00
parent 5f01cf5e83
commit 6aeb02cdd2
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
11 changed files with 77 additions and 41 deletions

View File

@ -199,3 +199,8 @@ def getDNS(domain: str):
"error": response['error']['message']
}
return response['result']['records']
def getNodeSync():
response = hsd.getInfo()
return response['chain']['progress']*100

View File

@ -10,7 +10,6 @@ import httpx
from requests_doh import DNSOverHTTPSSession, add_dns_provider
import requests
def hip2(domain: str):
domain_check = False
try:
@ -142,10 +141,16 @@ def niami_info(domain: str):
return False
response = response.json()
if response["data"]["owner_tx_data"] is not None:
output = {
"owner": response["data"]["owner_tx_data"]["address"],
"dns": response["data"]["dnsData"]
}
else:
output = {
"owner": None,
"dns": []
}
transactions = requests.get(f"https://api.niami.io/txs/{domain}")
if transactions.status_code != 200:
@ -156,3 +161,8 @@ def niami_info(domain: str):
return output
def emoji_to_punycode(emoji):
try:
return emoji.encode("idna").decode("ascii")
except Exception as e:
return ""

61
main.py
View File

@ -40,7 +40,8 @@ def index():
return render_template("index.html", account=account, available=available,
total=total, pending=pending, domains=domains, domain_count=domain_count)
total=total, pending=pending, domains=domains,
domain_count=domain_count, sync=account_module.getNodeSync())
#region Transactions
@app.route('/tx')
@ -55,7 +56,8 @@ def transactions():
transactions = account_module.getTransactions(account)
transactions = render.transactions(transactions)
return render_template("tx.html", account=account, tx=transactions)
return render_template("tx.html", account=account, sync=account_module.getNodeSync(),
tx=transactions)
@app.route('/send')
@ -82,8 +84,8 @@ def send_page():
amount = request.args.get("amount")
return render_template("send.html", account=account,max=max,message=message,
address=address,amount=amount)
return render_template("send.html", account=account,sync=account_module.getNodeSync(),
max=max,message=message,address=address,amount=amount)
@app.route('/send', methods=["POST"])
def send():
@ -137,7 +139,8 @@ def receive():
address = account_module.getAddress(account)
return render_template("receive.html", account=account, address=address)
return render_template("receive.html", account=account,sync=account_module.getNodeSync(),
address=address)
@app.route('/success')
def success():
@ -150,7 +153,8 @@ def success():
return redirect("/logout")
tx = request.args.get("tx")
return render_template("success.html", account=account, tx=tx)
return render_template("success.html", account=account,sync=account_module.getNodeSync(),
tx=tx)
@app.route('/checkaddress')
def check_address():
@ -175,18 +179,21 @@ def search():
search_term = request.args.get("q")
search_term = search_term.lower().strip()
# Convert emoji to punycode
search_term = domainLookup.emoji_to_punycode(search_term)
if len(search_term) == 0:
return redirect("/")
domain = account_module.getDomain(search_term)
if 'error' in domain:
return render_template("search.html", account=account, search_term=search_term, domain=domain['error'])
return render_template("search.html", account=account,sync=account_module.getNodeSync(),
search_term=search_term, domain=domain['error'])
print(domain)
if domain['info'] is None:
return render_template("search.html", account=account, search_term=search_term,
domain=search_term, state="AVAILABLE", next="Available Now")
return render_template("search.html", account=account, sync=account_module.getNodeSync(),
search_term=search_term,domain=search_term,
state="AVAILABLE", next="Available Now")
state = domain['info']['state']
@ -198,6 +205,15 @@ def search():
state = 'REGISTERED'
expires = domain['info']['stats']['daysUntilExpire']
next = f"Expires in ~{expires} days"
elif state == 'OPENING':
print(domain['info']['stats'])
next = "Bidding opens in ~" + str(domain['info']['stats']['blocksUntilBidding']) + " blocks"
elif state == 'BIDDING':
next = "Reveal in ~" + str(domain['info']['stats']['blocksUntilReveal']) + " blocks"
elif state == 'REVEAL':
print(domain['info']['stats'])
next = "Reveal ends in ~" + str(domain['info']['stats']['blocksUntilClose']) + " blocks"
domain_info = domainLookup.niami_info(search_term)
@ -218,9 +234,10 @@ def search():
dns = render.dns(dns)
txs = render.txs(txs)
return render_template("search.html", account=account, search_term=search_term,
domain=domain['info']['name'],raw=domain,
state=state, next=next, owner=owner, dns=dns, txs=txs)
return render_template("search.html", account=account, sync=account_module.getNodeSync(),
search_term=search_term,domain=domain['info']['name'],
raw=domain,state=state, next=next, owner=owner,
dns=dns, txs=txs)
@app.route('/manage/<domain>')
def manage(domain):
@ -242,15 +259,16 @@ def manage(domain):
domain_info = account_module.getDomain(domain)
if 'error' in domain_info:
return render_template("manage.html", account=account, domain=domain, error=domain_info['error'])
return render_template("manage.html", account=account, sync=account_module.getNodeSync(),
domain=domain, error=domain_info['error'])
expiry = domain_info['info']['stats']['daysUntilExpire']
dns = account_module.getDNS(domain)
dns = render.dns(dns)
return render_template("manage.html", account=account, domain=domain,
expiry=expiry, dns=dns)
return render_template("manage.html", account=account, sync=account_module.getNodeSync(),
domain=domain,expiry=expiry, dns=dns)
@app.route('/manage/<domain>/renew')
@ -274,7 +292,8 @@ def renew(domain):
@app.route('/login')
def login():
if 'message' in request.args:
return render_template("login.html", error=request.args.get("message"))
return render_template("login.html", sync=account_module.getNodeSync(),
error=request.args.get("message"))
return render_template("login.html")
@ -287,13 +306,15 @@ def login_post():
# Check if the account is valid
if account.count(":") > 0:
return render_template("login.html", error="Invalid account")
return render_template("login.html", sync=account_module.getNodeSync(),
error="Invalid account")
account = account + ":" + password
# Check if the account is valid
if not account_module.check_account(account):
return render_template("login.html", error="Invalid account")
return render_template("login.html", sync=account_module.getNodeSync(),
error="Invalid account")
# Set the cookie

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form>
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">