refactor crypto tracking and html

pull/1/head
lza_menace 4 years ago
parent 3d238846b8
commit 41abc64dd5

@ -8,7 +8,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.helpers import determine_crypto
from xmrnodes.forms import SubmitNode from xmrnodes.forms import SubmitNode
from xmrnodes.models import Node from xmrnodes.models import Node
@ -33,7 +33,16 @@ def index():
flash("Wow, wtf hackerman. Cool it.") flash("Wow, wtf hackerman. Cool it.")
page = 1 page = 1
nodes = Node.select().where(Node.validated==True).where(Node.is_monero==True).order_by( nettype = request.args.get("nettype", "mainnet")
crypto = request.args.get("crypto", "monero")
nodes = Node.select().where(
Node.validated==True
).where(
Node.nettype==nettype
).where(
Node.crypto==crypto
).order_by(
Node.datetime_entered.desc() Node.datetime_entered.desc()
) )
paginated = nodes.paginate(page, itp) paginated = nodes.paginate(page, itp)
@ -115,6 +124,7 @@ def validate():
assert "height" in r.json() assert "height" in r.json()
assert "nettype" in r.json() assert "nettype" in r.json()
nettype = r.json()["nettype"] nettype = r.json()["nettype"]
crypto = determine_crypto(node.url)
logging.info("success") logging.info("success")
if nettype in ["mainnet", "stagenet", "testnet"]: if nettype in ["mainnet", "stagenet", "testnet"]:
node.nettype = nettype node.nettype = nettype
@ -122,7 +132,7 @@ def validate():
node.validated = True node.validated = True
node.last_height = r.json()["height"] node.last_height = r.json()["height"]
node.datetime_checked = now node.datetime_checked = now
node.is_monero = is_monero(node.url) node.crypto = crypto
node.save() node.save()
else: else:
logging.info("unexpected nettype") logging.info("unexpected nettype")

@ -1,17 +1,28 @@
from requests import get as r_get from requests import get as r_get
def is_monero(url): def determine_crypto(url):
data = {"method": "get_block_header_by_height", "params": {"height": 0}} data = {"method": "get_block_header_by_height", "params": {"height": 0}}
known_hashes = [ hashes = {
"monero": [
"418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3", #mainnet "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3", #mainnet
"48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b", #testnet "48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b", #testnet
"76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb" #stagenet "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb" #stagenet
],
"wownero": [
"a3fd635dd5cb55700317783469ba749b5259f0eeac2420ab2c27eb3ff5ffdc5c", #mainnet
"d81a24c7aad4628e5c9129f8f2ec85888885b28cf468597a9762c3945e9f29aa", #testnet
] ]
}
try: try:
r = r_get(url + "/json_rpc", json=data, timeout=5) r = r_get(url + "/json_rpc", json=data, timeout=5)
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"] in known_hashes hash = r.json()["result"]["block_header"]["hash"]
return is_xmr crypto = "unknown"
for c, h in hashes.items():
if hash in h:
crypto = c
break
return crypto
except: except:
return False return "unknown"

@ -14,7 +14,7 @@ class Node(Model):
validated = BooleanField(default=False) validated = BooleanField(default=False)
nettype = CharField(null=True) nettype = CharField(null=True)
last_height = IntegerField(null=True) last_height = IntegerField(null=True)
is_monero = BooleanField(default=False) crypto = CharField(null=True)
datetime_entered = DateTimeField(default=datetime.utcnow) datetime_entered = DateTimeField(default=datetime.utcnow)
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)

@ -23,3 +23,11 @@ input[type="text"] {
.flashes { .flashes {
padding-top: 1em; padding-top: 1em;
} }
.search-btn {
margin: 2em .5em 0 .5em;
}
.wownero {
background-color: rgb(235, 74, 206);
}

@ -63,6 +63,11 @@
{% else %} {% else %}
<p>No nodes in the database yet...</p> <p>No nodes in the database yet...</p>
{% endif %} {% endif %}
<br>
<a href="/?nettype=mainnet"><button class="pure-button search-btn">Mainnet</button></a>
<a href="/?nettype=testnet"><button class="pure-button search-btn">Testnet</button></a>
<a href="/?nettype=stagenet"><button class="pure-button search-btn">Stagenet</button></a>
<a href="/?crypto=wownero"><button class="pure-button search-btn wownero">Wownero</button></a>
</div> </div>
</div> </div>

Loading…
Cancel
Save