Esempio n. 1
0
def get_balance(rpc_connection):
    if App.get_running_app().is_connected:
        balance = str(rpclib.getbalance(rpc_connection))
        ticker = rpclib.getinfo(rpc_connection)["name"]
        balance_reflection = balance + " " + ticker
    # to not crash in some cases when not connected or losing connection
    else:
        balance_reflection = ""
    return balance_reflection
Esempio n. 2
0
def getinfo_tui(rpc_connection):

    info_raw = rpclib.getinfo(rpc_connection)
    if isinstance(info_raw, dict):
        for key in info_raw:
            print("{}: {}".format(key, info_raw[key]))
        input("Press [Enter] to continue...")
    else:
        print("Error!\n")
        print(info_raw)
        input("\nPress [Enter] to continue...")
Esempio n. 3
0
    def verify_credentials(self):

        while True:
            try:
                server_input = self.ids["rpcserver"].text
                user_input = self.ids["rpcuser"].text
                password_input = self.ids["rpcpassword"].text
                port_input = int(self.ids["port"].text)
                connection = rpclib.rpc_connect(user_input, password_input,
                                                server_input, port_input)
                rpclib.getinfo(connection)
            except Exception as e:
                print(e)
                print("Not connected. Please check credentials")
                content = Button(text='Close me!')
                popup = Popup(content=content, auto_dismiss=False)
                # TODO: have to throw popup and in this case not clean text fields
                self.ids["rpcserver"].text = ''
                self.ids["rpcuser"].text = ''
                self.ids["rpcpassword"].text = ''
                self.ids["port"].text = ''
                break
            else:
                App.get_running_app().rpc_connection = connection
                App.get_running_app().is_connected = True
                if self.ids["savelogin"].active:
                    connection_details = {
                        "rpc_server": self.ids["rpcserver"].text,
                        "rpc_user": self.ids["rpcuser"].text,
                        "rpc_password": self.ids["rpcpassword"].text,
                        "rpc_port": self.ids["port"].text
                    }
                    connection_json = json.dumps(connection_details)
                    with open("connection.json", "w+") as file:
                        file.write(connection_json)
                    print("Saved login details")
                self.manager.current = "user"
                # TODO: loading channels list on startup
                break
Esempio n. 4
0
                        break
            else:
                list(menuItems[int(choice)].values())[0](rpc_connection)
        except (ValueError, IndexError):
            pass


if __name__ == "__main__":
    while True:
        try:
            print(
                tuilib.colorize(
                    "Welcome to the GatewaysCC TUI!\nPlease provide RPC connection details for initialization",
                    "blue"))
            rpc_connection = tuilib.rpc_connection_tui()
            rpclib.getinfo(rpc_connection)
        except Exception:
            print(
                tuilib.colorize(
                    "Cant connect to RPC! Please re-check credentials.",
                    "pink"))
        else:
            print(tuilib.colorize("Succesfully connected!\n", "green"))
            with (open("lib/logo.txt", "r")) as logo:
                for line in logo:
                    print(line, end='')
                    time.sleep(0.04)
                print("\n")
            break
    main()
