Exemple #1
0
def bitcoind_config_page():
    check_logged_in()

    # Handle form
    if request.method == 'POST':
        custom_config = request.form.get('custom_config')
        set_bitcoin_custom_config(custom_config)
        
        # Trigger reboot
        t = Timer(1.0, reboot_device)
        t.start()

        # Wait until device is restarted
        templateData = {
            "title": "myNode Reboot",
            "header_text": "Restarting",
            "subheader_text": "This will take several minutes...",
            "ui_settings": read_ui_settings()
        }
        return render_template('reboot.html', **templateData)

    bitcoin_config = get_bitcoin_custom_config()
    if bitcoin_config == "ERROR":
        bitcoin_config = get_bitcoin_config()

    templateData = {
        "title": "myNode Bitcoin Config",
        "bitcoin_config": bitcoin_config,
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoind_config.html', **templateData)
Exemple #2
0
def page_lnd_create_wallet():
    check_logged_in()

    try:
        seed = gen_new_wallet_seed()
        session['seed'] = seed.strip()
    except:
        templateData = {
            "title":
            "myNode Lightning Wallet",
            "show_lightning_back_button":
            True,
            "header":
            "Lightning Status",
            "message":
            Markup(
                "Waiting on Lightning...<br/>Please try again in a minute."),
            "ui_settings":
            read_ui_settings()
        }
        return render_template('error.html', **templateData)

    templateData = {
        "title": "myNode Lightning Wallet",
        "seed": seed,
        "ui_settings": read_ui_settings()
    }
    return render_template('lnd_wallet_create.html', **templateData)
Exemple #3
0
def search_page():
    check_logged_in()

    if not request:
        return redirect("/explorer")

    results = search(request.form['search'])
    if results["type"] == "block":
        return redirect("/explorer/block/{}".format(results["id"]))
    elif results["type"] == "tx":
        return redirect("/explorer/tx/{}".format(results["id"]))
    elif results["type"] == "addr":
        return redirect("/explorer/addr/{}".format(results["id"]))
    elif results["type"] == "not_found":
        templateData = {
            "title": "myNode BTC Bitcoin Error",
            "message": Markup("Not Found<br/>{}".format(request.form['search'])),
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)
    elif results["type"] == "error":
        templateData = {
            "title": "myNode Bitcoin Error",
            "message": Markup("Error<br/>{}".format(results["error_message"])),
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)

    templateData = {
        "title": "myNode Bitcoin Error",
        "message": Markup("Error - unknown return: {}".format(results["type"])),
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoind_error.html', **templateData)
Exemple #4
0
def address_page(addr):
    check_logged_in()

    try:
        # Get addr info
        script_hash = get_scripthash_for_address(addr)

        rev = reverse_hash(script_hash)
        data = get_from_electrum('blockchain.scripthash.get_balance', rev)

        confirmed_bal = data["result"]["confirmed"]
        if confirmed_bal != 0:
            confirmed_bal = float(confirmed_bal) / 100000000
        unconfirmed_bal = data["result"]["unconfirmed"]
        if unconfirmed_bal != 0:
            unconfirmed_bal = float(unconfirmed_bal) / 100000000

        # Get addr TXs
        txdata = get_from_electrum('blockchain.scripthash.get_history', rev)
        unconfirmed = []
        confirmed = []
        for t in txdata['result']:
            if t["height"] == 0:
                unconfirmed.append(t)
            else:
                confirmed.append(t)
        confirmed = list(reversed(confirmed))
        txs = unconfirmed + confirmed

        templateData = {
            "title": "myNode Bitcoin",
            "address": addr,
            "confirmed_balance": confirmed_bal,
            "unconfirmed_balance": unconfirmed_bal,
            "txs": txs,
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_address.html', **templateData)
    except Exception as e:
        templateData = {
            "title":
            "myNode Bitcoin Error",
            "message":
            Markup(
                "Error communicating with bitcoind. Node may be busy syncing.<br/><br/>{}"
                .format(str(e))),
            "back_url":
            "/bitcoind",
            "ui_settings":
            read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)
Exemple #5
0
def page_vpn_info():
    check_logged_in()

    # Check if we are premium
    if is_community_edition():
        return redirect("/")

    # Check if port is forwarded
    port_forwarded = False
    ip = get_public_ip()
    if subprocess.call(["nc", "-v", "-u", "-w", "1", ip, "51194"]) == 0:
        port_forwarded = True

    # Get status
    status = "Setting up..."
    vpn_file_exists = False
    if os.path.isfile("/home/pivpn/ovpns/mynode_vpn.ovpn"):
        vpn_file_exists = True
        status = "Running"

    templateData = {
        "title": "myNode VPN Info",
        "status": status,
        "vpn_file_exists": vpn_file_exists,
        "port_forwarded": port_forwarded,
        "public_ip": ip,
        "port": "51194",
        "ui_settings": read_ui_settings()
    }
    return render_template('vpn_info.html', **templateData)
Exemple #6
0
def page_lnd_create_wallet_with_seed():
    check_logged_in()

    # Load page
    if request.method == 'GET':
        templateData = {
            "title": "myNode Lightning Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd_wallet_create_with_seed.html', **templateData)

    # Get seed
    seed = request.form.get('seed').strip()

    # Check for channel backup
    channel_backup_filename = "/tmp/lnd_channel_backup"
    os.system("rm -f " + channel_backup_filename)

    if 'channel_backup' in request.files and request.files['channel_backup'] != "":
        f = request.files['channel_backup']
        if f.filename != "":
            f.save( channel_backup_filename )

    if create_wallet(seed):
        flash("Wallet Created!", category="message")
        return redirect(url_for(".page_lnd"))
    
    # Error creating wallet
    flash("Error Creating Wallet!", category="error")
    return redirect(url_for(".page_lnd"))
Exemple #7
0
def dojo_page():
    check_logged_in()

    NODE_ADMIN_KEY = 'Not found'
    try:
        NODE_ADMIN_KEY = subprocess.check_output(
            "cat /opt/mynode/dojo/docker/my-dojo/conf/docker-node.conf | grep -i NODE_ADMIN_KEY= | cut -c 16-",
            shell=True)
        NODE_ADMIN_KEY = NODE_ADMIN_KEY.strip()
    except:
        NODE_ADMIN_KEY = 'error'

    DOJO_V3_ADDR = 'Not found'
    try:
        DOJO_V3_ADDR = subprocess.check_output(
            "docker exec tor cat /var/lib/tor/hsv3dojo/hostname", shell=True)
        PAGE = '/admin'
        DOJO_V3_ADDR = DOJO_V3_ADDR.strip() + PAGE
    except:
        DOJO_V3_ADDR = 'error'

    dojo_status, dojo_status_color, dojo_initialized = get_dojo_status()

    # Load page
    templateData = {
        "title": "myNode Dojo",
        "ui_settings": read_ui_settings(),
        "dojo_status": dojo_status,
        "dojo_status_color": dojo_status_color,
        "dojo_enabled": is_dojo_enabled(),
        "dojo_initialized": dojo_initialized,
        "NODE_ADMIN_KEY": NODE_ADMIN_KEY,
        "DOJO_V3_ADDR": DOJO_V3_ADDR
    }
    return render_template('dojo.html', **templateData)
Exemple #8
0
def whirlpool_page():
    check_logged_in()

    whirlpool_api_key = 'Not found'
    try:
        whirlpool_api_key = subprocess.check_output(
            "cat /opt/mynode/whirlpool/whirlpool-cli-config* | grep -i cli.Apikey= | cut -c 12-",
            shell=True)
    except:
        whirlpool_api_key = 'error'

    whirlpool_status, whirlpool_status_color, whirlpool_initialized = get_whirlpool_status(
    )

    # Load page
    templateData = {
        "title": "myNode Whirlpool",
        "ui_settings": read_ui_settings(),
        "whirlpool_status": whirlpool_status,
        "whirlpool_status_color": whirlpool_status_color,
        "whirlpool_enabled": is_whirlpool_enabled(),
        "whirlpool_initialized": whirlpool_initialized,
        "whirlpool_api_key": whirlpool_api_key
    }
    return render_template('whirlpool.html', **templateData)
Exemple #9
0
def page_lnd_create_wallet_confirm():
    check_logged_in()

    # Load page
    if request.method == 'GET':
        templateData = {
            "title": "myNode Lightning Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd_wallet_create_confirm.html', **templateData)

    # Parse submission
    seed = request.form.get('seed').strip()
    if seed != session['seed']:
        session["seed"] = None
        flash("Incorrect Seed", category="error")
        return redirect(url_for(".page_lnd"))
    session["seed"] = None

    # Seed matches, create wallet!
    if create_wallet(seed):
        flash("Wallet Created!", category="message")
        return redirect(url_for(".page_lnd"))
    
    # Error creating wallet
    flash("Error Creating Wallet!", category="error")
    return redirect(url_for(".page_lnd"))
Exemple #10
0
def page_lnd_change_alias():
    check_logged_in()
    
    # Load page
    p = pam.pam()
    pw = request.form.get('password_change_alias')
    if pw == None or p.authenticate("admin", pw) == False:
        flash("Invalid Password", category="error")
        return redirect(url_for(".page_lnd"))

    # Change alias
    alias = request.form.get('alias')
    if alias == None or alias == "":
        flash("Empty Alias", category="error")
        return redirect(url_for(".page_lnd"))
    if len(alias) > 34:
        flash("Invalid Alias", category="error")
        return redirect(url_for(".page_lnd"))
    with open("/mnt/hdd/mynode/settings/.lndalias", "w") as f:
        utf8_alias = alias.decode('utf-8', 'ignore')
        f.write(utf8_alias)
        f.close()

    # Reboot
    t = Timer(1.0, reboot_device)
    t.start()

    # Wait until device is restarted
    templateData = {
        "title": "myNode Reboot",
        "header_text": "Restarting",
        "subheader_text": "This will take several minutes...",
        "ui_settings": read_ui_settings()
    }
    return render_template('reboot.html', **templateData)
Exemple #11
0
def bitcoind_explorer_page():
    check_logged_in()

    # Get current information
    try:
        info = get_bitcoin_blockchain_info()
        blockdata = get_bitcoin_recent_blocks()
        mempool = get_bitcoin_mempool()

        # 10 most recent blocks
        blocks = []
        for b in blockdata:
            block = b
            minutes = int(time.time() - int(b["time"])) / 60
            block["age"] = "{} minutes".format(minutes)
            block["size"] = int(b["size"] / 1000)
            blocks.append(block)
        blocks.reverse()

    except Exception as e:
        templateData = {
            "title":
            "myNode Bitcoin Error",
            "message":
            Markup(
                "Error communicating with bitcoind. Node may be busy syncing.<br/><br/>{}"
                .format(str(e))),
            "back_url":
            "/",
            "ui_settings":
            read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)

    templateData = {
        "title": "myNode Bitcoin Status",
        "blocks": blocks,
        "difficulty": "{:.3g}".format(info["difficulty"]),
        "block_num": info["blocks"],
        "header_num": info["headers"],
        "disk_size": (int(info["size_on_disk"]) / 1000 / 1000 / 1000),
        "mempool_tx": mempool["size"],
        "mempool_size":
        "{:.3} MB".format(float(mempool["bytes"]) / 1000 / 1000),
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoind_explorer.html', **templateData)
Exemple #12
0
def block_page(block_hash):
    check_logged_in()

    try:
        # Get info
        rpc_user = get_bitcoin_rpc_username()
        rpc_pass = get_bitcoin_rpc_password()
        rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8332" %
                                          (rpc_user, rpc_pass),
                                          timeout=10)
        block = rpc_connection.getblock(block_hash)

        txs = []
        for t in block["tx"]:
            txs.append(t)

        t = time.gmtime(int(block["time"]))
        tstring = time.strftime("%Y-%m-%d %H:%M:%S", t)

        templateData = {
            "title": "myNode Bitcoin",
            "raw": pformat(block, indent=2),
            "height": block["height"],
            "hash": block["hash"],
            "confirmations": block["confirmations"],
            "num_tx": block["nTx"],
            "difficulty": "{:.3g}".format(block["difficulty"]),
            "size": int(block["size"] / 1000),
            "date": tstring,
            "txs": txs,
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_block.html', **templateData)
    except Exception as e:
        templateData = {
            "title":
            "myNode Bitcoin Error",
            "message":
            Markup(
                "Error communicating with bitcoind. Node may be busy syncing.<br/><br/>{}"
                .format(str(e))),
            "back_url":
            "/bitcoind",
            "ui_settings":
            read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)
Exemple #13
0
def page_lnd_lndconnect():
    check_logged_in()

    # Load page
    if request.method == 'GET':
        return redirect(url_for(".page_lnd"))

    p = pam.pam()
    pw = request.form.get('password_lndconnect')
    from_homepage = request.form.get('lndconnect_from_homepage')
    if pw == None or p.authenticate("admin", pw) == False:
        if from_homepage != None:
            flash("Invalid Password", category="error")
            return redirect("/")
        else:
            flash("Invalid Password", category="error")
            return redirect(url_for(".page_lnd"))

    lndconnect_local_grpc_text = get_text_contents(
        "/tmp/mynode_lndconnect/lndconnect_local_grpc.txt")
    lndconnect_local_rest_text = get_text_contents(
        "/tmp/mynode_lndconnect/lndconnect_local_rest.txt")
    lndconnect_tor_grpc_text = get_text_contents(
        "/tmp/mynode_lndconnect/lndconnect_tor_grpc.txt")
    lndconnect_tor_rest_text = get_text_contents(
        "/tmp/mynode_lndconnect/lndconnect_tor_rest.txt")
    if is_community_edition():
        lndconnect_tor_grpc_text = "Premium Feature"
        lndconnect_tor_rest_text = "Premium Feature"

    lndconnect_local_grpc_img = get_image_contents(
        "/tmp/mynode_lndconnect/lndconnect_local_grpc.png")
    lndconnect_local_rest_img = get_image_contents(
        "/tmp/mynode_lndconnect/lndconnect_local_rest.png")
    lndconnect_tor_grpc_img = get_image_contents(
        "/tmp/mynode_lndconnect/lndconnect_tor_grpc.png")
    lndconnect_tor_rest_img = get_image_contents(
        "/tmp/mynode_lndconnect/lndconnect_tor_rest.png")
    if is_community_edition():
        lndconnect_tor_grpc_img = get_image_contents(
            "/var/www/mynode/static/images/dots.png")
        lndconnect_tor_rest_img = get_image_contents(
            "/var/www/mynode/static/images/dots.png")

    # Show lndconnect page
    templateData = {
        "title": "myNode Lightning Wallet",
        "lndconnect_local_grpc_text": lndconnect_local_grpc_text,
        "lndconnect_local_rest_text": lndconnect_local_rest_text,
        "lndconnect_tor_grpc_text": lndconnect_tor_grpc_text,
        "lndconnect_tor_rest_text": lndconnect_tor_rest_text,
        "lndconnect_local_grpc_img": lndconnect_local_grpc_img,
        "lndconnect_local_rest_img": lndconnect_local_rest_img,
        "lndconnect_tor_grpc_img": lndconnect_tor_grpc_img,
        "lndconnect_tor_rest_img": lndconnect_tor_rest_img,
        "ui_settings": read_ui_settings()
    }
    return render_template('lndconnect.html', **templateData)
Exemple #14
0
def caravan_page():
    check_logged_in()

    # Load page
    templateData = {
        "title": "myNode Caravan",
        "ui_settings": read_ui_settings()
    }
    return render_template('caravan.html', **templateData)
Exemple #15
0
def bitcoincli():
    check_logged_in()

    # Load page
    templateData = {
        "title": "myNode Bitcoin CLI",
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoin_cli.html', **templateData)
Exemple #16
0
def electrum_server_page():
    check_logged_in()

    # Make sure data is up to date
    update_electrs_info()

    # Get latest info
    current_block = get_electrum_server_current_block()
    if current_block == None:
        current_block = "Unknown"
    status = get_electrs_status()

    #server_url = get_local_ip() + ":50002:s"
    server_ip = get_local_ip()
    server_standard_port = "50001"
    server_secure_port = "50002"

    # Get IP URLs
    electrs_command = "./electrum -1 -s {}:50002:s".format(server_ip)

    # Get Onion URLs
    electrs_onion_hostname = "..."
    electrs_onion_password = "******"
    electrs_onion_command = "..."
    if os.path.isfile("/var/lib/tor/mynode/hostname"):
        with open("/var/lib/tor/mynode/hostname") as f:
            contents = f.read().split()
            electrs_onion_hostname = contents[0]
            electrs_onion_password = contents[1]
            electrs_onion_command = "./electrum -1 -s {}:50002:s -p socks5:localhost:9050".format(electrs_onion_hostname)
    else:
        electrs_onion_hostname = "disabled"
        electrs_onion_password = "******"
        electrs_onion_command = "disabled"

    # Load page
    templateData = {
        "title": "myNode Electrum Server",
        "port": 50002,
        "status": status,
        "product_key_skipped": skipped_product_key(),
        "current_block": current_block,
        #"server_url": server_url,
        "server_ip": server_ip,
        "server_standard_port": server_standard_port,
        "server_secure_port": server_secure_port,
        "electrs_command": electrs_command,
        "electrs_onion_hostname": electrs_onion_hostname,
        "electrs_onion_password": electrs_onion_password,
        "electrs_onion_command": electrs_onion_command,
        "ui_settings": read_ui_settings()
    }
    return render_template('electrum_server.html', **templateData)
Exemple #17
0
def bitcoin_reset_config_page():
    check_logged_in()

    delete_bitcoin_custom_config()
        
    # Trigger reboot
    t = Timer(1.0, reboot_device)
    t.start()

    # Wait until device is restarted
    templateData = {
        "title": "myNode Reboot",
        "header_text": "Restarting",
        "subheader_text": "This will take several minutes...",
        "ui_settings": read_ui_settings()
    }
    return render_template('reboot.html', **templateData)
Exemple #18
0
def electrum_server_page():
    check_logged_in()

    # Make sure data is up to date
    update_electrs_info()

    # Get latest info
    current_block = get_electrum_server_current_block()
    if current_block == None:
        current_block = "Unknown"
    status = get_electrs_status()

    #server_url = get_local_ip() + ":50002:s"
    server_ip = get_local_ip()
    server_standard_port = "50001"
    server_secure_port = "50002"

    # Get IP URLs
    electrs_command = "./electrum -1 -s {}:50002:s".format(server_ip)

    # Get Onion URLs
    electrs_onion_hostname = get_onion_url_electrs()
    electrs_onion_command = "./electrum -1 -s {}:50002:s -p socks5:localhost:9050".format(electrs_onion_hostname)


    # Load page
    templateData = {
        "title": "myNode Electrum Server",
        "port": 50002,
        "status": status,
        "product_key_skipped": skipped_product_key(),
        "current_block": current_block,
        #"server_url": server_url,
        "server_ip": server_ip,
        "server_standard_port": server_standard_port,
        "server_secure_port": server_secure_port,
        "electrs_command": electrs_command,
        "electrs_onion_hostname": electrs_onion_hostname,
        "electrs_onion_command": electrs_onion_command,
        "ui_settings": read_ui_settings()
    }
    return render_template('electrum_server.html', **templateData)
Exemple #19
0
def page_lnd_create_wallet_with_seed():
    check_logged_in()

    # Load page
    if request.method == 'GET':
        templateData = {
            "title": "myNode Lightning Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd_wallet_create_with_seed.html',
                               **templateData)

    # Create wallet!
    seed = request.form.get('seed').strip()
    if create_wallet(seed):
        flash("Wallet Created!", category="message")
        return redirect(url_for(".page_lnd"))

    # Error creating wallet
    flash("Error Creating Wallet!", category="error")
    return redirect(url_for(".page_lnd"))
Exemple #20
0
def tx_page(txid):
    check_logged_in()

    try:
        # Get info
        electrum_data = get_from_electrum("blockchain.transaction.get", [txid, True])
        tx = electrum_data['result']

        inputs = []
        outputs = []
        total = 0
        for i in tx["vin"]:
            if "coinbase" in i:
                inputs.append("New Coins")
            else:
                data = get_from_electrum("blockchain.transaction.get", [i["txid"], True])
                tx_data = data['result']
                inputs.append(tx_data["vout"][ i["vout"] ]["scriptPubKey"]["addresses"][0])
        for o in tx["vout"]:
            temp = {}
            if "scriptPubKey" in o:
                s = o["scriptPubKey"]
                if "type" in s and s["type"] != "nulldata":
                    if "addresses" in s:
                        temp["address"] = s["addresses"][0]
                    else:
                        temp["address"] = "Unable to decode address"
                    temp["amount"] = o["value"]
                    total += o["value"]
                    outputs.append(temp)

        confirmed = False
        confirmations = "Unconfirmed"
        block_height = 0
        block_date = ""
        if "confirmations" in tx:
            confirmations = tx["confirmations"]
            confirmed = True
        if confirmed:
            #block_height = tx["???"]
            t = time.gmtime( int(tx["blocktime"]) )
            block_date = time.strftime("%Y-%m-%d %H:%M:%S", t)

        templateData = {
            "title": "myNode Bitcoin",
            "heading": "Transaction",
            "raw": pformat(tx, indent=4),
            "txid": txid,
            "confirmations": confirmations,
            "size": tx["size"],
            "weight": tx["weight"],
            "confirmed": confirmed,
            "block_hash": tx["blockhash"],
            "block_height": tx,
            "block_date": block_date,
            "total": total,
            "inputs": inputs,
            "outputs": outputs,
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_tx.html', **templateData)
    except Exception as e:
        templateData = {
            "title": "myNode Bitcoin Error",
            "message": Markup("Error retreiving or parsing transaction.<br/><br/>{}".format(str(e))),
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_error.html', **templateData)
Exemple #21
0
def bitcoind_status_page():
    check_logged_in()

    # Get current information
    try:
        info = get_bitcoin_blockchain_info()
        blockdata = get_bitcoin_recent_blocks()
        peerdata = get_bitcoin_peers()
        networkdata = get_bitcoin_network_info()
        mempooldata = get_bitcoin_mempool()
        walletdata = get_bitcoin_wallet_info()
        version = get_bitcoin_version()
        rpc_password = get_bitcoin_rpc_password()

        # Mempool info
        mempool = {}
        mempool["size"] = "???"
        mempool["bytes"] = "0"
        if mempooldata != None:
            if "size" in mempooldata:
                mempool["size"] = mempooldata["size"]
            if "bytes" in mempooldata:
                mempool["bytes"] = mempooldata["bytes"]

        # Recent blocks
        blocks = []
        if blockdata != None:
            for b in blockdata:
                block = b
                minutes = int(time.time() - int(b["time"])) / 60
                block["age"] = "{} minutes".format(minutes)
                block["size"] = int(b["size"] / 1000)
                blocks.append(block)
            blocks.reverse()
            blocks = blocks[:5]  # Take top 5

        # Peers
        peers = []
        if peerdata != None:
            for p in peerdata:
                peer = p

                if "pingtime" in p:
                    peer["pingtime"] = int(p["pingtime"] * 1000)
                else:
                    peer["pingtime"] = "N/A"

                if "bytessent" in p:
                    peer["tx"] = "{:.2f}".format(
                        float(p["bytessent"]) / 1000 / 1000)
                else:
                    peer["tx"] = "N/A"

                if "bytesrecv" in p:
                    peer["rx"] = "{:.2f}".format(
                        float(p["bytesrecv"]) / 1000 / 1000)
                else:
                    peer["rx"] = "N/A"

                peers.append(peer)

        # Local address
        local_address = "..."
        if networkdata != None:
            local_address = "not none"
            if ("localaddresses" in networkdata) and (len(
                    networkdata["localaddresses"]) > 0):
                local_address = "{}:{}".format(
                    networkdata["localaddresses"][0]["address"],
                    networkdata["localaddresses"][0]["port"])

        # Balance
        walletinfo = {}
        walletinfo["balance"] = 0.0
        walletinfo["unconfirmed_balance"] = 0.0
        if walletdata != None:
            if "balance" in walletdata:
                walletinfo["balance"] = walletdata["balance"]
            if "unconfirmed_balance" in walletdata:
                walletinfo["unconfirmed_balance"] = walletdata[
                    "unconfirmed_balance"]

    except Exception as e:
        templateData = {
            "title":
            "myNode Bitcoin Error",
            "message":
            Markup(
                "Error communicating with bitcoind. Node may be busy syncing.<br/><br/>{}"
                .format(str(e))),
            "ui_settings":
            read_ui_settings()
        }
        return render_template('bitcoind_status_error.html', **templateData)

    templateData = {
        "title": "myNode Bitcoin Status",
        "blocks": blocks,
        "peers": peers,
        "local_address": local_address,
        "difficulty": "{:.3g}".format(info["difficulty"]),
        "block_num": info["blocks"],
        "header_num": info["headers"],
        "rpc_password": rpc_password,
        "disk_size": (int(info["size_on_disk"]) / 1000 / 1000 / 1000),
        "mempool_tx": mempool["size"],
        "mempool_size":
        "{:.3} MB".format(float(mempool["bytes"]) / 1000 / 1000),
        "confirmed_balance": walletinfo["balance"],
        "unconfirmed_balance": walletinfo["unconfirmed_balance"],
        "version": version,
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoind_status.html', **templateData)
Exemple #22
0
def page_lnd():
    check_logged_in()

    height = 0
    alias = "empty"
    num_peers = "0"
    num_active_channels = "TODO"
    num_pending_channels = "TODO"
    num_inactive_channels = "TODO"
    pubkey = "abcd"
    uri = ""
    ip = ""
    status = "Starting..."

    wallet_exists = lnd_wallet_exists()
    wallet_logged_in = is_lnd_logged_in()
    channel_backup_exists = lnd_channel_backup_exists()

    if not lnd_wallet_exists():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "version": get_lnd_version(),
            "status": status,
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    if not is_lnd_logged_in():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "status": get_lnd_status(),
            "version": get_lnd_version(),
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    try:
        data = get_lightning_info()

        height = data['block_height']
        alias = data['alias']
        pubkey = data['identity_pubkey']
        if "num_peers" in data:
            num_peers = data['num_peers']
        if "synced_to_chain" in data and data['synced_to_chain']:
            status = "Active"
        else:
            status = get_lnd_status()
        if "uris" in data and len(data['uris']) > 0:
            uri = data['uris'][0]
            ip = uri.split("@")[1]
        else:
            uri = "..."
            ip = "..."
    except Exception as e:
        templateData = {
            "title": "myNode Lightning Status",
            "message": str(e),
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd_error.html', **templateData)

    templateData = {
        "title": "myNode Lightning Status",
        "wallet_exists": wallet_exists,
        "wallet_logged_in": wallet_logged_in,
        "version": get_lnd_version(),
        "channel_backup_exists": channel_backup_exists,
        "status": status,
        "height": height,
        "alias": alias,
        "num_peers": num_peers,
        "num_active_channels": num_active_channels,
        "num_pending_channels": num_pending_channels,
        "num_inactive_channels": num_inactive_channels,
        "pubkey": pubkey,
        "uri": uri,
        "ip": ip,
        "ui_settings": read_ui_settings()
    }
    return render_template('lnd.html', **templateData)
Exemple #23
0
def bitcoind_status_page():
    check_logged_in()

    # Get current information
    try:
        info = get_bitcoin_blockchain_info()
        blockdata = get_bitcoin_recent_blocks()
        peerdata  = get_bitcoin_peers()
        mempooldata = get_bitcoin_mempool()
        version = get_bitcoin_version()

        # Mempool info
        mempool = {}
        mempool["size"] = "???"
        mempool["bytes"] = "0"
        if mempooldata != None:
            if "size" in mempooldata:
                mempool["size"] = mempooldata["size"]
            if "bytes" in mempooldata:
                mempool["bytes"] = mempooldata["bytes"]

        # Recent blocks
        blocks = []
        if blockdata != None:
            for b in blockdata:
                block = b
                minutes = int(time.time() - int(b["time"])) / 60
                block["age"] = "{} minutes".format(minutes)
                block["size"] = int(b["size"] / 1000)
                blocks.append(block)
            blocks.reverse()
            blocks = blocks[:5] # Take top 5

        # Peers
        peers = []
        if peerdata != None:
            for p in peerdata:
                peer = p

                if "pingtime" in p:
                    peer["pingtime"] =  int(p["pingtime"] * 1000)
                else:
                    peer["pingtime"] = "N/A"

                if "bytessent" in p:
                    peer["tx"] = "{:.2f}".format(float(p["bytessent"]) / 1000 / 1000)
                else:
                    peer["tx"] = "N/A"

                if "bytesrecv" in p:
                    peer["rx"] = "{:.2f}".format(float(p["bytesrecv"]) / 1000 / 1000)
                else:
                    peer["rx"] = "N/A"

                peers.append(peer)

    except Exception as e:
        templateData = {
            "title": "myNode Bitcoin Error",
            "message": Markup("Error communicating with bitcoind. Node may be busy syncing.<br/><br/>{}".format(str(e))),
            "ui_settings": read_ui_settings()
        }
        return render_template('bitcoind_status_error.html', **templateData)


    templateData = {
        "title": "myNode Bitcoin Status",
        "blocks": blocks,
        "peers": peers,
        "difficulty": "{:.3g}".format(info["difficulty"]),
        "block_num": info["blocks"],
        "header_num": info["headers"],
        "disk_size": (int(info["size_on_disk"]) / 1000 / 1000 / 1000),
        "mempool_tx": mempool["size"],
        "mempool_size": "{:.3} MB".format(float(mempool["bytes"]) / 1000 / 1000),
        "version": version,
        "ui_settings": read_ui_settings()
    }
    return render_template('bitcoind_status.html', **templateData)
Exemple #24
0
def page_lnd():
    check_logged_in()

    height = 0
    alias = get_lnd_alias_file_data()
    num_peers = "0"
    num_active_channels = "TODO"
    num_pending_channels = "TODO"
    num_inactive_channels = "TODO"
    pubkey = "abcd"
    uri = ""
    ip = ""
    status = "Starting..."
    lnd_deposit_address = get_deposit_address()
    channel_balance = "N/A"
    channel_pending = "0"
    wallet_balance = "N/A"
    wallet_pending = "0"

    wallet_exists = lnd_wallet_exists()
    wallet_logged_in = is_lnd_logged_in()
    channel_backup_exists = lnd_channel_backup_exists()

    if not lnd_wallet_exists():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "status": "Please Create Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    if not is_lnd_logged_in():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "alias": alias,
            "status": get_lnd_status(),
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    try:
        data = get_lightning_info()

        if "block_height" in data:
            height = data['block_height']
        if "identity_pubkey" in data:
            pubkey = data['identity_pubkey']
        if "num_peers" in data:
            num_peers = data['num_peers']
        if "synced_to_chain" in data and data['synced_to_chain']:
            status = "Active"
        else:
            status = get_lnd_status()
        if "uris" in data and len(data['uris']) > 0:
            uri = data['uris'][0]
            ip = uri.split("@")[1]
        else:
            uri = "..."
            ip = "..."

        peerdata = get_lightning_peers()
        peers = []
        if peerdata != None and "peers" in peerdata:
            for p in peerdata["peers"]:
                peer = p
                if "bytes_recv" in p:
                    peer["bytes_recv"] = "{:.2f}".format(float(p["bytes_recv"]) / 1000 / 1000)
                else:
                    peer["bytes_recv"] = "N/A"
                if "bytes_sent" in p:
                    peer["bytes_sent"] = "{:.2f}".format(float(p["bytes_sent"]) / 1000 / 1000)
                else:
                    peer["bytes_sent"] = "N/A"
                if "sat_sent" in p:
                    peer["sat_sent"] = format_sat_amount(peer["sat_sent"])
                if "sat_recv" in p:
                    peer["sat_recv"] = format_sat_amount(peer["sat_recv"])
                if "ping_time" not in p:
                    peer["ping_time"] = "N/A"
                if "pub_key" in p:
                    peer["alias"] = get_lightning_peer_alias( p["pub_key"] )
                else:
                    peer["alias"] = "Unknown"
                peers.append(peer)

        channeldata = get_lightning_channels()
        channels = []
        if channeldata != None and "channels" in channeldata:
            for c in channeldata["channels"]:
                channel = c
                if "capacity" in channel:
                    channel["capacity"] = format_sat_amount(channel["capacity"])
                if "local_balance" not in channel:
                    channel["local_balance"] = "0"
                else:
                    channel["local_balance"] = format_sat_amount(channel["local_balance"])
                if "remote_balance" not in channel:
                    channel["remote_balance"] = "0"
                else:
                    channel["remote_balance"] = format_sat_amount(channel["remote_balance"])
                if "remote_pubkey" in channel:
                    channel["remote_alias"] = get_lightning_peer_alias( channel["remote_pubkey"] )
                else:
                    channel["remote_alias"] = "Unknown"
                channels.append(channel)

        balance_info = get_lightning_balance_info()

        channel_balance_data = get_lightning_channel_balance()
        if channel_balance_data != None and "balance" in channel_balance_data:
            channel_balance = channel_balance_data["balance"]
        if channel_balance_data != None and "pending_open_balance" in channel_balance_data:
            channel_pending = channel_balance_data["pending_open_balance"]
        
        wallet_balance_data = get_lightning_wallet_balance()
        if wallet_balance_data != None and "confirmed_balance" in wallet_balance_data:
            wallet_balance = wallet_balance_data["confirmed_balance"]
        if wallet_balance_data != None and "unconfirmed_balance" in wallet_balance_data:
            wallet_pending = wallet_balance_data["unconfirmed_balance"]

            
    except Exception as e:
        templateData = {
            "title": "myNode Lightning Status",
            "message": str(e),
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd_error.html', **templateData)

    templateData = {
        "title": "myNode Lightning Status",
        "wallet_exists": wallet_exists,
        "wallet_logged_in": wallet_logged_in,
        "version": get_lnd_version(),
        "loop_version": get_loop_version(),
        "pool_version": get_pool_version(),
        "is_testnet_enabled": is_testnet_enabled(),
        "channel_backup_exists": channel_backup_exists,
        "status": status,
        "height": height,
        "alias": alias,
        "num_peers": num_peers,
        "num_active_channels": num_active_channels,
        "num_pending_channels": num_pending_channels,
        "num_inactive_channels": num_inactive_channels,
        "pubkey": pubkey,
        "uri": uri,
        "ip": ip,
        "lnd_deposit_address": lnd_deposit_address,
        "channel_balance": format_sat_amount(balance_info["channel_balance"]),
        "channel_pending": format_sat_amount(balance_info["channel_pending"]),
        "wallet_balance": format_sat_amount(balance_info["wallet_balance"]),
        "wallet_pending": format_sat_amount(balance_info["wallet_pending"]),
        "peers": peers,
        "channels": channels,
        "ui_settings": read_ui_settings()
    }
    return render_template('lnd.html', **templateData)
Exemple #25
0
def page_lnd():
    check_logged_in()

    height = 0
    alias = get_lnd_alias_file_data()
    num_peers = "0"
    num_active_channels = "TODO"
    num_pending_channels = "TODO"
    num_inactive_channels = "TODO"
    pubkey = "abcd"
    uri = ""
    ip = ""
    status = "Starting..."
    lnd_deposit_address = get_lnd_deposit_address()
    channel_balance = "N/A"
    channel_pending = "0"
    wallet_balance = "N/A"
    wallet_pending = "0"

    wallet_exists = lnd_wallet_exists()
    wallet_logged_in = is_lnd_logged_in()
    channel_backup_exists = lnd_channel_backup_exists()

    if not lnd_wallet_exists():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "watchtower_enabled": is_watchtower_enabled(),
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "status": "Please Create Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    if not is_lnd_logged_in():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "watchtower_enabled": is_watchtower_enabled(),
            "alias": alias,
            "status": get_lnd_status(),
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    try:
        data = get_lightning_info()

        if "block_height" in data:
            height = data['block_height']
        if "identity_pubkey" in data:
            pubkey = data['identity_pubkey']
        if "num_peers" in data:
            num_peers = data['num_peers']
        if "synced_to_chain" in data and data['synced_to_chain']:
            status = "Active"
        else:
            status = get_lnd_status()
        if "uris" in data and len(data['uris']) > 0:
            uri = data['uris'][0]
            ip = uri.split("@")[1]
        else:
            uri = "..."
            ip = "..."

        peers = get_lightning_peers()
        channels = get_lightning_channels()
        balance_info = get_lightning_balance_info()

        channel_balance_data = get_lightning_channel_balance()
        if channel_balance_data != None and "balance" in channel_balance_data:
            channel_balance = channel_balance_data["balance"]
        if channel_balance_data != None and "pending_open_balance" in channel_balance_data:
            channel_pending = channel_balance_data["pending_open_balance"]
        
        wallet_balance_data = get_lightning_wallet_balance()
        if wallet_balance_data != None and "confirmed_balance" in wallet_balance_data:
            wallet_balance = wallet_balance_data["confirmed_balance"]
        if wallet_balance_data != None and "unconfirmed_balance" in wallet_balance_data:
            wallet_pending = wallet_balance_data["unconfirmed_balance"]

        watchtower_server_info = get_lightning_watchtower_server_info()
        watchtower_uri = "..."
        if watchtower_server_info != None:
            if "uris" in watchtower_server_info and len(watchtower_server_info['uris']) > 0:
                watchtower_uri = watchtower_server_info['uris'][0]

            
    except Exception as e:
        templateData = {
            "title": "myNode Lightning Status",
            "header": "Lightning Status",
            #"message": str(e),
            "message": traceback.format_exc(),
            "ui_settings": read_ui_settings()
        }
        return render_template('error.html', **templateData)

    templateData = {
        "title": "myNode Lightning Status",
        "wallet_exists": wallet_exists,
        "wallet_logged_in": wallet_logged_in,
        "version": get_lnd_version(),
        "loop_version": get_loop_version(),
        "pool_version": get_pool_version(),
        "is_testnet_enabled": is_testnet_enabled(),
        "channel_backup_exists": channel_backup_exists,
        "status": status,
        "height": height,
        "alias": alias,
        "num_peers": num_peers,
        "num_active_channels": num_active_channels,
        "num_pending_channels": num_pending_channels,
        "num_inactive_channels": num_inactive_channels,
        "pubkey": pubkey,
        "uri": uri,
        "ip": ip,
        "watchtower_enabled": is_watchtower_enabled(),
        "lit_password": get_lnd_lit_password(),
        "lnd_deposit_address": lnd_deposit_address,
        "channel_balance": format_sat_amount(balance_info["channel_balance"]),
        "channel_pending": format_sat_amount(balance_info["channel_pending"]),
        "wallet_balance": format_sat_amount(balance_info["wallet_balance"]),
        "wallet_pending": format_sat_amount(balance_info["wallet_pending"]),
        "watchtower_uri": watchtower_uri,
        "peers": peers,
        "channels": channels,
        "ui_settings": read_ui_settings()
    }
    return render_template('lnd.html', **templateData)
Exemple #26
0
def page_tor():
    check_logged_in()

    # Check if we are premium
    if is_community_edition():
        return redirect("/")

    # Get Onion URLs
    ssh_onion_url = get_onion_url_ssh()
    general_onion_url = get_onion_url_general()
    btc_onion_url = get_onion_url_btc()
    lnd_onion_url = get_onion_url_lnd()
    electrs_onion_url = get_onion_url_electrs()

    # Services
    services = []
    services.append({
        "service": "myNode Web",
        "url": general_onion_url,
        "port": "80",
        "guide": ""
    })
    services.append({
        "service": "LND Hub",
        "url": general_onion_url,
        "port": "3000",
        "guide": ""
    })
    services.append({
        "service": "BTC RPC Explorer",
        "url": general_onion_url,
        "port": "3002",
        "guide": ""
    })
    services.append({
        "service": "Ride the Lightning",
        "url": general_onion_url,
        "port": "3010",
        "guide": ""
    })
    services.append({
        "service": "Bitcoin API (REST)",
        "url": btc_onion_url,
        "port": "8332",
        "guide": ""
    })
    services.append({
        "service": "LND API (gRPC)",
        "url": lnd_onion_url,
        "port": "10009",
        "guide": ""
    })
    services.append({
        "service": "LND API (REST)",
        "url": lnd_onion_url,
        "port": "10080",
        "guide": ""
    })
    services.append({
        "service": "SSH",
        "url": ssh_onion_url,
        "port": "22022",
        "guide": ""
    })
    services.append({
        "service": "Electrum Server",
        "url": electrs_onion_url,
        "port": "50001",
        "guide": "https://mynodebtc.com/guide/electrum_server_tor"
    })
    services.append({
        "service": "Electrum Server",
        "url": electrs_onion_url,
        "port": "50002",
        "guide": "https://mynodebtc.com/guide/electrum_server_tor"
    })

    # App links
    rpc_password = get_bitcoin_rpc_password()
    fully_noded_link = "btcrpc://*****:*****@{}:8332?label=myNode%20Tor".format(
        rpc_password, btc_onion_url)

    # Load page
    templateData = {
        "title": "myNode Tor Services",
        "services": services,
        "fully_noded_link": fully_noded_link,
        "ui_settings": read_ui_settings()
    }
    return render_template('tor.html', **templateData)
Exemple #27
0
def page_tor():
    check_logged_in()
    mynode_onion_hostname = "..."
    mynode_onion_password = "******"

    # Check if we are premium
    if is_community_edition():
        return redirect("/")

    # Get Onion URLs
    try:
        if os.path.isfile("/var/lib/tor/mynode/hostname"):
            with open("/var/lib/tor/mynode/hostname") as f:
                contents = f.read().split()
                mynode_onion_hostname = contents[0]
                mynode_onion_password = contents[1]
    except:
        mynode_onion_hostname = "error"
        mynode_onion_password = "******"

    # Services
    services = []
    services.append({"service": "myNode Web", "port": "80", "guide": ""})
    services.append({"service": "LND Hub", "port": "3000", "guide": ""})
    services.append({
        "service": "BTC RPC Explorer",
        "port": "3002",
        "guide": ""
    })
    services.append({"service": "LND Admin", "port": "3004", "guide": ""})
    services.append({
        "service": "Ride the Lightning",
        "port": "3010",
        "guide": ""
    })
    services.append({
        "service": "Bitcoin API (REST)",
        "port": "8332",
        "guide": ""
    })
    services.append({
        "service": "LND API (gRPC)",
        "port": "10009",
        "guide": ""
    })
    services.append({
        "service": "LND API (REST)",
        "port": "10080",
        "guide": ""
    })
    services.append({
        "service": "Electrum Server",
        "port": "50001",
        "guide": "https://mynodebtc.com/guide/electrum_server_tor"
    })
    services.append({
        "service": "Electrum Server",
        "port": "50002",
        "guide": "https://mynodebtc.com/guide/electrum_server_tor"
    })

    # App links
    rpc_password = get_bitcoin_rpc_password()
    fully_noded_link = "btcrpc://*****:*****@{}:8332?label=myNode%20Tor&v2password={}".format(
        rpc_password, mynode_onion_hostname, mynode_onion_password)

    # Load page
    templateData = {
        "title": "myNode Tor Services",
        "mynode_onion_hostname": mynode_onion_hostname,
        "mynode_onion_password": mynode_onion_password,
        "services": services,
        "fully_noded_link": fully_noded_link,
        "ui_settings": read_ui_settings()
    }
    return render_template('tor.html', **templateData)
Exemple #28
0
def page_lnd():
    check_logged_in()

    height = 0
    refresh_rate = 3600
    alias = get_lnd_alias_file_data()
    num_peers = "0"
    num_active_channels = "TODO"
    num_pending_channels = "TODO"
    num_inactive_channels = "TODO"
    pubkey = "abcd"
    uri = ""
    ip = ""
    status = "Starting..."
    lnd_deposit_address = get_lnd_deposit_address()
    channel_balance = "N/A"
    channel_pending = "0"
    wallet_balance = "N/A"
    wallet_pending = "0"

    wallet_exists = lnd_wallet_exists()
    wallet_logged_in = is_lnd_logged_in()
    channel_backup_exists = lnd_channel_backup_exists()

    lnd_has_error = get_service_status_code("lnd") != 0

    if not lnd_wallet_exists():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "lnd_has_error": lnd_has_error,
            "using_lnd_custom_config": using_lnd_custom_config(),
            "watchtower_enabled": is_watchtower_enabled(),
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "status": "Please Create Wallet",
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    if not is_lnd_logged_in():
        templateData = {
            "title": "myNode Lightning Wallet",
            "wallet_exists": wallet_exists,
            "wallet_logged_in": wallet_logged_in,
            "lnd_has_error": lnd_has_error,
            "watchtower_enabled": is_watchtower_enabled(),
            "alias": alias,
            "status": get_lnd_status(),
            "version": get_lnd_version(),
            "loop_version": get_loop_version(),
            "pool_version": get_pool_version(),
            "refresh_rate": 10,
            "ui_settings": read_ui_settings()
        }
        return render_template('lnd.html', **templateData)

    try:
        data = get_lightning_info()

        # If lightning data is still None, show message
        if data == None:
            templateData = {
                "title": "myNode Lightning Wallet",
                "wallet_exists": wallet_exists,
                "wallet_logged_in": False,
                "lnd_has_error": lnd_has_error,
                "watchtower_enabled": is_watchtower_enabled(),
                "alias": alias,
                "status": "Waiting on LND data...",
                "version": get_lnd_version(),
                "loop_version": get_loop_version(),
                "pool_version": get_pool_version(),
                "refresh_rate": 10,
                "ui_settings": read_ui_settings()
            }
            return render_template('lnd.html', **templateData)

        if "block_height" in data:
            height = data['block_height']
        if "identity_pubkey" in data:
            pubkey = data['identity_pubkey']
        if "num_peers" in data:
            num_peers = data['num_peers']
        if "synced_to_chain" in data and data['synced_to_chain']:
            status = "Active"
        else:
            status = get_lnd_status()
        if "uris" in data and len(data['uris']) > 0:
            uri = data['uris'][0]
            ip = uri.split("@")[1]
        else:
            uri = "..."
            ip = "..."

        peers = get_lightning_peers()
        channels = get_lightning_channels()
        balance_info = get_lightning_balance_info()

        channel_balance_data = get_lightning_channel_balance()
        if channel_balance_data != None and "balance" in channel_balance_data:
            channel_balance = channel_balance_data["balance"]
        if channel_balance_data != None and "pending_open_balance" in channel_balance_data:
            channel_pending = channel_balance_data["pending_open_balance"]
        
        wallet_balance_data = get_lightning_wallet_balance()
        if wallet_balance_data != None and "confirmed_balance" in wallet_balance_data:
            wallet_balance = wallet_balance_data["confirmed_balance"]
        if wallet_balance_data != None and "unconfirmed_balance" in wallet_balance_data:
            wallet_pending = wallet_balance_data["unconfirmed_balance"]

        # Update TX info
        update_lightning_tx_info()
        transactions = get_lightning_transactions()
        payments = get_lightning_payments()
        invoices = get_lightning_invoices()

        watchtower_server_info = get_lightning_watchtower_server_info()
        watchtower_uri = "..."
        if watchtower_server_info != None:
            if "uris" in watchtower_server_info and len(watchtower_server_info['uris']) > 0:
                watchtower_uri = watchtower_server_info['uris'][0]

            
    except Exception as e:
        templateData = {
            "title": "myNode Lightning Status",
            "header": "Lightning Status",
            #"message": str(e),
            "message": traceback.format_exc(),
            "refresh_rate": 10,
            "ui_settings": read_ui_settings()
        }
        return render_template('error.html', **templateData)

    if not is_lnd_ready():
        refresh_rate = 15

    templateData = {
        "title": "myNode Lightning Status",
        "is_community_edition": is_community_edition(),
        "wallet_exists": wallet_exists,
        "wallet_logged_in": wallet_logged_in,
        "lnd_has_error": lnd_has_error,
        "using_lnd_custom_config": using_lnd_custom_config(),
        "version": get_lnd_version(),
        "loop_version": get_loop_version(),
        "pool_version": get_pool_version(),
        "is_testnet_enabled": is_testnet_enabled(),
        "channel_backup_exists": channel_backup_exists,
        "status": status,
        "height": height,
        "alias": alias,
        "num_peers": num_peers,
        "num_active_channels": num_active_channels,
        "num_pending_channels": num_pending_channels,
        "num_inactive_channels": num_inactive_channels,
        "pubkey": pubkey,
        "uri": uri,
        "ip": ip,
        "channel_db_size": lnd_get_channel_db_size(),
        "watchtower_enabled": is_watchtower_enabled(),
        "lit_password": get_lnd_lit_password(),
        "lnd_deposit_address": lnd_deposit_address,
        "channel_balance": format_sat_amount(balance_info["channel_balance"]),
        "channel_pending": format_sat_amount(balance_info["channel_pending"]),
        "wallet_balance": format_sat_amount(balance_info["wallet_balance"]),
        "wallet_pending": format_sat_amount(balance_info["wallet_pending"]),
        "watchtower_uri": watchtower_uri,
        "peers": peers,
        "channels": channels,
        "transactions": transactions,
        "payments": payments,
        "invoices": invoices,
        "tx_display_limit": 8,
        "refresh_rate": refresh_rate,
        "ui_settings": read_ui_settings()
    }
    return render_template('lnd.html', **templateData)
Exemple #29
0
def page_lnd_pair_wallet():
    check_logged_in()

    # Load page
    if request.method == 'GET':
        return redirect(url_for(".page_lnd"))

    p = pam.pam()
    pw = request.form.get('password_pair_wallet')
    from_homepage = request.form.get('pair_wallet_from_homepage')
    if pw == None or p.authenticate("admin", pw) == False:
        if from_homepage != None:
            flash("Invalid Password", category="error")
            return redirect("/")
        else:
            flash("Invalid Password", category="error")
            return redirect(url_for(".page_lnd"))

    # Lndconnect Data
    lndconnect_local_grpc_text = get_text_contents("/tmp/mynode_lndconnect/lndconnect_local_grpc.txt")
    lndconnect_local_rest_text = get_text_contents("/tmp/mynode_lndconnect/lndconnect_local_rest.txt")
    lndconnect_tor_grpc_text = get_text_contents("/tmp/mynode_lndconnect/lndconnect_tor_grpc.txt")
    lndconnect_tor_rest_text = get_text_contents("/tmp/mynode_lndconnect/lndconnect_tor_rest.txt")
    zap_tor_text = get_text_contents("/tmp/mynode_lndconnect/zap_tor.txt")

    lndconnect_local_grpc_img = get_image_src_b64("/tmp/mynode_lndconnect/lndconnect_local_grpc.png")
    lndconnect_local_rest_img = get_image_src_b64("/tmp/mynode_lndconnect/lndconnect_local_rest.png")
    lndconnect_tor_grpc_img = get_image_src_b64("/tmp/mynode_lndconnect/lndconnect_tor_grpc.png")
    lndconnect_tor_rest_img = get_image_src_b64("/tmp/mynode_lndconnect/lndconnect_tor_rest.png")
    zap_tor_img = get_image_src_b64("/tmp/mynode_lndconnect/zap_tor.png")

    # Blue Wallet Data
    electrs_onion_url = get_onion_url_electrs()
    lndhub_onion_url = get_onion_url_lndhub()
    local_ip = get_local_ip()
    #LNDhub QR:
    #bluewallet:setlndhuburl?url=http%3A%2F%2Fg45wix2qhsxtoz2k675ikmlt5ypmcoz4nyhy44teku7amb7vqoh7jyyd.onion:3001

    #Electrum QR:
    #bluewallet:setelectrumserver?server=v7gtzf7nua6hdmb2wtqaqioqmesdb4xrlly4zwr7bvayxv2bpg665pqd.onion%3A50001%3At
    bluewallet_lndhub_local_text = "bluewallet:setlndhuburl?url=http://"+local_ip+":3000"
    bluewallet_lndhub_local_img = "/api/get_qr_code_image?url="+quote_plus(bluewallet_lndhub_local_text)
    bluewallet_lndhub_tor_text = "bluewallet:setlndhuburl?url=http://"+lndhub_onion_url+":3000"
    bluewallet_lndhub_tor_img = "/api/get_qr_code_image?url="+quote_plus(bluewallet_lndhub_tor_text)
    bluewallet_electrs_local_text = "bluewallet:setelectrumserver?server="+local_ip+":50002:s"
    bluewallet_electrs_local_img = "/api/get_qr_code_image?url="+quote_plus(bluewallet_electrs_local_text)
    bluewallet_electrs_tor_text = "bluewallet:setelectrumserver?server="+electrs_onion_url+":50001:t"     # Use non-SSL for Tor (scans in Bluewallet better)
    bluewallet_electrs_tor_img = "/api/get_qr_code_image?url="+quote_plus(bluewallet_electrs_tor_text)


    # Pairing options
    pairs = []
    pairs.append( create_pair(name="Lightning (gRPC + Local IP)", image_src=lndconnect_local_grpc_img,text=lndconnect_local_grpc_text,premium=False) )
    pairs.append( create_pair(name="Lightning (gRPC + Tor)", image_src=lndconnect_tor_grpc_img,text=lndconnect_tor_grpc_text,premium=True) )
    pairs.append( create_pair(name="Lightning (REST + Local IP)", image_src=lndconnect_local_rest_img,text=lndconnect_local_rest_text,premium=False) )
    pairs.append( create_pair(name="Lightning (REST + Tor)", image_src=lndconnect_tor_rest_img,text=lndconnect_tor_rest_text,premium=True) )
    pairs.append( create_pair(name="Blue Wallet (LNDHub + Local IP)", image_src=bluewallet_lndhub_local_img,text=bluewallet_lndhub_local_text,premium=False) )
    pairs.append( create_pair(name="Blue Wallet (LNDHub + Tor)", image_src=bluewallet_lndhub_tor_img,text=bluewallet_lndhub_tor_text,premium=True) )
    pairs.append( create_pair(name="Blue Wallet (Electrum + Local IP)", image_src=bluewallet_electrs_local_img,text=bluewallet_electrs_local_text,premium=False) )
    pairs.append( create_pair(name="Blue Wallet (Electrum + Tor)", image_src=bluewallet_electrs_tor_img,text=bluewallet_electrs_tor_text,premium=True) )
    #pairs.append( create_pair(name="Fully Noded (Tor)", image_src="",text="",premium=True) ) # Maybe not? pairs diff wallet
    pairs.append( create_pair(name="Zap (Local IP)", image_src=lndconnect_local_grpc_img,text=lndconnect_local_grpc_text,premium=False) )
    pairs.append( create_pair(name="Zap (Tor)", image_src=zap_tor_img,text=zap_tor_text,premium=True) )

    # Show lndconnect page
    templateData = {
        "title": "myNode Lightning Wallet",
        "dots_img": get_image_src_b64("/var/www/mynode/static/images/dots.png"),
        "pairs": pairs,
        "ui_settings": read_ui_settings()
    }
    return render_template('pair_wallet.html', **templateData)