brush special pages
This commit is contained in:
parent
708c037a9f
commit
1f82fd3144
20
app.py
20
app.py
|
@ -57,8 +57,16 @@ def is_slot_number(raw_string):
|
|||
return re.fullmatch("[0-9]+", raw_string) is not None
|
||||
|
||||
|
||||
|
||||
def is_block_hash(raw_string):
|
||||
# regex is not perfect - feel free to improve
|
||||
return re.fullmatch("[0-9a-zA-Z]{43,44}", raw_string) is not None
|
||||
|
||||
|
||||
def is_tx_sig(raw_string):
|
||||
# regex is not perfect - feel free to improve
|
||||
if is_block_hash(raw_string):
|
||||
return False
|
||||
return re.fullmatch("[0-9a-zA-Z]{64,100}", raw_string) is not None
|
||||
|
||||
|
||||
|
@ -67,15 +75,23 @@ def search():
|
|||
this_config = config.get_config()
|
||||
if htmx:
|
||||
search_string = request.form.get("search").strip()
|
||||
print("search_string=", search_string)
|
||||
|
||||
if is_slot_number(search_string):
|
||||
print("slot search=", search_string)
|
||||
maprows = list(recent_blocks_database.find_block_by_slotnumber(int(search_string)))
|
||||
if len(maprows):
|
||||
return render_template('_blockslist.html', config=this_config, blocks=maprows)
|
||||
else:
|
||||
return render_template('_search_noresult.html')
|
||||
elif is_block_hash(search_string):
|
||||
print("blockhash search=", search_string)
|
||||
maprows = list(recent_blocks_database.find_block_by_blockhash(search_string))
|
||||
if len(maprows):
|
||||
return render_template('_blockslist.html', config=this_config, blocks=maprows)
|
||||
else:
|
||||
return render_template('_search_noresult.html')
|
||||
elif is_tx_sig(search_string):
|
||||
print("txsig search=", search_string)
|
||||
maprows = list(transaction_database.find_transaction_by_sig(search_string))
|
||||
if len(maprows):
|
||||
return render_template('_txlist.html', config=this_config, transactions=maprows)
|
||||
|
@ -117,7 +133,7 @@ def update_load():
|
|||
# note: the push sends update to all subscribed clients
|
||||
|
||||
maprows = list(transaction_database.run_query())
|
||||
turbo.push(turbo.replace(render_template('_txlist.html', config=this_config, transactions=maprows), 'datatable'))
|
||||
turbo.push(turbo.replace(render_template('_txlist.html', config=this_config, transactions=maprows), 'txlist'))
|
||||
|
||||
maprows = list(recent_blocks_database.run_query())
|
||||
turbo.push(turbo.replace(render_template('_blockslist.html', config=this_config, blocks=maprows), 'blockslist'))
|
||||
|
|
|
@ -76,9 +76,9 @@ def run_query():
|
|||
maprows = [dict(zip(keys, row)) for row in cursor]
|
||||
|
||||
# print some samples
|
||||
for row in maprows[:3]:
|
||||
print(row)
|
||||
print("...")
|
||||
# for row in maprows[:3]:
|
||||
# print(row)
|
||||
# print("...")
|
||||
|
||||
for row in maprows:
|
||||
calc_bars(row)
|
||||
|
@ -87,10 +87,9 @@ def run_query():
|
|||
return maprows
|
||||
|
||||
|
||||
def find_block_by_slotnumber(slot_number):
|
||||
def find_block_by_slotnumber(slot_number: int):
|
||||
con = postgres_connection.create_connection()
|
||||
cursor = con.cursor()
|
||||
# uses index idx_blocks_slot
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM (
|
||||
|
@ -103,7 +102,7 @@ def find_block_by_slotnumber(slot_number):
|
|||
total_cu_used,
|
||||
total_cu_requested
|
||||
FROM banking_stage_results.blocks
|
||||
-- this critera uses index idx_blocks_slot_errors
|
||||
-- this critera uses index idx_blocks_slot
|
||||
WHERE slot = %s
|
||||
) AS data
|
||||
""", args=[slot_number])
|
||||
|
@ -120,6 +119,40 @@ def find_block_by_slotnumber(slot_number):
|
|||
return maprows
|
||||
|
||||
|
||||
def find_block_by_blockhash(block_hash: str):
|
||||
con = postgres_connection.create_connection()
|
||||
cursor = con.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
ROW_NUMBER() OVER () AS pos,
|
||||
slot,
|
||||
processed_transactions,
|
||||
successful_transactions,
|
||||
banking_stage_errors,
|
||||
total_cu_used,
|
||||
total_cu_requested
|
||||
FROM banking_stage_results.blocks
|
||||
-- uses index on primary key
|
||||
WHERE block_hash = %s
|
||||
) AS data
|
||||
""", args=[block_hash])
|
||||
|
||||
keys = [k[0] for k in cursor.description]
|
||||
maprows = [dict(zip(keys, row)) for row in cursor]
|
||||
|
||||
assert len(maprows) <= 1, "Block hash is unique - find zero or one"
|
||||
|
||||
for row in maprows:
|
||||
calc_bars(row)
|
||||
calc_figures(row)
|
||||
|
||||
print("found ", maprows, block_hash)
|
||||
|
||||
return maprows
|
||||
|
||||
|
||||
def main():
|
||||
run_query()
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!-- note: this fragment gets used on recent-blocks and search page -->
|
||||
<table id="blockslist" class="table table-sm table-nowrap">
|
||||
<table id="blockslist" class="table table-sm table-nowrap card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-muted">Slot #</th>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<tr>
|
||||
<td colspan="3">NO RESULT</td>
|
||||
</tr>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title text-warning">No Data found</h5>
|
||||
<p class="card-text">Note: the database contains only a subset of the chain's data!</p>
|
||||
</div>
|
|
@ -1,3 +1,13 @@
|
|||
<tr>
|
||||
<td colspan="3"><span class="text-warning">unsupported string:</span> <span class="font-monospace">'{{ search_string }}'</span></td>
|
||||
</tr>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title text-warning">Unsupported Format</h5>
|
||||
<p class="card-text">
|
||||
The search string <span class="font-monospace">'{{ search_string }}'</span> was not recognized.
|
||||
|
||||
Supported formats:
|
||||
<ul>
|
||||
<li><b>Signature</b> (e.g. 4jvxUpPwq564752PiZ9YvbiaiuhLqUyGQfg3ZcY1MTWctUQvWVQvnXtGCSRcBqPcEZ7fyPpveQxmajasuAMWTBY1)</li>
|
||||
<li><b>Slot Number</b> (e.g. 230739932)</li>
|
||||
<li><b>Blockhash</b> (e.g. iyE1zMCPKz4mjeSWxNRVufEfLnYL8QxKzJMm8AzDE3d)</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
|
@ -1,4 +1,4 @@
|
|||
<table id="datatable" class="able table-sm table-nowrap card-table">
|
||||
<table id="txlist" class="table table-sm table-nowrap card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-muted c-pointer">#</th>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class="container mt-n2">
|
||||
|
||||
</div>
|
||||
<div class="container-fluid mt-n2">
|
||||
<div class="container mt-n2">
|
||||
|
||||
<div class="card">
|
||||
|
||||
|
@ -50,8 +50,5 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -32,9 +32,9 @@ def run_query():
|
|||
maprows = [dict(zip(keys, row)) for row in cursor]
|
||||
|
||||
# print some samples
|
||||
for row in maprows[:3]:
|
||||
print(row)
|
||||
print("...")
|
||||
# for row in maprows[:3]:
|
||||
# print(row)
|
||||
# print("...")
|
||||
|
||||
for row in maprows:
|
||||
# note: type changed from 'text' to 'text[]'
|
||||
|
@ -43,7 +43,7 @@ def run_query():
|
|||
return maprows
|
||||
|
||||
|
||||
def find_transaction_by_sig(tx_sig):
|
||||
def find_transaction_by_sig(tx_sig: str):
|
||||
con = postgres_connection.create_connection()
|
||||
cursor = con.cursor()
|
||||
# transaction table primary key is uses
|
||||
|
|
Loading…
Reference in New Issue