Esempio n. 5
0
def convert_file_oracle_D(rpc_connection):
    while True:
        path = input("Input path to file you want to upload to oracle: ")
        try:
            hex_data = (hexdump(path, 1))
        except Exception as e:
            print(e)
            print(
                "Seems something goes wrong (I guess you've specified wrong path)!"
            )
            input("Press [Enter] to continue...")
            break
        else:
            length = round(len(hex_data) / 2)
            # if length > 800000:
            #     print("Too big file size to upload for this version of program. Maximum size is 800KB.")
            #     input("Press [Enter] to continue...")
            #     break
            if length > 8000:
                # if file is more than 8000 bytes - slicing it to <= 8000 bytes chunks (16000 symbols = 8000 bytes)
                data = [
                    hex_data[i:i + 16000]
                    for i in range(0, len(hex_data), 16000)
                ]
                chunks_amount = len(data)
                # TODO: have to create oracle but subscribe this time chunks amount times to send whole file in same block
                # TODO: 2 - on some point file will not fit block - have to find this point
                # TODO: 3 way how I want to implement it first will keep whole file in RAM - have to implement some way to stream chunks to oracle before whole file readed
                # TODO: have to "optimise" registration fee
                # Maybe just check size first by something like a du ?
                print("Length: " + str(length) + " bytes.\n Chunks amount: " +
                      str(chunks_amount))
                new_oracle_hex = rpclib.oracles_create(
                    rpc_connection, "tonyconvert_" + str(chunks_amount), path,
                    "D")
                new_oracle_txid = rpclib.sendrawtransaction(
                    rpc_connection, new_oracle_hex["hex"])
                time.sleep(0.5)
                oracle_register_hex = rpclib.oracles_register(
                    rpc_connection, new_oracle_txid, "10000")
                oracle_register_txid = rpclib.sendrawtransaction(
                    rpc_connection, oracle_register_hex["hex"])
                # subscribe chunks_amount + 1 times, but lets limit our broadcasting 100 tx per block (800KB/block)
                if chunks_amount > 100:
                    utxo_num = 101
                else:
                    utxo_num = chunks_amount
                while utxo_num > 0:
                    while True:
                        oracle_subscription_hex = rpclib.oracles_subscribe(
                            rpc_connection, new_oracle_txid,
                            rpclib.getinfo(rpc_connection)["pubkey"], "0.001")
                        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
                # waiting for last broadcasted subscribtion transaction to be mined to be sure that money are on oracle balance
                while True:
                    mempool = rpclib.get_rawmempool(rpc_connection)
                    if oracle_subscription_txid in mempool:
                        print(
                            "Waiting for oracle subscribtion tx to be mined" +
                            "\n")
                        time.sleep(6)
                        pass
                    else:
                        break
                print("Oracle preparation is finished. Oracle txid: " +
                      new_oracle_txid)
                # can publish data now
                counter = 0
                for chunk in data:
                    hex_length_bigendian = format(round(len(chunk) / 2),
                                                  '#06x')[2:]
                    # swap to get little endian length
                    a = hex_length_bigendian[2:]
                    b = hex_length_bigendian[:2]
                    hex_length = a + b
                    data_for_oracle = str(hex_length) + chunk
                    counter = counter + 1
                    # print("Chunk number: " + str(counter) + "\n")
                    # print(data_for_oracle)
                    try:
                        oracles_data_hex = rpclib.oracles_data(
                            rpc_connection, new_oracle_txid, data_for_oracle)
                    except Exception as e:
                        print(data_for_oracle)
                        print(e)
                        input("Press [Enter] to continue...")
                        break
                    # on broadcasting ensuring that previous one reached mempool before blast next one
                    while True:
                        mempool = rpclib.get_rawmempool(rpc_connection)
                        oracle_data_txid = rpclib.sendrawtransaction(
                            rpc_connection, oracles_data_hex["hex"])
                        #time.sleep(0.1)
                        if oracle_data_txid in mempool:
                            break
                        else:
                            pass
                    # blasting not more than 100 at once (so maximum capacity per block can be changed here)
                    # but keep in mind that registration UTXOs amount needs to be changed too !
                    if counter % 100 == 0 and chunks_amount > 100:
                        while True:
                            mempool = rpclib.get_rawmempool(rpc_connection)
                            if oracle_data_txid in mempool:
                                print(
                                    "Waiting for previous data chunks to be mined before send new ones"
                                    + "\n")
                                print("Sent " + str(counter) +
                                      " chunks from " + str(chunks_amount))
                                time.sleep(6)
                                pass
                            else:
                                break

                print("Last baton: " + oracle_data_txid)
                input("Press [Enter] to continue...")
                break
            # if file suits single oraclesdata just broadcasting it straight without any slicing
            else:
                hex_length_bigendian = format(length, '#06x')[2:]
                # swap to get little endian length
                a = hex_length_bigendian[2:]
                b = hex_length_bigendian[:2]
                hex_length = a + b
                data_for_oracle = str(hex_length) + hex_data
                print("File hex representation: \n")
                print(data_for_oracle + "\n")
                print("Length: " + str(length) + " bytes")
                print("File converted!")
                new_oracle_hex = rpclib.oracles_create(rpc_connection,
                                                       "tonyconvert_" + "1",
                                                       path, "D")
                new_oracle_txid = rpclib.sendrawtransaction(
                    rpc_connection, new_oracle_hex["hex"])
                time.sleep(0.5)
                oracle_register_hex = rpclib.oracles_register(
                    rpc_connection, new_oracle_txid, "10000")
                oracle_register_txid = rpclib.sendrawtransaction(
                    rpc_connection, oracle_register_hex["hex"])
                time.sleep(0.5)
                oracle_subscribe_hex = rpclib.oracles_subscribe(
                    rpc_connection, new_oracle_txid,
                    rpclib.getinfo(rpc_connection)["pubkey"], "0.001")
                oracle_subscribe_txid = rpclib.sendrawtransaction(
                    rpc_connection, oracle_subscribe_hex["hex"])
                time.sleep(0.5)
                while True:
                    mempool = rpclib.get_rawmempool(rpc_connection)
                    if oracle_subscribe_txid in mempool:
                        print(
                            "Waiting for oracle subscribtion tx to be mined" +
                            "\n")
                        time.sleep(6)
                        pass
                    else:
                        break
                oracles_data_hex = rpclib.oracles_data(rpc_connection,
                                                       new_oracle_txid,
                                                       data_for_oracle)
                try:
                    oracle_data_txid = rpclib.sendrawtransaction(
                        rpc_connection, oracles_data_hex["hex"])
                except Exception as e:
                    print(oracles_data_hex)
                    print(e)
                    input("Press [Enter] to continue...")
                    break
                else:
                    print("Oracle created: " + str(new_oracle_txid))
                    print("Data published: " + str(oracle_data_txid))
                    input("Press [Enter] to continue...")
                    break
