cluster switch
This commit is contained in:
parent
a8b773a8a1
commit
5699dcf692
|
@ -19,7 +19,7 @@ Pre-alpha / demo only
|
|||
# Unix/macOS
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
PGDATABASE=da11copy PGUSER=query_user PGPASSWORD=secret TEMPLATES_AUTO_RELOAD=True flask run --port 5050 --debug --reload
|
||||
SOLANA_CLUSTER=testnet PGDATABASE=da11copy PGUSER=query_user PGPASSWORD=secret TEMPLATES_AUTO_RELOAD=True flask run --port 5050 --debug --reload
|
||||
```
|
||||
|
||||
Open Firefox Browser and navigate to ...
|
||||
|
|
20
app.py
20
app.py
|
@ -1,10 +1,11 @@
|
|||
from flask import Flask, render_template
|
||||
from turbo_flask import Turbo
|
||||
import transaction_database
|
||||
import recent_blocks_database
|
||||
import threading
|
||||
import time
|
||||
from random import shuffle
|
||||
|
||||
import transaction_database
|
||||
import recent_blocks_database
|
||||
import config
|
||||
|
||||
#
|
||||
# MAIN
|
||||
|
@ -16,6 +17,8 @@ turbo = Turbo(app)
|
|||
app.update_thread_started = False
|
||||
|
||||
|
||||
config = config.get_config()
|
||||
print("SOLANA_CLUSTER", config['cluster'])
|
||||
transaction_database.run_query()
|
||||
recent_blocks_database.run_query()
|
||||
print("SELFTEST passed")
|
||||
|
@ -26,22 +29,24 @@ print("SELFTEST passed")
|
|||
@app.route('/dashboard')
|
||||
def dashboard():
|
||||
start_if_needed()
|
||||
this_config = config.get_config()
|
||||
start = time.time()
|
||||
maprows = transaction_database.run_query()
|
||||
elapsed = time.time() - start
|
||||
if elapsed > .5:
|
||||
print("transaction_database.RunQuery() took", elapsed, "seconds")
|
||||
return render_template('dashboard.html', transactions=maprows)
|
||||
return render_template('dashboard.html', config=this_config, transactions=maprows)
|
||||
|
||||
@app.route('/recent-blocks')
|
||||
def recent_blocks():
|
||||
start_if_needed()
|
||||
this_config = get_config()
|
||||
start = time.time()
|
||||
maprows = recent_blocks_database.run_query()
|
||||
elapsed = time.time() - start
|
||||
if elapsed > .5:
|
||||
print("recent_blocks_database.RunQuery() took", elapsed, "seconds")
|
||||
return render_template('recent_blocks.html', blocks=maprows)
|
||||
return render_template('recent_blocks.html', config=this_config, blocks=maprows)
|
||||
|
||||
|
||||
def start_if_needed():
|
||||
|
@ -55,14 +60,15 @@ def start_if_needed():
|
|||
def update_load():
|
||||
with app.app_context():
|
||||
print('start turbo.js update poller')
|
||||
this_config = app.get_config()
|
||||
while True:
|
||||
# note: the push sends update to all subscribed clients
|
||||
|
||||
maprows = transaction_database.run_query()
|
||||
turbo.push(turbo.replace(render_template('_table.html', transactions=maprows), 'datatable'))
|
||||
turbo.push(turbo.replace(render_template('_table.html', config=this_config, transactions=maprows), 'datatable'))
|
||||
|
||||
maprows = recent_blocks_database.run_query()
|
||||
turbo.push(turbo.replace(render_template('_blockslist.html', blocks=maprows), 'blockslist'))
|
||||
turbo.push(turbo.replace(render_template('_blockslist.html', config=this_config, blocks=maprows), 'blockslist'))
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from os import environ
|
||||
|
||||
|
||||
def get_config():
|
||||
cluster_param = environ.get('SOLANA_CLUSTER')
|
||||
assert cluster_param is not None, "SOLANA_CLUSTER environment variable must be set"
|
||||
switch={
|
||||
'mainnet':{'cluster': 'mainnet', 'cluster_label': 'Mainnet'},
|
||||
'testnet':{'cluster': 'testnet', 'cluster_label': 'Testnet'},
|
||||
'devnet':{'cluster': 'devnet', 'cluster_label': 'Devnet'},
|
||||
}
|
||||
config = switch.get(cluster_param.lower())
|
||||
assert config is not None, f"No Config for " + cluster_param
|
||||
return config
|
|
@ -30,7 +30,7 @@
|
|||
<td>
|
||||
<div class="align-items-center text-truncate" style="width:300px">
|
||||
<span class="font-monospace">
|
||||
<a href="https://explorer.solana.com/tx/{{ tx.signature }}">{{ tx.signature }}</a>
|
||||
<a href="https://explorer.solana.com/tx/{{ tx.signature }}?cluster={{config.cluster}}">{{ tx.signature }}</a>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class="container mt-n2">
|
||||
<div class="card">
|
||||
|
||||
<div class="card-header align-items-center"><h3 class="card-header-title">Transactions Errors</h3>
|
||||
<div class="card-header align-items-center"><h3 class="card-header-title">Transactions Errors ({{config.cluster_label}})</h3>
|
||||
</div>
|
||||
<div class="table-responsive mb-0">
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class="container mt-n2">
|
||||
<div class="card">
|
||||
|
||||
<div class="card-header align-items-center"><h3 class="card-header-title">Recent Blocks</h3>
|
||||
<div class="card-header align-items-center"><h3 class="card-header-title">Recent Blocks ({{config.cluster_label}})</h3>
|
||||
</div>
|
||||
<!-- mb-0 = margin+padding bottom -->
|
||||
<div class="card-body mb-0 table-responsive">
|
||||
|
|
Loading…
Reference in New Issue