import datetime import json import urllib.parse from flask import render_template def domains(domains, mobile=False): html = '' for domain in domains: owner = domain['owner'] if 'index' in owner: if owner['index'] == 0: continue expires = domain['stats'] if 'daysUntilExpire' in expires: expires = expires['daysUntilExpire'] else: expires = "No expiration date" paid = domain['value'] paid = paid / 1000000 if not mobile: html += f'{domain["name"]}{expires} days{paid} HNSManage' else: html += f'{domain["name"]}{expires} days' return html def transactions(txs): html = '' # Reverse the list txs = txs[::-1] for tx in txs: action = "HNS Transfer" address = tx["outputs"][0]["address"] hash = tx["hash"] confirmations=tx["confirmations"] amount = 0 incomming = False if not tx["inputs"][0]["path"]: incomming = True for output in tx["outputs"]: if output["covenant"]["action"] != "NONE": if action == "HNS Transfer": action = output["covenant"]["action"] elif action == output["covenant"]["action"]: continue else: action = "Multiple Actions" if not output["path"] and not incomming: amount += output["value"] elif output["path"] and incomming: amount += output["value"] amount = amount / 1000000 amount = round(amount, 2) amount = "{:,}".format(amount) hash = "" + hash[:8] + "..." if confirmations < 5: confirmations = "" + str(confirmations) + "" else: confirmations = "" + str(confirmations) + "" html += f'{action}{address}{hash}{confirmations}{amount} HNS' return html def dns(data, edit=False): html_output = "" index = 0 for entry in data: html_output += f"{entry['type']}\n" if entry['type'] != 'DS' and not entry['type'].startswith("GLUE") and not entry['type'].startswith("SYNTH"): for key, value in entry.items(): if key != 'type': if isinstance(value, list): html_output += "\n" for val in value: html_output += f"{val}
\n" html_output += "\n" else: html_output += f"{value}\n" elif entry['type'] == 'DS': ds = str(entry['keyTag']) + " " + str(entry['algorithm']) + " " + str(entry['digestType']) + " " + entry['digest'] html_output += f"{ds}\n" else: value = "" for key, val in entry.items(): if key != 'type': value += str(val) + " " html_output += f"{value}\n" if edit: # Remove the current entry from the list keptRecords = str(data[:index] + data[index+1:]).replace("'", '"') keptRecords = urllib.parse.quote(keptRecords) html_output += f"Remove\n" html_output += " \n" index += 1 return html_output def txs(data): data = data[::-1] html_output = "" for entry in data: html_output += f"{entry['action']}\n" html_output += f"{entry['txid'][:8]}...\n" amount = entry['amount'] amount = amount / 1000000 amount = round(amount, 2) if entry['blind'] == None: html_output += f"{amount} HNS\n" else: blind = entry['blind'] blind = blind / 1000000 blind = round(blind, 2) html_output += f"{amount} + {blind} HNS\n" html_output += f"{timestamp_to_readable_time(entry['time'])}\n" html_output += f"\n" return html_output def timestamp_to_readable_time(timestamp): # Assuming the timestamp is in seconds dt_object = datetime.datetime.fromtimestamp(timestamp) readable_time = dt_object.strftime("%H:%M:%S %d %b %Y") return readable_time def bids(bids,reveals): html = '' for bid in bids: lockup = bid['lockup'] lockup = lockup / 1000000 lockup = round(lockup, 2) html += "" html += f"{lockup} HNS" revealed = False for reveal in reveals: if reveal['bid'] == bid['prevout']['hash']: revealed = True value = reveal['value'] value = value / 1000000 value = round(value, 2) html += f"{value} HNS" bidValue = lockup - value bidValue = round(bidValue, 2) html += f"{bidValue} HNS" break if not revealed: html += f"Hidden until reveal" html += f"Hidden until reveal" if bid['own']: html += "You" else: html += "Unknown" html += "" return html def bidDomains(bids,domains, sortState=False): html = '' if not sortState: for bid in bids: for domain in domains: if bid['name'] == domain['name']: lockup = bid['lockup'] lockup = lockup / 1000000 lockup = round(lockup, 2) bidValue = bid['value'] / 1000000 bidValue = round(bidValue, 2) blind = lockup - bidValue bidValue = "{:,}".format(bidValue) blind = "{:,}".format(blind) bidDisplay = f'{bidValue} HNS + {blind} HNS blind' html += "" html += f"{domain['name']}" html += f"{domain['state']}" html += f"{bidDisplay}" html += "" else: for domain in domains: for bid in bids: if bid['name'] == domain['name']: lockup = bid['lockup'] lockup = lockup / 1000000 lockup = round(lockup, 2) bidValue = bid['value'] / 1000000 bidValue = round(bidValue, 2) blind = lockup - bidValue bidValue = "{:,}".format(bidValue) blind = "{:,}".format(blind) bidDisplay = f'{bidValue} HNS + {blind} HNS blind' html += "" html += f"{domain['name']}" html += f"{domain['state']}" html += f"{bidDisplay}" html += "" return html def wallets(wallets): html = '' for wallet in wallets: html += f'' return html def plugins(plugins): html = '' for plugin in plugins: name = plugin['name'] link = plugin['link'] if plugin['verified']: html += f'
  • {name}
  • ' else: html += f'
  • {name} (Not verified)
  • ' return html def plugin_functions(functions, pluginName): html = '' for function in functions: name = functions[function]['name'] description = functions[function]['description'] params = functions[function]['params'] returnsRaw = functions[function]['returns'] returns = "" for output in returnsRaw: returns += f"{returnsRaw[output]['name']}, " returns = returns.removesuffix(', ') functionType = "default" if "type" in functions[function]: functionType = functions[function]["type"] html += f'
    ' html += f'
    ' html += f'

    {name}

    ' html += f'
    {description}
    ' html += f'
    Function type: {functionType.capitalize()}
    ' if functionType != "default": html += f'

    Returns: {returns}

    ' html += f'
    ' html += f'
    ' continue # Form html += f'
    ' for param in params: html += f'
    ' paramName = params[param]["name"] paramType = params[param]["type"] if paramType == "text": html += f'' html += f'' elif paramType == "longText": html += f'' html += f'' elif paramType == "number": html += f'' html += f'' elif paramType == "checkbox": html += f'
    ' elif paramType == "address": # render components/address.html address = render_template('components/address.html', paramName=paramName, param=param) html += address elif paramType == "dns": html += render_template('components/dns-input.html', paramName=paramName, param=param) html += f'
    ' html += f'' html += f'
    ' # For debugging html += f'

    Returns: {returns}

    ' html += f'' html += f'' return html def plugin_output(outputs, returns): html = '' for returnOutput in returns: if returnOutput not in outputs: continue html += f'
    ' html += f'
    ' html += f'

    {returns[returnOutput]["name"]}

    ' output = outputs[returnOutput] if returns[returnOutput]["type"] == "list": html += f'' elif returns[returnOutput]["type"] == "text": html += f'

    {output}

    ' elif returns[returnOutput]["type"] == "tx": html += render_template('components/tx.html', tx=output) elif returns[returnOutput]["type"] == "dns": output = json.loads(output) html += render_template('components/dns-output.html', dns=dns(output)) html += f'
    ' html += f'
    ' return html def plugin_output_dash(outputs, returns): html = '' for returnOutput in returns: if returnOutput not in outputs: continue html += render_template('components/dashboard-plugin.html', name=returns[returnOutput]["name"], output=outputs[returnOutput]) return html