From fa75ea3570ef7430a1115e9437e0ac96241c1811 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 29 Dec 2023 14:24:43 +1100 Subject: [PATCH] feat: Add reveal --- account.py | 23 +++++++++++++++++------ main.py | 33 +++++++++++++++++++++++++++++---- render.py | 1 - 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/account.py b/account.py index f691e13..1370721 100644 --- a/account.py +++ b/account.py @@ -221,14 +221,25 @@ def getRevealTX(reveal): hash = prevout['hash'] index = prevout['index'] tx = hsd.getTxByHash(hash) - revealAddress = tx['outputs'][index]['address'] - - for input in tx['inputs']: - if input['coin']['address'] == revealAddress: - return input['prevout']['hash'] - return False + return tx['inputs'][index]['prevout']['hash'] +def revealAuction(account,domain): + account_name = check_account(account) + password = ":".join(account.split(":")[1:]) + + if account_name == False: + return { + "error": "Invalid account" + } + + try: + response = hsw.sendREVEAL(account_name,password,domain) + return response + except Exception as e: + return { + "error": str(e) + } def rescan_auction(account,domain): # Get height of the start of the auction diff --git a/main.py b/main.py index b84a2d2..002f72e 100644 --- a/main.py +++ b/main.py @@ -351,8 +351,6 @@ def auction(domain): elif state == 'OPENING': next = "Bidding opens in ~" + str(domainInfo['info']['stats']['blocksUntilBidding']) + " blocks" elif state == 'BIDDING': - #! Check if the user has scanned the auction - next = "Reveal in ~" + str(domainInfo['info']['stats']['blocksUntilReveal']) + " blocks" elif state == 'REVEAL': next = "Reveal ends in ~" + str(domainInfo['info']['stats']['blocksUntilClose']) + " blocks" @@ -395,9 +393,20 @@ def bid(domain): return redirect("/logout") domain = domain.lower() + bid = request.args.get("bid") + blind = request.args.get("blind") + + if bid is "": + bid = 0 + if blind is "": + blind = 0 + + if bid+blind == 0: + return redirect("/auction/" + domain+ "?message=Invalid bid amount") + # Show confirm page - total = float(request.args.get('bid')) + float(request.args.get('blind')) + total = float(bid) + float(blind) action = f"Bid on {domain}/" content = f"Are you sure you want to bid on {domain}/?" @@ -433,7 +442,7 @@ def bid_confirm(domain): float(request.args.get('blind'))) print(response) if 'error' in response: - return redirect("/auction/" + domain + "?message=" + response['error']) + return redirect("/auction/" + domain + "?message=" + response['error']['message']) return redirect("/success?tx=" + response['hash']) @@ -451,6 +460,22 @@ def open_auction(domain): response = account_module.openAuction(request.cookies.get("account"),domain) return redirect("/success?tx=" + response['hash']) +@app.route('/auction//reveal') +def reveal_auction(domain): + # Check if the user is logged in + if request.cookies.get("account") is None: + return redirect("/login") + + if not account_module.check_account(request.cookies.get("account")): + return redirect("/logout") + + domain = domain.lower() + response = account_module.revealAuction(request.cookies.get("account"),domain) + if 'error' in response: + return redirect("/auction/" + domain + "?message=" + response['error']['message']) + return redirect("/success?tx=" + response['hash']) + + #endregion diff --git a/render.py b/render.py index 645bb66..6e2e768 100644 --- a/render.py +++ b/render.py @@ -164,5 +164,4 @@ def bids(bids,reveals): else: html += "Unknown" html += "" - return html \ No newline at end of file