This commit is contained in:
39
main.py
39
main.py
@@ -16,6 +16,8 @@ import importlib
|
|||||||
import plugin as plugins_module
|
import plugin as plugins_module
|
||||||
import gitinfo
|
import gitinfo
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
|
import time
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
@@ -68,6 +70,10 @@ def reverseDirection(direction: str):
|
|||||||
|
|
||||||
|
|
||||||
#region Transactions
|
#region Transactions
|
||||||
|
# Add a cache for transactions with a timeout
|
||||||
|
tx_cache = {}
|
||||||
|
TX_CACHE_TIMEOUT = 60*5 # Cache timeout in seconds
|
||||||
|
|
||||||
@app.route('/tx')
|
@app.route('/tx')
|
||||||
def transactions():
|
def transactions():
|
||||||
# Check if the user is logged in
|
# Check if the user is logged in
|
||||||
@@ -84,13 +90,34 @@ def transactions():
|
|||||||
|
|
||||||
if page < 1:
|
if page < 1:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
transactions = account_module.getTransactions(account,page)
|
# Check for force refresh parameter
|
||||||
txCount = len(transactions)
|
force_refresh = request.args.get('refresh') == 'true'
|
||||||
transactions = render.transactions(transactions)
|
|
||||||
|
# Create a cache key based on account and page
|
||||||
|
cache_key = f"{account}_{page}"
|
||||||
|
|
||||||
|
# Check if data is in cache and not expired
|
||||||
|
current_time = time.time()
|
||||||
|
if not force_refresh and cache_key in tx_cache and (current_time - tx_cache[cache_key]['time'] < TX_CACHE_TIMEOUT):
|
||||||
|
transactions = tx_cache[cache_key]['data']
|
||||||
|
txCount = len(transactions)
|
||||||
|
transactions_html = tx_cache[cache_key]['html']
|
||||||
|
else:
|
||||||
|
# Fetch transactions from account module
|
||||||
|
transactions = account_module.getTransactions(account, page)
|
||||||
|
txCount = len(transactions)
|
||||||
|
transactions_html = render.transactions(transactions)
|
||||||
|
|
||||||
|
# Store in cache
|
||||||
|
tx_cache[cache_key] = {
|
||||||
|
'data': transactions,
|
||||||
|
'html': transactions_html,
|
||||||
|
'time': current_time
|
||||||
|
}
|
||||||
return render_template("tx.html", account=account,
|
return render_template("tx.html", account=account,
|
||||||
tx=transactions,
|
tx=transactions_html,
|
||||||
page=page,txCount=txCount)
|
page=page, txCount=txCount)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/send')
|
@app.route('/send')
|
||||||
|
|||||||
44
render.py
44
render.py
@@ -96,54 +96,60 @@ def transactions(txs):
|
|||||||
if len(txs) == 0:
|
if len(txs) == 0:
|
||||||
return '<tr><td colspan="5">No transactions found</td></tr>'
|
return '<tr><td colspan="5">No transactions found</td></tr>'
|
||||||
html = ''
|
html = ''
|
||||||
|
|
||||||
|
test = "1de69f8138513fd8d9f1b3a8285b06e4b94f74b919b123f5da37beb164bb1688"
|
||||||
for tx in txs:
|
for tx in txs:
|
||||||
action = "HNS Transfer"
|
action = "HNS Transfer"
|
||||||
address = tx["outputs"][0]["address"]
|
address = tx["outputs"][0]["address"]
|
||||||
hash = tx["hash"]
|
hash = tx["hash"]
|
||||||
confirmations=tx["confirmations"]
|
confirmations=tx["confirmations"]
|
||||||
|
incomming = True
|
||||||
amount = 0
|
amount = 0
|
||||||
incomming = False
|
|
||||||
isMulti = False
|
isMulti = False
|
||||||
nameHashes = []
|
nameHashes = []
|
||||||
|
|
||||||
if not tx["inputs"][0]["path"]:
|
if tx["hash"] == test:
|
||||||
incomming = True
|
with open("test.json", "w") as f:
|
||||||
|
json.dump(tx, f, indent=4)
|
||||||
|
|
||||||
for txInput in tx["inputs"]:
|
for txInput in tx["inputs"]:
|
||||||
if txInput["path"]:
|
if txInput["path"]:
|
||||||
|
incomming = False
|
||||||
amount -= txInput["value"]
|
amount -= txInput["value"]
|
||||||
|
|
||||||
|
if tx["hash"] == test:
|
||||||
|
print(f"TEXT TX INPUT VALUE: {amount}")
|
||||||
|
|
||||||
for output in tx["outputs"]:
|
for output in tx["outputs"]:
|
||||||
if output["covenant"]["action"] != "NONE":
|
if output["covenant"]["action"] != "NONE":
|
||||||
if action == "HNS Transfer":
|
if action == "HNS Transfer":
|
||||||
action = output["covenant"]["action"]
|
action = output["covenant"]["action"]
|
||||||
elif action == output["covenant"]["action"]:
|
elif action == output["covenant"]["action"]:
|
||||||
isMulti = True
|
isMulti = True
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
action = "Multiple Actions"
|
action = "Multiple Actions"
|
||||||
|
|
||||||
|
|
||||||
if output["covenant"]["items"] and len(output["covenant"]["items"]) > 0:
|
if output["covenant"]["items"] and len(output["covenant"]["items"]) > 0:
|
||||||
nameHashes.append(output["covenant"]["items"][0])
|
nameHashes.append(output["covenant"]["items"][0])
|
||||||
|
|
||||||
|
|
||||||
# Skip value of domains
|
if not incomming:
|
||||||
if output["covenant"]["action"] in ["FINALIZE", "RENEW"]:
|
if output["path"]:
|
||||||
continue
|
amount += output["value"]
|
||||||
|
else:
|
||||||
|
if output["path"] and output["covenant"]["action"] == "NONE":
|
||||||
|
amount += output["value"]
|
||||||
|
|
||||||
if not output["path"] and not incomming:
|
if not incomming:
|
||||||
amount += output["value"]
|
# Subtract fee to make it easier to read
|
||||||
elif output["path"] and incomming:
|
amount += tx["fee"]
|
||||||
amount += output["value"]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
amount = amount / 1000000
|
amount = amount / 1000000
|
||||||
humanAction = action
|
humanAction = action
|
||||||
|
|
||||||
if action == "HNS Transfer":
|
if action == "HNS Transfer":
|
||||||
if incomming:
|
if amount > 0:
|
||||||
humanAction = "Received HNS"
|
humanAction = "Received HNS"
|
||||||
else:
|
else:
|
||||||
humanAction = "Sent HNS"
|
humanAction = "Sent HNS"
|
||||||
@@ -173,9 +179,9 @@ def transactions(txs):
|
|||||||
name = None
|
name = None
|
||||||
humanAction += renderDomain(name) if name else "domain"
|
humanAction += renderDomain(name) if name else "domain"
|
||||||
|
|
||||||
if not incomming and amount > 0:
|
if amount < 0:
|
||||||
amount = f"<span style='color: red;'>-{amount:,.2f}</span>"
|
amount = f"<span style='color: red;'>{amount:,.2f}</span>"
|
||||||
elif incomming and amount > 0:
|
elif amount > 0:
|
||||||
amount = f"<span style='color: green;'>+{amount:,.2f}</span>"
|
amount = f"<span style='color: green;'>+{amount:,.2f}</span>"
|
||||||
else:
|
else:
|
||||||
amount = f"<span style='color: gray;'>0.00</span>"
|
amount = f"<span style='color: gray;'>0.00</span>"
|
||||||
|
|||||||
Reference in New Issue
Block a user