예제 #1
0
def files_downloader(rpc_connection):
    while True:
        display_files_list(rpc_connection)
        print("\n")
        oracle_id = input("Input oracle ID you want to download file from: ")
        output_path = input(
            "Input output path for downloaded file (name included) e.g. /home/test.txt: "
        )
        oracle_info = rpclib.oracles_info(rpc_connection, oracle_id)
        name = oracle_info['name']
        latest_baton_txid = oracle_info['registered'][0]['batontxid']
        if name[0:12] == 'tonyconvert_':
            # downloading process here
            chunks_amount = int(name[12:])
            data = rpclib.oracles_samples(rpc_connection,
                                          oracle_id, latest_baton_txid,
                                          str(chunks_amount))["samples"]
            for chunk in reversed(data):
                with open(output_path, 'ab+') as file:
                    file.write(unhexlify(chunk[0]))
            print("I hope that file saved to " + output_path + "\n")
            input("Press [Enter] to continue...")
            break

        else:
            print(
                "I cant recognize file inside this oracle. I'm very sorry, boss."
            )
            input("Press [Enter] to continue...")
            break
예제 #2
0
def oracle_subscription_utxogen(rpc_connection):
    # TODO: have an idea since blackjoker new RPC call
    # grab all list and printout only or which owner match with node pubkey
    try:
        print(colorize("Oracles created from this instance by TUI: \n", "blue"))
        with open("oracles_list", "r") as file:
            for oracle in file:
                print(oracle)
        print(colorize('_' * 65, "blue"))
        print("\n")
    except FileNotFoundError:
        print("Seems like a no oracles created from this instance yet\n")
        pass
    while True:
        try:
            oracle_id = input("Input oracle ID you want to subscribe to: ")
            #printout to fast copypaste publisher id
            oracle_info = rpclib.oracles_info(rpc_connection, oracle_id)
            publishers = 0
            print(colorize("\nPublishers registered for a selected oracle: \n", "blue"))
            try:
                for entry in oracle_info["registered"]:
                    publisher = entry["publisher"]
                    print(publisher + "\n")
                    publishers = publishers + 1
                print("Total publishers:{}".format(publishers))
            except (KeyError, ConnectionResetError):
                print(colorize("Please re-check your input. Oracle txid seems not valid.", "red"))
                pass
            print(colorize('_' * 65, "blue"))
            print("\n")
            if publishers == 0:
                print(colorize("This oracle have no publishers to subscribe.\n"
                               "Please register as an oracle publisher first and/or wait since registration transaciton mined!", "red"))
                input("Press [Enter] to continue...")
                break
            publisher_id = input("Input oracle publisher id you want to subscribe to: ")
            data_fee = input("Input subscription fee (in COINS!): ")
            utxo_num = int(input("Input how many transactions you want to broadcast: "))
        except KeyboardInterrupt:
            break
        while utxo_num > 0:
            while True:
                oracle_subscription_hex = rpclib.oracles_subscribe(rpc_connection, oracle_id, publisher_id, data_fee)
                oracle_subscription_txid = rpclib.sendrawtransaction(rpc_connection, oracle_subscription_hex['hex'])
                mempool = rpclib.get_rawmempool(rpc_connection)
                if oracle_subscription_txid in mempool:
                    break
                else:
                    pass
            print(colorize("Oracle subscription transaction broadcasted: " + oracle_subscription_txid, "green"))
            utxo_num = utxo_num - 1
        input("Press [Enter] to continue...")
        break
예제 #3
0
def get_files_list(rpc_connection):

    start_time = time.time()
    oracles_list = rpclib.oracles_list(rpc_connection)
    files_list = []
    for oracle_txid in oracles_list:
        oraclesinfo_result = rpclib.oracles_info(rpc_connection, oracle_txid)
        description = oraclesinfo_result['description']
        name = oraclesinfo_result['name']
        if name[0:12] == 'tonyconvert_':
            new_file = '[' + name + ': ' + description + ']: ' + oracle_txid
            files_list.append(new_file)
    print("--- %s seconds ---" % (time.time() - start_time))
    return files_list
