add more logic for monero checking and simple html table

pull/1/head
lza_menace 4 years ago
parent 62b4f391f4
commit 2faf28808f

@ -7,6 +7,7 @@ from datetime import datetime
from flask import Flask, request, redirect from flask import Flask, request, redirect
from flask import render_template, flash, url_for from flask import render_template, flash, url_for
from urllib.parse import urlparse from urllib.parse import urlparse
from xmrnodes.helpers import is_monero
from xmrnodes.forms import SubmitNode from xmrnodes.forms import SubmitNode
from xmrnodes.models import Node from xmrnodes.models import Node
@ -65,7 +66,7 @@ def add():
if Node.select().where(Node.url == url).exists(): if Node.select().where(Node.url == url).exists():
flash("This node is already in the database.") flash("This node is already in the database.")
else: else:
flash("Seems like a valid node. Added to the database and will check soon.") flash("Seems like a valid node URL. Added to the database and will check soon.")
node = Node(url=url) node = Node(url=url)
node.save() node.save()
return redirect("/") return redirect("/")
@ -79,7 +80,7 @@ def validate():
logging.info(f"Attempting to validate {node.url}") logging.info(f"Attempting to validate {node.url}")
if is_onion: if is_onion:
logging.info("onion address found") logging.info("onion address found")
node.tor = True node.is_tor = True
try: try:
r = requests.get(node.url + "/get_info", timeout=3) r = requests.get(node.url + "/get_info", timeout=3)
r.raise_for_status() r.raise_for_status()
@ -92,6 +93,7 @@ def validate():
node.available = True node.available = True
node.validated = True node.validated = True
node.datetime_checked = now node.datetime_checked = now
node.is_monero = is_monero(node.url)
node.save() node.save()
else: else:
logging.info("unexpected nettype") logging.info("unexpected nettype")

@ -2,11 +2,16 @@ from requests import get as r_get
def is_monero(url): def is_monero(url):
data = {"method": "get_block_header_by_height", "params": {"height": 0}} data = {"method": "get_block_header_by_height", "params": {"height": 0}}
known_hashes = [
"418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3", #mainnet
"48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b", #testnet
"76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb" #stagenet
]
try: try:
r = r_get(url + "/json_rpc", json=data) r = r_get(url + "/json_rpc", json=data)
r.raise_for_status() r.raise_for_status()
assert "result" in r.json() assert "result" in r.json()
is_xmr = r.json()["result"]["block_header"]["hash"] == "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3" is_xmr = r.json()["result"]["block_header"]["hash"] in known_hashes
return is_xmr return is_xmr
except: except:
return False return False

@ -9,10 +9,11 @@ db = SqliteDatabase(f"{data_dir}/sqlite.db")
class Node(Model): class Node(Model):
id = AutoField() id = AutoField()
url = CharField() url = CharField()
tor = BooleanField(default=False) is_tor = BooleanField(default=False)
available = BooleanField(default=False) available = BooleanField(default=False)
validated = BooleanField(default=False) validated = BooleanField(default=False)
nettype = CharField(null=True) nettype = CharField(null=True)
is_monero = BooleanField(default=False)
datetime_entered = DateTimeField(default=datetime.now) datetime_entered = DateTimeField(default=datetime.now)
datetime_checked = DateTimeField(default=None, null=True) datetime_checked = DateTimeField(default=None, null=True)
datetime_failed = DateTimeField(default=None, null=True) datetime_failed = DateTimeField(default=None, null=True)

@ -8,9 +8,27 @@
<h3>Add Node</h3> <h3>Add Node</h3>
</div> </div>
<table>
<tr>
<th>URL</th>
<th>Tor</th>
<th>Available</th>
<th>Network</th>
<th>Is Monero</th>
<th>Last Checked</th>
</tr>
{% for node in nodes %} {% for node in nodes %}
{{ node.url }}<br> <tr>
<td>{{ node.url }}</td>
<td>{{ node.is_tor }}</td>
<td>{{ node.available }}</td>
<td>{{ node.nettype }}</td>
<td>{{ node.is_monero }}</td>
<td>{{ node.datetime_checked }}</td>
</tr>
{% endfor %} {% endfor %}
</table>
<form method="POST" action="{{ url_for('add') }}"> <form method="POST" action="{{ url_for('add') }}">
{{ form.csrf_token }} {{ form.csrf_token }}

Loading…
Cancel
Save