def test_node_connection_saving_and_unl(self): temp_private_key_class = Wallet_Create() node_1 = ndstart("127.0.0.1", 10001) temp_private_key = temp_private_key_class.toPem() saved_wallets = get_saved_wallet() for each_wallet in saved_wallets: if temp_private_key == saved_wallets[each_wallet]["privatekey"]: Wallet_Delete(each_wallet) temp_private_key_class2 = Wallet_Create() node_2 = ndstart("127.0.0.1", 10002) temp_private_key2 = temp_private_key_class2.toPem() saved_wallets2 = get_saved_wallet() for each_wallet in saved_wallets2: if temp_private_key2 == saved_wallets2[each_wallet]["privatekey"]: Wallet_Delete(each_wallet) ndconnect("127.0.0.1", 10001) finded_node = False in_unl_list = False get_as_node = False nodes_list = get_connected_node() for element in nodes_list: if element == node_1.id or element == node_2.id: finded_node = True save_new_unl_node(node_1.id) save_new_unl_node(node_2.id) temp_unl_node_list = get_unl_nodes() temp_get_as_node_type = get_as_node_type(temp_unl_node_list) for unl_element in temp_unl_node_list: if unl_element == node_1.id or unl_element == node_2.id: for node_element_of_unl in temp_get_as_node_type: if node_1.host == node_element_of_unl.host or node_2 == node_element_of_unl.host: if node_1.port == node_element_of_unl.port or node_2 == node_element_of_unl.port: get_as_node = True in_unl_list = True unl_node_delete(unl_element) connected_node_delete(element) node_1.stop() node_2.stop() self.assertEqual(finded_node, True, "Problem on connection saving system.") self.assertEqual(in_unl_list, True, "Problem on UNL node saving system.") self.assertEqual(get_as_node, True, "Problem on UNL get as node system.")
def add_unl_node_func(self, widget): text_list = self.get_add_unl_node_dialog_text() pubkey = text_list[0] print(pubkey) from node.unl import save_new_unl_node save_new_unl_node(pubkey) self.add_unl_node_dialog.dismiss()
def add_new_unl(self): id = simpledialog.askstring("Input", "ID: ", parent=self.toplevel) if id is not None: print("Pubkey: ", id) else: print("You don't write ID ?") from node.unl import save_new_unl_node save_new_unl_node(id) messagebox.showinfo('Node', ("Added new node. " + "ID: " + id))
def menu(): """ The main structure of the cli mode, this function prints the menu, listens to the entries, makes the directions. """ animation = [ "[■□□□□□□□□□]", "[■■□□□□□□□□]", "[■■■□□□□□□□]", "[■■■■□□□□□□]", "[■■■■■□□□□□]", "[■■■■■■□□□□]", "[■■■■■■■□□□]", "[■■■■■■■■□□]", "[■■■■■■■■■□]", "[■■■■■■■■■■]" ] for i in range(len(animation)): time.sleep(0.1) sys.stdout.write("\r" + animation[i]) sys.stdout.flush() while True: show_menu() choices_input = question_maker(mode="main") if choices_input == "pw": print_wallets() if choices_input == "w": wallet_selector() if choices_input == "cw": create_a_wallet() if choices_input == "dw": if "y" == input("Are you sure ? (y or n): "): delete_current_wallet() if choices_input == "sc": send_the_coin(input("Please write receiver adress: "), input("Coin Amount (ex. 1.0): "), getpass("Password: "******"gb": print_balance() if choices_input == "help": show_menu() if choices_input == "ndstart": ndstart(str(input("ip: ")), int(input("port: "))) if choices_input == "ndstop": ndstop() if choices_input == "ndconnect": ndconnect(str(input("node ip: ")), int(input("node port: "))) if choices_input == "ndconnectmixdb": ndconnectmixdb() if choices_input == "ndnewunl": save_new_unl_node(input("Please write ID of the node: ")) if choices_input == "ndid": print(ndid()) if choices_input == "testmodeon": test_mode(True) if choices_input == "testmodeoff": test_mode(False) if choices_input == "debugmodeon": debug_mode(True) if choices_input == "debugmodeoff": debug_mode(False) if choices_input == "exptrcsv": if export_the_transactions(): print( f"CSV file created in {MY_TRANSACTION_EXPORT_PATH} directory" ) else: print("You have not a transaction") if choices_input == "returntrs": PrintTransactions() if choices_input == "getblock": if the_settings()["test_mode"]: CreateBlock() else: GetBlockFromOtherNode() if choices_input == "status": print(Status()) if choices_input == "0": exit()
def arguments(): parser = argparse.ArgumentParser( description= "This is an open source decentralized application network. In this network, you can develop and publish decentralized applications. Use the menu (-m) or GUI to gain full control and use the node, operation, etc." ) parser.add_argument('-pw', '--printwallet', action='store_true', help='Print Wallets') parser.add_argument('-w', '--wallet', type=int, help='Change Wallet') parser.add_argument('-cw', '--createwallet', help='Create wallet') parser.add_argument('-dw', '--deletewallet', action='store_true', help='Delete wallet') parser.add_argument('-gb', '--getbalance', action='store_true', help='Get Balance') parser.add_argument('-ndnunl', '--ndnewunl', type=str, help='Add new UNL node') parser.add_argument('-ndid', '--ndid', action='store_true', help='Print my id') parser.add_argument('-tmon', '--testmodeon', action='store_true', help='Test Mode On') parser.add_argument('-tmoff', '--testmodeoff', action='store_true', help='Test Mode Off') parser.add_argument('-dmon', '--debugmodeon', action='store_true', help='Debug Mode On') parser.add_argument('-dmoff', '--debugmodeoff', action='store_true', help='Debug Mode Off') parser.add_argument('-exptrcsv', '--exporttransactioncsv', action='store_true', help='Exports the transaction as csv') parser.add_argument('-returntrans', '--returntransactions', action='store_true', help='Exports the transaction as csv') parser.add_argument('-st', '--status', action='store_true', help='Exports the transaction as csv') parser.add_argument('-m', '--menu', action='store_true', help='An optional boolean for open the menu.') args = parser.parse_args() if len(sys.argv) < 2: parser.print_help() if args.printwallet: print_wallets() if not args.wallet is None: wallet_selector(args.wallet) if not args.createwallet is None: create_a_wallet(args.createwallet) if args.deletewallet: delete_current_wallet() if args.getbalance: print_balance() if not args.ndnewunl is None: save_new_unl_node(args.ndnewunl) if args.ndid: print(ndid()) if args.testmodeon: test_mode(True) if args.testmodeoff: test_mode(False) if args.debugmodeon: debug_mode(True) if args.debugmodeoff: debug_mode(False) if args.exporttransactioncsv: if export_the_transactions(): print( f"CSV file created in {MY_TRANSACTION_EXPORT_PATH} directory") else: print("You have not a transaction") if args.returntransactions: PrintTransactions() if args.status: print(Status()) if args.menu: menu()
def menu(): """ The main structure of the cli mode, this function prints the menu, listens to the entries, makes the directions. """ while True: show_menu() choices_input = question_maker(mode="main") if choices_input == "connectmainnetwork": connect_to_main_network() if choices_input == "cw": Wallet_Create() if choices_input == "sc": temp_coin_amount = input("Coin Amount (ex. 1.0): ") type_control = False try: float(temp_coin_amount) type_control = True except: print("This is not float coin amount.") if type_control and not float(temp_coin_amount) < GetBlock().minumum_transfer_amount: send_coin(float(temp_coin_amount), input("Please write receiver adress: ")) if choices_input == "gb": print(GetBalance(Wallet_Import(0,0), GetBlock())) print(Wallet_Import(0,3)) if choices_input == "help": show_menu() if choices_input == "ndstart": ndstart(str(input("ip: ")), int(input("port: "))) if choices_input == "ndstop": ndstop() if choices_input == "ndconnect": ndconnect(str(input("node ip: ")), int(input("node port: "))) if choices_input == "ndconnectmixdb": ndconnectmixdb() if choices_input == "ndnewunl": save_new_unl_node(input("Please write ID of the node: ")) if choices_input == "testmodeon": test_mode(True) if choices_input == "testmodeoff": test_mode(False) if choices_input == "debugmodeon": debug_mode(True) # from node.myownp2pn import mynode # mynode.main_node.debug = True if choices_input == "debugmodeoff": debug_mode(False) # from node.myownp2pn import mynode # mynode.main_node.debug = False if choices_input == "getfullnodelist": GetNodeList() if choices_input == "getblock": if the_settings()["test_mode"]: CreateBlock() else: GetBlockFromOtherNode() if choices_input == "0": exit()
def menu(): """ The main structure of the cli mode, this function prints the menu, listens to the entries, makes the directions. """ while True: show_menu() choices_input = question_maker(mode="main") if choices_input == "w": all_wallets = list(get_saved_wallet()) if not len(all_wallets) == 0: current_wallet = the_settings()["wallet"] for wallet in all_wallets: number = str(all_wallets.index(wallet)) address = Wallet_Import(all_wallets.index(wallet),3) if not current_wallet == number: print(menu_maker(menu_number=number, menu_text=address)) else: print(menu_maker(menu_number=number, menu_text=address + " - CURRENTLY USED")) while True: try: new_wallet = input("Please select wallet: ") if int(new_wallet) in list(range(len(all_wallets))): change_wallet(new_wallet) break else: print("There is no such wallet") except: print("This is not a number") else: print("There is no wallet") if choices_input == "connectmainnetwork": connect_to_main_network() if choices_input == "cw": Wallet_Create() if choices_input == "sc": temp_coin_amount = input("Coin Amount (ex. 1.0): ") type_control = False try: float(temp_coin_amount) type_control = True except: print("This is not float coin amount.") if type_control and not float(temp_coin_amount) < GetBlock().minumum_transfer_amount: send_coin(float(temp_coin_amount), input("Please write receiver adress: ")) if choices_input == "gb": print(GetBalance(Wallet_Import(-1,0), GetBlock())) if choices_input == "help": show_menu() if choices_input == "ndstart": ndstart(str(input("ip: ")), int(input("port: "))) if choices_input == "ndstop": ndstop() if choices_input == "ndconnect": ndconnect(str(input("node ip: ")), int(input("node port: "))) if choices_input == "ndconnectmixdb": ndconnectmixdb() if choices_input == "ndnewunl": save_new_unl_node(input("Please write ID of the node: ")) if choices_input == "testmodeon": test_mode(True) if choices_input == "testmodeoff": test_mode(False) if choices_input == "debugmodeon": debug_mode(True) # from node.myownp2pn import mynode # mynode.main_node.debug = True if choices_input == "debugmodeoff": debug_mode(False) # from node.myownp2pn import mynode # mynode.main_node.debug = False if choices_input == "getfullnodelist": GetNodeList() if choices_input == "getblock": if the_settings()["test_mode"]: CreateBlock() else: GetBlockFromOtherNode() if choices_input == "0": exit()
def menu(): while True: show_menu() choices_input = question_maker(mode="main") from lib.settings_system import the_settings if the_settings().test_mode(): if choices_input == "cbl": create_ledger() else: if choices_input == "connectmainnetwork": from func.node_connection import connect_to_main_network connect_to_main_network() if choices_input == "cw": Wallet_Create() if choices_input == "sc": temp_coin_amount = input("Coin Amount (ex. 1.0): ") type_control = False try: float(temp_coin_amount) type_control = True except: print("This is not float coin amount.") if type_control: send_coin(float(temp_coin_amount), input("Please write receiver adress: ")) if choices_input == "gb": print(get_ledger().getBalance(Wallet_Import(0, 0))) if choices_input == "help": show_menu() if choices_input == "ndstart": ndstart(str(input("ip: ")), int(input("port: "))) if choices_input == "ndstop": ndstop() if choices_input == "ndconnect": ndconnect(str(input("node ip: ")), int(input("node port: "))) if choices_input == "ndconnectmixdb": ndconnectmixdb() if choices_input == "ndnewunl": from node.unl import save_new_unl_node save_new_unl_node(input("Please write ID of the node: ")) if choices_input == "testmodeon": the_settings().test_mode(True) if choices_input == "testmodeoff": the_settings().test_mode(False) if choices_input == "debugmodeon": the_settings().debug_mode(True) # from node.myownp2pn import MyOwnPeer2PeerNode # MyOwnPeer2PeerNode.main_node.debug = True if choices_input == "debugmodeoff": the_settings().debug_mode(False) # from node.myownp2pn import MyOwnPeer2PeerNode # MyOwnPeer2PeerNode.main_node.debug = False if choices_input == "getfullnodelist": sendme_full_node_list() if choices_input == "getfullledger": get_ledger_from_other_node() for folder_entry in os.scandir('apps'): if ".md" not in folder_entry.name: for entry in os.scandir("apps/" + folder_entry.name): if entry.is_file(): if entry.name[ 0] != '_' and ".py" in entry.name and "_main" in entry.name: print(entry.name) import_command = f"from apps.{folder_entry.name}.{entry.name.replace('.py','')} import {entry.name.replace('.py','')}_cli_command" tx_command = f"{entry.name.replace('.py','')}_cli_command(choices_input)" exec(import_command) exec(tx_command) if choices_input == "0": exit()
def node_newunl_page(): save_new_unl_node(request.query_string.decode("utf-8")) return jsonify("OK")