diff --git a/account.py b/account.py index 83a3de1..6de3889 100644 --- a/account.py +++ b/account.py @@ -1155,6 +1155,87 @@ def createBatch(account, batch): } } +# region Mempool +def getMempoolTxs(): + # hsd-cli rpc getrawmempool + response = hsd.rpc_getRawMemPool() + if 'error' in response and response['error'] is not None: + return [] + + return response['result'] if 'result' in response else [] + + +def getMempoolBids(): + mempoolTxs = getMempoolTxs() + bids = {} + for txid in mempoolTxs: + tx = hsd.getTxByHash(txid) + if 'error' in tx and tx['error'] is not None: + print(f"Error getting tx {txid}: {tx['error']}") + continue + # bid_data.append({ + # 'bid': bid, + # 'lockup': lockup, + # 'revealed': revealed, + # 'value': value, + # 'sort_value': value if revealed else lockup # Use value for sorting if revealed, otherwise lockup + # }) + if 'outputs' not in tx: + print(f"Error getting outputs for tx {txid}") + continue + for output in tx['outputs']: + if output['covenant']['action'] not in ["BID", "REVEAL"]: + continue + if output['covenant']['action'] == "REVEAL": + # Try to find bid tx from inputs + namehash = output['covenant']['items'][0] + for txInput in tx['inputs']: + if txInput['coin']['covenant']['action'] != "BID": + continue + if txInput['coin']['covenant']['items'][0] != namehash: + continue + name = txInput['coin']['covenant']['items'][2] + # Convert name from hex to ascii + name = bytes.fromhex(name).decode('ascii') + + bid = { + 'txid': txid, + 'lockup': txInput['coin']['value'], + 'revealed': True, + 'height': -1, + 'value': output['value'], + 'sort_value': txInput['coin']['value'] + } + if name not in bids: + bids[name] = [] + bids[name].append(bid) + continue + + name = output['covenant']['items'][2] + # Convert name from hex to ascii + name = bytes.fromhex(name).decode('ascii') + if name not in bids: + bids[name] = [] + bid = { + 'txid': txid, + 'value': -1000000, # Default value if not found + 'lockup': output['value'], + 'revealed': False, + 'height': -1, + 'sort_value': output['value'] + } + bids[name].append(bid) + + + return bids + + + + +# endregion + + + # region settingsAPIs def rescan(): diff --git a/main.py b/main.py index 8a862c9..310118b 100644 --- a/main.py +++ b/main.py @@ -923,10 +923,6 @@ def auction(domain): # Get TX revealInfo = account_module.getRevealTX(reveal) reveal['bid'] = revealInfo - print("RAW Bids found: ", len(bids)) - print(json.dumps(bids, indent=4)) - print("RAW Reveals found: ", len(reveals)) - print(json.dumps(reveals, indent=4)) bids = render.bids(bids,reveals) stats = domainInfo['info']['stats'] if 'stats' in domainInfo['info'] else {} @@ -1546,6 +1542,10 @@ def api_hsd(function): return jsonify({"result": account_module.hsdVersion(False)}) if function == "height": return jsonify({"result": account_module.getBlockHeight()}) + if function == "mempool": + return jsonify({"result": account_module.getMempoolTxs()}) + if function == "mempoolBids": + return jsonify({"result": account_module.getMempoolBids()}) return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400 diff --git a/render.py b/render.py index 9d15765..3740cad 100644 --- a/render.py +++ b/render.py @@ -320,8 +320,6 @@ def bids(bids,reveals): 'value': value, 'sort_value': value if revealed else lockup # Use value for sorting if revealed, otherwise lockup }) - print("PARSED Bids found: ", len(bid_data)) - print(json.dumps(bid_data, indent=4)) # Sort by the sort_value in descending order (highest first) bid_data.sort(key=lambda x: x['sort_value'], reverse=True)