Exemplo n.º 1
0
def rpc_connection_tui():
    # TODO: possible to save multiply entries from successfull sessions and ask user to choose then
    while True:
        restore_choice = input("Do you want to use connection details from previous session? [y/n]: ")
        if restore_choice == "y":
            try:
                with open("connection.json", "r") as file:
                    connection_json = json.load(file)
                    rpc_user = connection_json["rpc_user"]
                    rpc_password = connection_json["rpc_password"]
                    rpc_port = connection_json["rpc_port"]
                    rpc_connection = rpclib.rpc_connect(rpc_user, rpc_password, int(rpc_port))
            except FileNotFoundError:
                print(colorize("You do not have cached connection details. Please select n for connection setup", "red"))
            break
        elif restore_choice == "n":
            rpc_user = input("Input your rpc user: "******"Input your rpc password: "******"Input your rpc port: ")
            connection_details = {"rpc_user": rpc_user,
                                  "rpc_password": rpc_password,
                                  "rpc_port": rpc_port}
            connection_json = json.dumps(connection_details)
            with open("connection.json", "w+") as file:
                file.write(connection_json)
            rpc_connection = rpclib.rpc_connect(rpc_user, rpc_password, int(rpc_port))
            break
        else:
            print(colorize("Please input y or n", "red"))
    return rpc_connection
Exemplo n.º 2
0
def rpc_kmd_connection_tui():
    while True:
        restore_choice = input(
            "Do you want to use KMD daemon connection details from previous session? [y/n]: "
        )
        if restore_choice == "y":
            try:
                with open("connection_kmd.json", "r") as file:
                    connection_json = json.load(file)
                    rpc_user = connection_json["rpc_user"]
                    rpc_password = connection_json["rpc_password"]
                    rpc_port = connection_json["rpc_port"]
                    rpc_connection_kmd = rpclib.rpc_connect(
                        rpc_user, rpc_password, int(rpc_port))
                    try:
                        print(rpc_connection_kmd.getinfo())
                        print(colorize("Successfully connected!\n", "green"))
                        input("Press [Enter] to continue...")
                        break
                    except Exception as e:
                        print(e)
                        print(colorize("NOT CONNECTED!\n", "red"))
                        input("Press [Enter] to continue...")
                        break
            except FileNotFoundError:
                print(
                    colorize(
                        "You do not have cached KMD daemon connection details."
                        " Please select n for connection setup", "red"))
                input("Press [Enter] to continue...")
        elif restore_choice == "n":
            rpc_user = input("Input your rpc user: "******"Input your rpc password: "******"Input your rpc port: ")
            connection_details = {
                "rpc_user": rpc_user,
                "rpc_password": rpc_password,
                "rpc_port": rpc_port
            }
            connection_json = json.dumps(connection_details)
            with open("connection_kmd.json", "w+") as file:
                file.write(connection_json)
            rpc_connection_kmd = rpclib.rpc_connect(rpc_user, rpc_password,
                                                    int(rpc_port))
            try:
                print(rpc_connection_kmd.getinfo())
                print(colorize("Successfully connected!\n", "green"))
                input("Press [Enter] to continue...")
                break
            except Exception as e:
                print(e)
                print(colorize("NOT CONNECTED!\n", "red"))
                input("Press [Enter] to continue...")
                break
        else:
            print(colorize("Please input y or n", "red"))
    return rpc_connection_kmd
Exemplo 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