예제 #4
0
def gateways_bind_tui(rpc_connection):
    # main loop with keyboard interrupt handling
    while True:
        try:
            while True:
                try:
                    print(
                        colorize(
                            "Tokens created from this instance by TUI: \n",
                            "blue"))
                    with open("tokens_list", "r") as file:
                        for oracle in file:
                            print(oracle)
                    print(colorize('_' * 65, "blue"))
                    print("\n")
                except FileNotFoundError:
                    print(
                        "Seems like a no oracles created from this instance yet\n"
                    )
                    pass
                token_id = input(
                    "Input id of token you want to use in gw bind: ")
                try:
                    token_name = rpclib.token_info(rpc_connection,
                                                   token_id)["name"]
                except KeyError:
                    print(
                        colorize("Not valid tokenid. Please try again.",
                                 "red"))
                    input("Press [Enter] to continue...")
                token_info = rpclib.token_info(rpc_connection, token_id)
                print(
                    colorize(
                        "\n{} token total supply: {}\n".format(
                            token_id, token_info["supply"]), "blue"))
                token_supply = input("Input supply for token binding: ")
                try:
                    print(
                        colorize(
                            "\nOracles created from this instance by TUI: \n",
                            "blue"))
                    with open("oracles_list", "r") as file:
                        for oracle in file:
                            print(oracle)
                    print(colorize('_' * 65, "blue"))
                    print("\n")
                except FileNotFoundError:
                    print(
                        "Seems like a no oracles created from this instance yet\n"
                    )
                    pass
                oracle_id = input(
                    "Input id of oracle you want to use in gw bind: ")
                try:
                    oracle_name = rpclib.oracles_info(rpc_connection,
                                                      oracle_id)["name"]
                except KeyError:
                    print(
                        colorize("Not valid oracleid. Please try again.",
                                 "red"))
                    input("Press [Enter] to continue...")
                while True:
                    coin_name = input(
                        "Input external coin ticker (binded oracle and token need to have same name!): "
                    )
                    if token_name == oracle_name and token_name == coin_name:
                        break
                    else:
                        print(
                            colorize(
                                "Token name, oracle name and external coin ticker should match!",
                                "red"))
                while True:
                    M = input(
                        "Input minimal amount of pubkeys needed for transaction confirmation (1 for non-multisig gw): "
                    )
                    N = input(
                        "Input maximal amount of pubkeys needed for transaction confirmation (1 for non-multisig gw): "
                    )
                    if (int(N) >= int(M)):
                        break
                    else:
                        print(
                            "Maximal amount of pubkeys should be more or equal than minimal. Please try again."
                        )
                pubkeys = []
                for i in range(int(N)):
                    pubkeys.append(input("Input pubkey {}: ".format(i + 1)))
                #pubkeys = ', '.join(pubkeys)
                args = [
                    rpc_connection, token_id, oracle_id, coin_name,
                    token_supply, M, N
                ]
                args = args + pubkeys
                # broadcasting block
                try:
                    gateways_bind_hex = rpclib.gateways_bind(*args)
                except Exception as e:
                    print(e)
                    input("Press [Enter] to continue...")
                    break
                try:
                    gateways_bind_txid = rpclib.sendrawtransaction(
                        rpc_connection, gateways_bind_hex["hex"])
                except Exception as e:
                    print(e)
                    print(gateways_bind_hex)
                    input("Press [Enter] to continue...")
                    break
                else:
                    print(
                        colorize(
                            "Gateway bind transaction broadcasted: " +
                            gateways_bind_txid, "green"))
                    file = open("gateways_list", "a")
                    file.writelines(gateways_bind_txid + "\n")
                    file.close()
                    print(
                        colorize("Entry added to gateways_list file!\n",
                                 "green"))
                    input("Press [Enter] to continue...")
                    break
            break
        except KeyboardInterrupt:
            break