Exemple #1
0
def check_node():
    app_log.info("Connecting to node...")
    for i in range(1, 21):
        check_version = rpc.node_version()
        if "node_vendor" in check_version:

            try:
                version_str = check_version["node_vendor"]
                version = float(version_str[version_str.index('V') +
                                            1:len(version_str)])
            except:
                app_log.error("Could not detect your nano node version")
                quit()
            else:
                if version < 21.2:
                    app_log.error("Your Nano node version " + version_str +
                                  " is not supported. Upgrade to >= V21.2")
                    quit()
                else:
                    app_log.info("Node" + " (" + version_str +
                                 ") is online on " + worker["node"])
                    return True
        else:
            app_log.info("Node " + worker["node"] + " error: " +
                         check_version["error"])
            if i <= 20:
                app_log.info("Retrying again in 15 seconds... " + str(i) +
                             " of 20")
        time.sleep(15)
    app_log.info("Exiting...")
    quit()
Exemple #2
0
def check_worker():
    app_log.info("Connecting to worker node...")
    check_worker = rpc.validate_work(
        "718CC2121C3E641059BC1C2CFC45666C99E8AE922F7A807B7D07B62C995D79E2",
        "2bf29ef00786a6bc")
    if "difficulty" in check_worker:
        if check_worker["difficulty"] == "ffffffd21c3933f4":
            app_log.info("Worker is online on " + worker["worker_node"])
        else:
            app_log.error("Worker " + worker["worker_node"] +
                          " error validating! Exiting...")
            quit()
    else:
        app_log.info("Worker " + worker["worker_node"] + " error: " +
                     str(check_worker["error"]))
        app_log.info("Exiting...")
        quit()
Exemple #3
0
def register_worker(account, previous, ip_account, multiplier):
    if rpc.balance(account) >= register_config["register_code"]:
        app_log.info(
            "You have sufficient funds to register your worker address")
        app_log.info("Registering worker account with your current IP")
        r = rpc.send(account, ip_account, previous, register_config["account"],
                     register_config["register_code"])
    else:
        app_log.info(
            "Insufficient funds, checking for unpocketed transactions...")
        pending = rpc.pending_filter(account, register_config["register_code"],
                                     1)
        if pending == None:
            app_log.warning(
                "You have not sufficient funds to register your worker address! Please send at least "
                + str(register_config["register_code"]) +
                " raws to your worker account")
            return False
        else:
            for block in pending:
                app_log.info("Receiving pending block: " +
                             str(pending[block]) + " raws")
                r = rpc.receive(account, worker["private_key"],
                                worker["representative"], int(pending[block]),
                                block)
                if 'hash' in r:
                    app_log.info("Transaction received!" + "! Block: " +
                                 r["hash"])
                else:
                    app_log.error("Transaction receiving fail. Details: " +
                                  json.dumps(r))
                    return False
            app_log.info("Ok, registering worker now")
            r = rpc.send(account, ip_account, rpc.frontier(account),
                         register_config["account"],
                         register_config["register_code"])
    if 'hash' in r:
        app_log.info("Successfully registred worker! Block: " + r["hash"])
    else:
        app_log.error("Register transaction fail. Details: " + json.dumps(r))
        return False
Exemple #4
0
def check_worker_register():
    app_log.info("Checking register...")
    history = rpc.check_history(worker["account"], register_config["account"])
    myIP = get_my_ip()  #check IP register
    ip_account = encode_ip(myIP)
    if history is not None:
        if int(history["amount"]) == register_config["register_code"]:
            app_log.info("Found your worker account registration: " +
                         worker["account"])
            if ip_account == history["representative"]:
                app_log.info("Found your actuall IP address registration: " +
                             myIP)
            else:
                app_log.info(
                    "Not found your actuall IP address registration: " + myIP)
                try_r = register_worker(worker["account"],
                                        rpc.frontier(worker["account"]),
                                        ip_account, 1.0)
                if (try_r is False):
                    app_log.error("Registration failed")
                    quit()
        else:
            app_log.info("Incorrect amount in register")
            try_r = register_worker(worker["account"],
                                    rpc.frontier(worker["account"]),
                                    ip_account, 1.0)
            if (try_r is False):
                app_log.error("Registration failed")
                quit()
    else:
        app_log.info("Not found your worker registration: " +
                     worker["account"])
        try_r = register_worker(worker["account"],
                                rpc.frontier(worker["account"]), ip_account,
                                1.0)
        if (try_r is False):
            app_log.error("Registration failed")
            quit()
Exemple #5
0
    except Exception as e:
        raise Exception(
            "Invalid config in worker_config.json found! Details: " + str(e))

    #Check config file
    try:
        nanolib.validate_account_id(register_config["account"])
    except Exception as e:
        raise Exception(
            "Invalid config in register_config.json found! Details: " + str(e))

    #Check if key pair is valid
    if worker["account"] != nanolib.get_account_id(
            private_key=worker["private_key"], prefix="nano_"):
        raise Exception("Invalid key pair")

    return {"worker_config": worker, "register_config": register_config}


#worker api config
worker = {}
register_config = {}
try:
    importingConfig = importConfig()
    worker = importingConfig["worker_config"]
    register_config = importingConfig["register_config"]
    app_log.info("Configurations okay")
except Exception as err:
    app_log.error(err)
    quit()