示例#1
0
def fetch_services():
    """
    Fetch and return the json text from services.json.
    """

    services_response = fetch_url(SERVICES_URL)
    if services_response is None:
        sys.exit(f"Unable to fetch {SERVICES_URL}")

    return services_response.content
示例#2
0
def get_votpow(url):
    """
    Get the current catch up status of the node at the given RPC url.
    """

    response = fetch_url(f"{url}/status")

    try:
        return response.json()["result"]["validator_info"]["voting_power"]
    except:
        return "UNKNOWN"
示例#3
0
def get_version(url):
    """
    Get the version of the node at the given API url.
    """

    response = fetch_url(f"{url}/version")

    try:
        return response.json()["NdauVersion"]
    except:
        return "UNKNOWN"
示例#4
0
def get_height(url):
    """
    Get the current height of the node at the given API url.
    """

    response = fetch_url(f"{url}/block/current")

    try:
        return response.json()["block_meta"]["header"]["height"]
    except:
        # Return an invalid height to signal failure.
        return 0
示例#5
0
def get_peers(url):
    """
    Get the peer count of the node at the given RPC url.
    """

    response = fetch_url(f"{url}/net_info")

    try:
        return response.json()["result"]["n_peers"]
    except:
        # Return an invalid peer count to signal failure.
        return -1
示例#6
0
def get_health(url):
    """
    Get the health of the node at the given API url.
    """

    response = fetch_url(f"{url}/health")

    try:
        health = response.content.decode("utf-8").strip('"').rstrip('"\n')
        if len(health) != 0:
            return health
        # Blank health isn't really "healthy", but there was a response, so it's not "bad" either.
        return "ILL"
    except:
        return "BAD"
示例#7
0
def get_catchup(url):
    """
    Get the current catch up status of the node at the given RPC url.
    """

    response = fetch_url(f"{url}/status")

    try:
        sync_info = response.json()["result"]["sync_info"]
        if sync_info["catching_up"] or int(
                sync_info["latest_block_height"]) == 0:
            return "CATCHINGUP"
        return "COMPLETE"
    except:
        return "UNKNOWN"