Esempio n. 6
0
def convert_file_oracle_d(rpc_connection):
    while True:
        path = input("Input path to file you want to upload to oracle: ")
        try:
            hex_data = (hexdump(path, 1))[2:]
        except Exception as e:
            print(e)
            print(
                "Seems something goes wrong (I guess you've specified wrong path)!"
            )
            input("Press [Enter] to continue...")
            break
        else:
            length = round(len(hex_data) / 2)
            if length > 256:
                print("Length: " + str(length) + " bytes")
                print("File is too big for this app")
                input("Press [Enter] to continue...")
                break
            else:
                hex_length = format(length, '#04x')[2:]
                data_for_oracle = str(hex_length) + hex_data
                print("File hex representation: \n")
                print(data_for_oracle + "\n")
                print("Length: " + str(length) + " bytes")
                print("File converted!")
                new_oracle_hex = rpclib.oracles_create(rpc_connection,
                                                       "tonyconvert", path,
                                                       "d")
                new_oracle_txid = rpclib.sendrawtransaction(
                    rpc_connection, new_oracle_hex["hex"])
                time.sleep(0.5)
                oracle_register_hex = rpclib.oracles_register(
                    rpc_connection, new_oracle_txid, "10000")
                oracle_register_txid = rpclib.sendrawtransaction(
                    rpc_connection, oracle_register_hex["hex"])
                time.sleep(0.5)
                oracle_subscribe_hex = rpclib.oracles_subscribe(
                    rpc_connection, new_oracle_txid,
                    rpclib.getinfo(rpc_connection)["pubkey"], "0.001")
                oracle_subscribe_txid = rpclib.sendrawtransaction(
                    rpc_connection, oracle_subscribe_hex["hex"])
                time.sleep(0.5)
                while True:
                    mempool = rpclib.get_rawmempool(rpc_connection)
                    if oracle_subscribe_txid in mempool:
                        print(
                            "Waiting for oracle subscribtion tx to be mined" +
                            "\n")
                        time.sleep(6)
                        pass
                    else:
                        break
                oracles_data_hex = rpclib.oracles_data(rpc_connection,
                                                       new_oracle_txid,
                                                       data_for_oracle)
                try:
                    oracle_data_txid = rpclib.sendrawtransaction(
                        rpc_connection, oracles_data_hex["hex"])
                except Exception as e:
                    print(oracles_data_hex)
                    print(e)
                print("Oracle created: " + str(new_oracle_txid))
                print("Data published: " + str(oracle_data_txid))
                input("Press [Enter] to continue...")
                break
Esempio n. 7
0
                list(menuItems[int(choice)].values())[0](rpc_connection)
        except (ValueError, IndexError):
            pass


if __name__ == "__main__":
    while True:
        chain = "ROGUE"
        try:
            print(
                tuilib.colorize(
                    "Welcome to the RogueCC TUI!\n"
                    "Please provide asset chain RPC connection details for initialization",
                    "blue"))
            rpc_connection = rpclib.def_credentials(chain)
            rpclib.getinfo(rpc_connection)
            # waiting until chain is in sync
            while True:
                have_blocks = rpclib.getinfo(rpc_connection)["blocks"]
                longest_chain = rpclib.getinfo(rpc_connection)["longestchain"]
                if have_blocks != longest_chain:
                    print(tuilib.colorize("ROGUE not synced yet.", "red"))
                    print("Have " + str(have_blocks) + " from " +
                          str(longest_chain) + " blocks")
                    time.sleep(5)
                else:
                    print(tuilib.colorize("Chain is synced!", "green"))
                    break
            # checking if pubkey is set and set valid if not
            info = rpclib.getinfo(rpc_connection)
            if "pubkey" in info.keys():