From 7dda41bda7c07beef332c3aa810c6f386153f817 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 10 Jul 2025 18:15:26 +1000 Subject: [PATCH] feat: Add api route for possible outbidded domains --- account.py | 41 +++++++++++++++++++++++++++++++++++++++++ main.py | 6 ++++++ render.py | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/account.py b/account.py index 4427a61..6382493 100644 --- a/account.py +++ b/account.py @@ -628,6 +628,47 @@ def getBids(account, domain="NONE"): bids.append(bid) return bids +def getPossibleOutbids(account): + # Get all bids + bids = getBids(account) + if 'error' in bids: + return [] + + # Get current height + current_height = getBlockHeight() + + # Sort out bids older than 720 blocks + bids = [bid for bid in bids if (current_height - bid['height']) <= 720] + possible_outbids = [] + + for bid in bids: + domain = bid['name'] + + # Check to make sure that bidding is still happening + domain_info = getDomain(domain) + if 'info' not in domain_info or 'state' not in domain_info['info']: + print(f"Domain {domain} not found or no info available",flush=True) + continue + if domain_info['info']['state'] != "BIDDING": + continue + + + current_highest_bid = bid['value'] + domain_bids = getBids(account, domain) + print(domain) + print(json.dumps(domain_bids, indent=4)) + for domain_bid in domain_bids: + if domain_bid["own"]: + current_highest_bid = max(current_highest_bid, domain_bid['value']) + continue + if domain_bid['value'] != -1000000: + print("Revealed bid") + continue + if current_highest_bid < domain_bid["lockup"]: + possible_outbids.append(domain) + break + + return possible_outbids def getReveals(account, domain): return hsw.getWalletRevealsByName(domain, account) diff --git a/main.py b/main.py index e263000..a5b0052 100644 --- a/main.py +++ b/main.py @@ -1673,6 +1673,12 @@ def api_wallet(function): 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 @app.route('/api/v1/wallet//mobile', methods=["GET"]) diff --git a/render.py b/render.py index ff79dd9..74a598b 100644 --- a/render.py +++ b/render.py @@ -358,7 +358,7 @@ def bidDomains(bids,domains, sortbyDomains=False): html += f"{renderDomain(domain['name'])}" html += f"{domain['state']}" html += f"{bidDisplay}" - html += f"{domain['height']:,}" + html += f"{bid['height']:,}" html += "" else: for domain in domains: @@ -374,7 +374,7 @@ def bidDomains(bids,domains, sortbyDomains=False): html += f"{renderDomain(domain['name'])}" html += f"{domain['state']}" html += f"{bidDisplay}" - html += f"{domain['height']:,}" + html += f"{bid['height']:,}" html += "" return html