Compare commits
6 Commits
test/gitea
...
feat/aucti
| Author | SHA1 | Date | |
|---|---|---|---|
|
525b068f14
|
|||
|
6b69f933c3
|
|||
|
6271cf810e
|
|||
|
61d9f209b7
|
|||
|
b2db24c08e
|
|||
|
7dda41bda7
|
Binary file not shown.
367
account.py
367
account.py
@@ -7,6 +7,7 @@ import re
|
|||||||
import domainLookup
|
import domainLookup
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import concurrent.futures
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
@@ -611,45 +612,202 @@ def getWalletStatus():
|
|||||||
return "Error wallet ahead of node"
|
return "Error wallet ahead of node"
|
||||||
|
|
||||||
|
|
||||||
|
# Add a simple cache for bid data
|
||||||
|
_bid_cache = {}
|
||||||
|
_bid_cache_time = {}
|
||||||
|
_cache_duration = 300 # Increased cache duration to 5 minutes for bids
|
||||||
|
|
||||||
|
# Add domain info cache
|
||||||
|
_domain_info_cache = {}
|
||||||
|
_domain_info_time = {}
|
||||||
|
_domain_info_duration = 600 # Cache domain info for 10 minutes
|
||||||
|
|
||||||
|
# Add wallet authentication cache
|
||||||
|
_wallet_auth_cache = {}
|
||||||
|
_wallet_auth_time = {}
|
||||||
|
_wallet_auth_duration = 300 # Increased to 5 minutes for wallet auth
|
||||||
|
|
||||||
def getBids(account, domain="NONE"):
|
def getBids(account, domain="NONE"):
|
||||||
if domain == "NONE":
|
cache_key = f"{account}:{domain}"
|
||||||
response = hsw.getWalletBids(account)
|
current_time = time.time()
|
||||||
else:
|
|
||||||
response = hsw.getWalletBidsByName(domain, account)
|
# Return cached data if available and fresh
|
||||||
# Add backup for bids with no value
|
if cache_key in _bid_cache and current_time - _bid_cache_time.get(cache_key, 0) < _cache_duration:
|
||||||
bids = []
|
return _bid_cache[cache_key]
|
||||||
for bid in response:
|
|
||||||
if 'value' not in bid:
|
try:
|
||||||
bid['value'] = -1000000
|
if domain == "NONE":
|
||||||
|
response = hsw.getWalletBids(account)
|
||||||
|
else:
|
||||||
|
response = hsw.getWalletBidsByName(domain, account)
|
||||||
|
|
||||||
|
# Add backup for bids with no value
|
||||||
|
bids = []
|
||||||
|
for bid in response:
|
||||||
|
if 'value' not in bid:
|
||||||
|
bid['value'] = -1000000
|
||||||
|
|
||||||
|
# Backup for older HSD versions
|
||||||
|
if 'height' not in bid:
|
||||||
|
bid['height'] = 0
|
||||||
|
bids.append(bid)
|
||||||
|
|
||||||
|
# Cache the results
|
||||||
|
_bid_cache[cache_key] = bids
|
||||||
|
_bid_cache_time[cache_key] = current_time
|
||||||
|
|
||||||
|
return bids
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error fetching bids: {str(e)}")
|
||||||
|
return []
|
||||||
|
|
||||||
# Backup for older HSD versions
|
def _fetch_domain_info(domain):
|
||||||
if 'height' not in bid:
|
"""Helper function to fetch domain info with caching"""
|
||||||
bid['height'] = 0
|
current_time = time.time()
|
||||||
bids.append(bid)
|
|
||||||
return bids
|
# Check cache first
|
||||||
|
if (domain in _domain_info_cache and
|
||||||
|
current_time - _domain_info_time.get(domain, 0) < _domain_info_duration):
|
||||||
|
return _domain_info_cache[domain]
|
||||||
|
|
||||||
|
# Fetch domain info
|
||||||
|
domain_info = getDomain(domain)
|
||||||
|
|
||||||
|
# Store in cache
|
||||||
|
_domain_info_cache[domain] = domain_info
|
||||||
|
_domain_info_time[domain] = current_time
|
||||||
|
|
||||||
|
return domain_info
|
||||||
|
|
||||||
|
def _fetch_domain_batch(domains, max_workers=10):
|
||||||
|
"""Fetch multiple domains in parallel"""
|
||||||
|
results = {}
|
||||||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
||||||
|
# Create a mapping of futures to domains
|
||||||
|
future_to_domain = {executor.submit(_fetch_domain_info, domain): domain for domain in domains}
|
||||||
|
|
||||||
|
# Process as they complete
|
||||||
|
for future in concurrent.futures.as_completed(future_to_domain):
|
||||||
|
domain = future_to_domain[future]
|
||||||
|
try:
|
||||||
|
results[domain] = future.result()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error fetching domain {domain}: {str(e)}")
|
||||||
|
results[domain] = {"error": str(e)}
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def getPossibleOutbids(account):
|
||||||
|
# Get all bids
|
||||||
|
bids = getBids(account)
|
||||||
|
if not bids or 'error' in bids:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Get current height
|
||||||
|
current_height = getBlockHeight()
|
||||||
|
|
||||||
|
# Sort out bids older than 720 blocks and extract domain names
|
||||||
|
filtered_bids = []
|
||||||
|
domains_to_check = set()
|
||||||
|
|
||||||
|
for bid in bids:
|
||||||
|
if (current_height - bid['height']) <= 720:
|
||||||
|
filtered_bids.append(bid)
|
||||||
|
domains_to_check.add(bid['name'])
|
||||||
|
|
||||||
|
if not domains_to_check:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Fetch all domain info in parallel
|
||||||
|
domain_info_map = _fetch_domain_batch(domains_to_check)
|
||||||
|
|
||||||
|
# Pre-filter domains in bidding state
|
||||||
|
bidding_domains = {
|
||||||
|
domain: info for domain, info in domain_info_map.items()
|
||||||
|
if ('info' in info and 'state' in info['info'] and
|
||||||
|
info['info']['state'] == "BIDDING")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process the results
|
||||||
|
possible_outbids = []
|
||||||
|
processed_domains = set()
|
||||||
|
|
||||||
|
# Group bids by domain name for efficient processing
|
||||||
|
bids_by_domain = {}
|
||||||
|
for bid in filtered_bids:
|
||||||
|
domain = bid['name']
|
||||||
|
if domain not in bids_by_domain:
|
||||||
|
bids_by_domain[domain] = []
|
||||||
|
bids_by_domain[domain].append(bid)
|
||||||
|
|
||||||
|
# Analyze each domain in bidding state
|
||||||
|
for domain, info in bidding_domains.items():
|
||||||
|
if domain in processed_domains or domain not in bids_by_domain:
|
||||||
|
continue
|
||||||
|
|
||||||
|
processed_domains.add(domain)
|
||||||
|
|
||||||
|
# Get all bids for this domain in one call
|
||||||
|
domain_bids = getBids(account, domain)
|
||||||
|
|
||||||
|
# Find the highest bid we've made
|
||||||
|
our_highest_bid = max(
|
||||||
|
(bid['value'] for bid in domain_bids if bid.get("own", False)),
|
||||||
|
default=0
|
||||||
|
)
|
||||||
|
|
||||||
|
# Quick check if any unrevealed bids could outbid us
|
||||||
|
if any(
|
||||||
|
bid["lockup"] > our_highest_bid
|
||||||
|
for bid in domain_bids
|
||||||
|
if not bid.get("own", False) and bid.get('value', 0) == -1000000
|
||||||
|
):
|
||||||
|
possible_outbids.append(domain)
|
||||||
|
|
||||||
|
return possible_outbids
|
||||||
|
|
||||||
def getReveals(account, domain):
|
def getReveals(account, domain):
|
||||||
return hsw.getWalletRevealsByName(domain, account)
|
return hsw.getWalletRevealsByName(domain, account)
|
||||||
|
|
||||||
|
|
||||||
def getPendingReveals(account):
|
def getPendingReveals(account):
|
||||||
bids = getBids(account)
|
bids = getBids(account)
|
||||||
domains = getDomains(account, False)
|
# Only get domains in REVEAL state to reduce API calls
|
||||||
|
domains = [d for d in getDomains(account, False) if d['state'] == "REVEAL"]
|
||||||
|
|
||||||
|
if not domains: # Early return if no domains in REVEAL state
|
||||||
|
return []
|
||||||
|
|
||||||
pending = []
|
pending = []
|
||||||
for domain in domains:
|
|
||||||
if domain['state'] == "REVEAL":
|
# Create a dictionary for O(1) lookups
|
||||||
reveals = getReveals(account, domain['name'])
|
domain_names = {domain['name']: domain for domain in domains}
|
||||||
for bid in bids:
|
|
||||||
if bid['name'] == domain['name']:
|
# Group bids by name to batch process reveals
|
||||||
state_found = False
|
bids_by_name = {}
|
||||||
for reveal in reveals:
|
for bid in bids:
|
||||||
if reveal['own'] == True:
|
if bid['name'] in domain_names:
|
||||||
if bid['value'] == reveal['value']:
|
if bid['name'] not in bids_by_name:
|
||||||
state_found = True
|
bids_by_name[bid['name']] = []
|
||||||
|
bids_by_name[bid['name']].append(bid)
|
||||||
if not state_found:
|
|
||||||
pending.append(bid)
|
# Fetch reveals for each domain once
|
||||||
|
reveals_by_name = {}
|
||||||
|
for domain_name in bids_by_name:
|
||||||
|
reveals_by_name[domain_name] = getReveals(account, domain_name)
|
||||||
|
|
||||||
|
# Check each bid against the reveals
|
||||||
|
for domain_name, domain_bids in bids_by_name.items():
|
||||||
|
domain_reveals = reveals_by_name[domain_name]
|
||||||
|
for bid in domain_bids:
|
||||||
|
# Check if this bid has been revealed
|
||||||
|
bid_revealed = any(
|
||||||
|
reveal['own'] == True and bid['value'] == reveal['value']
|
||||||
|
for reveal in domain_reveals
|
||||||
|
)
|
||||||
|
|
||||||
|
if not bid_revealed:
|
||||||
|
pending.append(bid)
|
||||||
|
|
||||||
return pending
|
return pending
|
||||||
|
|
||||||
|
|
||||||
@@ -662,20 +820,27 @@ def getPendingRedeems(account, password):
|
|||||||
|
|
||||||
pending = []
|
pending = []
|
||||||
try:
|
try:
|
||||||
|
# Collect all nameHashes first
|
||||||
|
name_hashes = []
|
||||||
for output in tx['result']['outputs']:
|
for output in tx['result']['outputs']:
|
||||||
if output['covenant']['type'] != 5:
|
if output['covenant']['type'] != 5:
|
||||||
continue
|
continue
|
||||||
if output['covenant']['action'] != "REDEEM":
|
if output['covenant']['action'] != "REDEEM":
|
||||||
continue
|
continue
|
||||||
nameHash = output['covenant']['items'][0]
|
name_hashes.append(output['covenant']['items'][0])
|
||||||
# Try to get the name from hash
|
|
||||||
name = hsd.rpc_getNameByHash(nameHash)
|
# Batch processing name hashes
|
||||||
|
name_lookup = {}
|
||||||
|
for name_hash in name_hashes:
|
||||||
|
name = hsd.rpc_getNameByHash(name_hash)
|
||||||
if name['error']:
|
if name['error']:
|
||||||
pending.append(nameHash)
|
pending.append(name_hash)
|
||||||
else:
|
else:
|
||||||
pending.append(name['result'])
|
pending.append(name['result'])
|
||||||
except:
|
name_lookup[name_hash] = name['result']
|
||||||
print("Failed to parse redeems")
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to parse redeems: {str(e)}")
|
||||||
|
|
||||||
return pending
|
return pending
|
||||||
|
|
||||||
@@ -683,13 +848,22 @@ def getPendingRedeems(account, password):
|
|||||||
def getPendingRegisters(account):
|
def getPendingRegisters(account):
|
||||||
bids = getBids(account)
|
bids = getBids(account)
|
||||||
domains = getDomains(account, False)
|
domains = getDomains(account, False)
|
||||||
|
|
||||||
|
# Create dictionaries for O(1) lookups
|
||||||
|
bids_by_name = {}
|
||||||
|
for bid in bids:
|
||||||
|
if bid['name'] not in bids_by_name:
|
||||||
|
bids_by_name[bid['name']] = []
|
||||||
|
bids_by_name[bid['name']].append(bid)
|
||||||
|
|
||||||
pending = []
|
pending = []
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
if domain['state'] == "CLOSED" and domain['registered'] == False:
|
if domain['state'] == "CLOSED" and domain['registered'] == False:
|
||||||
for bid in bids:
|
if domain['name'] in bids_by_name:
|
||||||
if bid['name'] == domain['name']:
|
for bid in bids_by_name[domain['name']]:
|
||||||
if bid['value'] == domain['highest']:
|
if bid['value'] == domain['highest']:
|
||||||
pending.append(bid)
|
pending.append(bid)
|
||||||
|
|
||||||
return pending
|
return pending
|
||||||
|
|
||||||
|
|
||||||
@@ -700,20 +874,26 @@ def getPendingFinalizes(account, password):
|
|||||||
|
|
||||||
pending = []
|
pending = []
|
||||||
try:
|
try:
|
||||||
|
# Collect all nameHashes first
|
||||||
|
name_hashes = []
|
||||||
for output in tx['outputs']:
|
for output in tx['outputs']:
|
||||||
if output['covenant']['type'] != 10:
|
if output['covenant']['type'] != 10:
|
||||||
continue
|
continue
|
||||||
if output['covenant']['action'] != "FINALIZE":
|
if output['covenant']['action'] != "FINALIZE":
|
||||||
continue
|
continue
|
||||||
nameHash = output['covenant']['items'][0]
|
name_hashes.append(output['covenant']['items'][0])
|
||||||
# Try to get the name from hash
|
|
||||||
name = hsd.rpc_getNameByHash(nameHash)
|
# Batch lookup for name hashes
|
||||||
|
for name_hash in name_hashes:
|
||||||
|
name = hsd.rpc_getNameByHash(name_hash)
|
||||||
if name['error']:
|
if name['error']:
|
||||||
pending.append(nameHash)
|
pending.append(name_hash)
|
||||||
else:
|
else:
|
||||||
pending.append(name['result'])
|
pending.append(name['result'])
|
||||||
except:
|
|
||||||
print("Failed to parse finalizes")
|
except Exception as e:
|
||||||
|
print(f"Failed to parse finalizes: {str(e)}")
|
||||||
|
|
||||||
return pending
|
return pending
|
||||||
|
|
||||||
|
|
||||||
@@ -1056,19 +1236,51 @@ def revoke(account, domain):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def sendBatch(account, batch):
|
def _prepare_wallet_for_batch(account_name, password):
|
||||||
account_name = check_account(account)
|
"""Helper function to prepare wallet for batch operations with caching"""
|
||||||
password = ":".join(account.split(":")[1:])
|
cache_key = f"{account_name}:{password}"
|
||||||
|
current_time = time.time()
|
||||||
if account_name == False:
|
|
||||||
return {
|
# Return cached authentication if available and fresh
|
||||||
"error": {
|
if (cache_key in _wallet_auth_cache and
|
||||||
"message": "Invalid account"
|
current_time - _wallet_auth_time.get(cache_key, 0) < _wallet_auth_duration):
|
||||||
}
|
return _wallet_auth_cache[cache_key]
|
||||||
}
|
|
||||||
|
# Select and unlock wallet
|
||||||
|
result = {'success': False, 'error': None}
|
||||||
|
|
||||||
|
# Try to select the wallet
|
||||||
|
select_response = hsw.rpc_selectWallet(account_name)
|
||||||
|
if select_response['error'] is not None:
|
||||||
|
result['error'] = {"message": select_response['error']['message']}
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Try to unlock the wallet
|
||||||
|
unlock_response = hsw.rpc_walletPassphrase(password, 30) # Increased timeout to reduce future unlocks
|
||||||
|
if (unlock_response['error'] is not None and
|
||||||
|
unlock_response['error']['message'] != "Wallet is not encrypted."):
|
||||||
|
result['error'] = {"message": unlock_response['error']['message']}
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Authentication successful
|
||||||
|
result['success'] = True
|
||||||
|
|
||||||
|
# Cache the authentication result
|
||||||
|
_wallet_auth_cache[cache_key] = result
|
||||||
|
_wallet_auth_time[cache_key] = current_time
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _execute_batch_operation(account_name, batch, operation_type="sendbatch"):
|
||||||
|
"""Execute a batch operation with the specified wallet"""
|
||||||
|
# Make the batch request
|
||||||
try:
|
try:
|
||||||
response = hsw.rpc_selectWallet(account_name)
|
response = requests.post(
|
||||||
|
get_wallet_api_url(),
|
||||||
|
json={"method": operation_type, "params": [batch]},
|
||||||
|
timeout=30 # Add timeout to prevent hanging
|
||||||
|
).json()
|
||||||
|
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@@ -1090,31 +1302,42 @@ def sendBatch(account, batch):
|
|||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return response
|
return response
|
||||||
if 'result' not in response:
|
if 'result' not in response:
|
||||||
return {
|
return {"error": {"message": "No result"}}
|
||||||
"error": {
|
|
||||||
"message": "No result"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response['result']
|
return response['result']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {"error": {"message": str(e)}}
|
||||||
"error": {
|
|
||||||
"message": str(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
def sendBatch(account, batch):
|
||||||
|
account_name = check_account(account)
|
||||||
|
if account_name == False:
|
||||||
|
return {"error": {"message": "Invalid account"}}
|
||||||
|
|
||||||
|
password = ":".join(account.split(":")[1:])
|
||||||
|
|
||||||
|
# Prepare the wallet (this uses caching)
|
||||||
|
auth_result = _prepare_wallet_for_batch(account_name, password)
|
||||||
|
if not auth_result['success']:
|
||||||
|
return auth_result['error']
|
||||||
|
|
||||||
|
# Execute the batch operation
|
||||||
|
return _execute_batch_operation(account_name, batch, "sendbatch")
|
||||||
|
|
||||||
def createBatch(account, batch):
|
def createBatch(account, batch):
|
||||||
account_name = check_account(account)
|
account_name = check_account(account)
|
||||||
password = ":".join(account.split(":")[1:])
|
|
||||||
|
|
||||||
if account_name == False:
|
if account_name == False:
|
||||||
return {
|
return {"error": {"message": "Invalid account"}}
|
||||||
"error": {
|
|
||||||
"message": "Invalid account"
|
password = ":".join(account.split(":")[1:])
|
||||||
}
|
|
||||||
}
|
# Prepare the wallet (this uses caching)
|
||||||
|
auth_result = _prepare_wallet_for_batch(account_name, password)
|
||||||
|
if not auth_result['success']:
|
||||||
|
return auth_result['error']
|
||||||
|
|
||||||
|
# Execute the batch operation
|
||||||
|
return _execute_batch_operation(account_name, batch, "createbatch")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = hsw.rpc_selectWallet(account_name)
|
response = hsw.rpc_selectWallet(account_name)
|
||||||
|
|||||||
72
main.py
72
main.py
@@ -56,6 +56,14 @@ def blocks_to_time(blocks: int) -> str:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Add a cache for transactions with a timeout
|
||||||
|
tx_cache = {}
|
||||||
|
TX_CACHE_TIMEOUT = 60*5 # Cache timeout in seconds
|
||||||
|
|
||||||
|
# Add a cache for outbids with a timeout
|
||||||
|
outbids_cache = {}
|
||||||
|
OUTBIDS_CACHE_TIMEOUT = 60*2 # Cache timeout in seconds
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
# Check if the user is logged in
|
# Check if the user is logged in
|
||||||
@@ -94,10 +102,6 @@ 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
|
||||||
@@ -318,8 +322,12 @@ def auctions():
|
|||||||
sort_time = direction
|
sort_time = direction
|
||||||
sort_time_next = reverseDirection(direction)
|
sort_time_next = reverseDirection(direction)
|
||||||
|
|
||||||
|
# Check if bids list is empty to avoid IndexError
|
||||||
|
if not bids:
|
||||||
|
domains = sorted(domains, key=lambda k: k['height'],reverse=reverse)
|
||||||
|
sortbyDomain = True
|
||||||
# If older HSD version sort by domain height
|
# If older HSD version sort by domain height
|
||||||
if bids[0]['height'] == 0:
|
elif bids[0]['height'] == 0:
|
||||||
domains = sorted(domains, key=lambda k: k['height'],reverse=reverse)
|
domains = sorted(domains, key=lambda k: k['height'],reverse=reverse)
|
||||||
sortbyDomain = True
|
sortbyDomain = True
|
||||||
else:
|
else:
|
||||||
@@ -330,7 +338,27 @@ def auctions():
|
|||||||
sort_domain = direction
|
sort_domain = direction
|
||||||
sort_domain_next = reverseDirection(direction)
|
sort_domain_next = reverseDirection(direction)
|
||||||
|
|
||||||
bidsHtml = render.bidDomains(bids,domains,sortbyDomain)
|
# Check if outbids set to true
|
||||||
|
outbids = request.args.get("outbids")
|
||||||
|
if outbids is not None and outbids.lower() == "true":
|
||||||
|
# Check cache before making expensive call
|
||||||
|
cache_key = f"outbids_{account}"
|
||||||
|
current_time = time.time()
|
||||||
|
|
||||||
|
if cache_key in outbids_cache and (current_time - outbids_cache[cache_key]['time'] < OUTBIDS_CACHE_TIMEOUT):
|
||||||
|
outbids = outbids_cache[cache_key]['data']
|
||||||
|
else:
|
||||||
|
# Get outbid domains
|
||||||
|
outbids = account_module.getPossibleOutbids(account)
|
||||||
|
# Store in cache
|
||||||
|
outbids_cache[cache_key] = {
|
||||||
|
'data': outbids,
|
||||||
|
'time': current_time
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
outbids = []
|
||||||
|
|
||||||
|
bidsHtml = render.bidDomains(bids,domains,sortbyDomain,outbids)
|
||||||
plugins = ""
|
plugins = ""
|
||||||
message = ''
|
message = ''
|
||||||
if 'message' in request.args:
|
if 'message' in request.args:
|
||||||
@@ -358,11 +386,12 @@ def revealAllBids():
|
|||||||
return redirect("/logout")
|
return redirect("/logout")
|
||||||
|
|
||||||
response = account_module.revealAll(request.cookies.get("account"))
|
response = account_module.revealAll(request.cookies.get("account"))
|
||||||
if 'error' in response:
|
# Simplified error handling
|
||||||
if response['error'] != None:
|
if 'error' in response and response['error']:
|
||||||
if response['error']['message'] == "Nothing to do.":
|
error_msg = response['error'].get('message', str(response['error']))
|
||||||
return redirect("/auctions?message=No reveals pending")
|
if error_msg == "Nothing to do.":
|
||||||
return redirect("/auctions?message=" + response['error']['message'])
|
return redirect("/auctions?message=No reveals pending")
|
||||||
|
return redirect("/auctions?message=" + error_msg)
|
||||||
|
|
||||||
return redirect("/success?tx=" + response['result']['hash'])
|
return redirect("/success?tx=" + response['result']['hash'])
|
||||||
|
|
||||||
@@ -501,10 +530,7 @@ def search():
|
|||||||
|
|
||||||
dns = account_module.getDNS(search_term)
|
dns = account_module.getDNS(search_term)
|
||||||
|
|
||||||
own_domains = account_module.getDomains(account)
|
if account_module.isOwnDomain(account, search_term):
|
||||||
own_domains = [x['name'] for x in own_domains]
|
|
||||||
own_domains = [x.lower() for x in own_domains]
|
|
||||||
if search_term in own_domains:
|
|
||||||
owner = "You"
|
owner = "You"
|
||||||
|
|
||||||
dns = render.dns(dns)
|
dns = render.dns(dns)
|
||||||
@@ -699,10 +725,7 @@ def editPage(domain: str):
|
|||||||
|
|
||||||
domain = domain.lower()
|
domain = domain.lower()
|
||||||
|
|
||||||
own_domains = account_module.getDomains(account)
|
if not account_module.isOwnDomain(account, domain):
|
||||||
own_domains = [x['name'] for x in own_domains]
|
|
||||||
own_domains = [x.lower() for x in own_domains]
|
|
||||||
if domain not in own_domains:
|
|
||||||
return redirect("/search?q=" + domain)
|
return redirect("/search?q=" + domain)
|
||||||
|
|
||||||
|
|
||||||
@@ -944,10 +967,7 @@ def auction(domain):
|
|||||||
expires = domainInfo['info']['stats']['daysUntilExpire']
|
expires = domainInfo['info']['stats']['daysUntilExpire']
|
||||||
next = f"Expires in ~{expires} days"
|
next = f"Expires in ~{expires} days"
|
||||||
|
|
||||||
own_domains = account_module.getDomains(account)
|
if account_module.isOwnDomain(account,domain):
|
||||||
own_domains = [x['name'] for x in own_domains]
|
|
||||||
own_domains = [x.lower() for x in own_domains]
|
|
||||||
if search_term in own_domains:
|
|
||||||
next_action = f'<a href="/manage/{domain}">Manage</a>'
|
next_action = f'<a href="/manage/{domain}">Manage</a>'
|
||||||
elif state == "REVOKED":
|
elif state == "REVOKED":
|
||||||
next = "Available Now"
|
next = "Available Now"
|
||||||
@@ -1673,6 +1693,12 @@ def api_wallet(function):
|
|||||||
|
|
||||||
return send_file('templates/assets/img/HNS.png')
|
return send_file('templates/assets/img/HNS.png')
|
||||||
|
|
||||||
|
|
||||||
|
if function == "possibleOutbids":
|
||||||
|
return jsonify({"result": account_module.getPossibleOutbids(account)})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400
|
return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400
|
||||||
|
|
||||||
@app.route('/api/v1/wallet/<function>/mobile', methods=["GET"])
|
@app.route('/api/v1/wallet/<function>/mobile', methods=["GET"])
|
||||||
|
|||||||
15
render.py
15
render.py
@@ -336,9 +336,8 @@ def bids(bids,reveals):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def bidDomains(bids,domains, sortbyDomains=False):
|
def bidDomains(bids,domains, sortbyDomains=False, outbids=[]):
|
||||||
html = ''
|
html = ''
|
||||||
|
|
||||||
if not sortbyDomains:
|
if not sortbyDomains:
|
||||||
for bid in bids:
|
for bid in bids:
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
@@ -352,13 +351,15 @@ def bidDomains(bids,domains, sortbyDomains=False):
|
|||||||
bidDisplay = f'<b>{bidValue:,.2f}</b> (+{blind:,.2f}) HNS'
|
bidDisplay = f'<b>{bidValue:,.2f}</b> (+{blind:,.2f}) HNS'
|
||||||
else:
|
else:
|
||||||
bidDisplay = f'<b>{bidValue:,.2f}</b> HNS'
|
bidDisplay = f'<b>{bidValue:,.2f}</b> HNS'
|
||||||
|
|
||||||
|
|
||||||
html += "<tr>"
|
html += "<tr>"
|
||||||
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
if domain['name'] in outbids:
|
||||||
|
html += f"<td style='background-color: red;'><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
|
else:
|
||||||
|
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
html += f"<td>{domain['state']}</td>"
|
html += f"<td>{domain['state']}</td>"
|
||||||
html += f"<td style='white-space: nowrap;'>{bidDisplay}</td>"
|
html += f"<td style='white-space: nowrap;'>{bidDisplay}</td>"
|
||||||
html += f"<td class='hide-mobile'>{domain['height']:,}</td>"
|
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
else:
|
else:
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
@@ -374,7 +375,7 @@ def bidDomains(bids,domains, sortbyDomains=False):
|
|||||||
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
html += f"<td>{domain['state']}</td>"
|
html += f"<td>{domain['state']}</td>"
|
||||||
html += f"<td>{bidDisplay}</td>"
|
html += f"<td>{bidDisplay}</td>"
|
||||||
html += f"<td class='hide-mobile'>{domain['height']:,}</td>"
|
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|||||||
2
templates/assets/js/dashboard.min.js
vendored
2
templates/assets/js/dashboard.min.js
vendored
@@ -1 +1 @@
|
|||||||
function createCard(e,n,t){if(document.getElementById(t)&&document.getElementById(t).remove(),n<=0)return;const a=document.createElement("div");a.classList.add("col-md-6","col-xl-3","mb-4"),a.id=t,html=`\n <div class="card shadow border-start-warning py-2">\n <div class="card-body">\n <div class="row align-items-center no-gutters">\n <div class="col me-2">\n <div class="text-uppercase text-warning fw-bold text-xs mb-1"><span>${e}</span></div>\n <div class="text-dark fw-bold h5 mb-0"><span id="${e}">${n}</span></div>\n </div>\n <div class="col"><a class="btn btn-primary" role="button" href="/all/${t.toLowerCase()}">${t} All</a></div>\n <div class="col-auto"><svg class="fa-2x text-gray-300" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor">\n <g>\n <rect fill="none" height="24" width="24"></rect>\n </g>\n <g>\n <path d="M12,2C6.48,2,2,6.48,2,12c0,5.52,4.48,10,10,10s10-4.48,10-10C22,6.48,17.52,2,12,2z M7,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C8.5,12.83,7.83,13.5,7,13.5z M12,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C13.5,12.83,12.83,13.5,12,13.5z M17,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C18.5,12.83,17.83,13.5,17,13.5z"></path>\n </g>\n </svg></div>\n </div>\n </div>`,a.innerHTML=html,document.getElementById("actions-row").appendChild(a)}async function updateActions(){const e={Finalize:"Pending Finalizes",Register:"Pending Register",Redeem:"Pending Redeem",Reveal:"Pending Reveal"};for(const n in e){const t=await request(`wallet/pending${n}`);"Error"!=t&&createCard(e[n],t.length,n)}}window.addEventListener("load",(async()=>{updateActions()})),setInterval((async function(){updateActions()}),2e4);
|
function createCard(e,n,t){if(document.getElementById(t)&&document.getElementById(t).remove(),n<=0)return;const s=document.createElement("div");s.classList.add("col-md-6","col-xl-3","mb-4"),s.id=t,html=`\n <div class="card shadow border-start-warning py-2">\n <div class="card-body">\n <div class="row align-items-center no-gutters">\n <div class="col me-2">\n <div class="text-uppercase text-warning fw-bold text-xs mb-1"><span>${e}</span></div>\n <div class="text-dark fw-bold h5 mb-0"><span id="${e}">${n}</span></div>\n </div>\n <div class="col"><a class="btn btn-primary" role="button" href="/all/${t.toLowerCase()}">${t} All</a></div>\n <div class="col-auto"><svg class="fa-2x text-gray-300" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor">\n <g>\n <rect fill="none" height="24" width="24"></rect>\n </g>\n <g>\n <path d="M12,2C6.48,2,2,6.48,2,12c0,5.52,4.48,10,10,10s10-4.48,10-10C22,6.48,17.52,2,12,2z M7,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C8.5,12.83,7.83,13.5,7,13.5z M12,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C13.5,12.83,12.83,13.5,12,13.5z M17,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C18.5,12.83,17.83,13.5,17,13.5z"></path>\n </g>\n </svg></div>\n </div>\n </div>`,s.innerHTML=html,document.getElementById("actions-row").appendChild(s)}async function updateActions(){const e={Finalize:"Pending Finalizes",Register:"Pending Register",Redeem:"Pending Redeem",Reveal:"Pending Reveal"},n=Object.keys(e).map((e=>request(`wallet/pending${e}`).then((n=>({id:e,result:n}))))),t=await Promise.all(n);for(const{id:n,result:s}of t)"Error"!==s&&createCard(e[n],s.length,n);const s=await request("wallet/possibleOutbids");if("Error"===s)return;const d=document.getElementById("outbids");if(d&&d.remove(),s.length<=0)return;const i=document.createElement("div");i.classList.add("col-md-6","col-xl-3","mb-4"),i.id="outbids",i.innerHTML=`\n <div class="card shadow border-start-warning py-2">\n <div class="card-body">\n <div class="row align-items-center no-gutters">\n <div class="col me-2">\n <div class="text-uppercase text-warning fw-bold text-xs mb-1"><span>Names with possible outbids</span></div>\n <div class="text-dark fw-bold h5 mb-0"><span id="outbids-count">${s.length}</span></div>\n </div>\n <div class="col"><a class="btn btn-primary" role="button" href="/auctions?outbids=true">Show All</a></div>\n <div class="col-auto">\n <svg class="fa-2x text-gray-300" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor">\n <g><rect fill="none" height="24" width="24"></rect></g>\n <g>\n <path d="M12,2C6.48,2,2,6.48,2,12c0,5.52,4.48,10,10,10s10-4.48,10-10C22,6.48,17.52,2,12,2z M7,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C8.5,12.83,7.83,13.5,7,13.5z M12,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C13.5,12.83,12.83,13.5,12,13.5z M17,13.5c-0.83,0-1.5-0.67-1.5-1.5 c0-0.83,0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5C18.5,12.83,17.83,13.5,17,13.5z"></path>\n </g>\n </svg>\n </div>\n </div>\n </div>\n </div>\n `,document.getElementById("actions-row").appendChild(i)}window.addEventListener("load",(async()=>{updateActions()})),setInterval((async function(){updateActions()}),2e4);
|
||||||
Reference in New Issue
Block a user