def Get_Current_Ledger_Addresses(self): self.Current_Addresses = Dynamic_Public_Ledger().Check_User_In_Ledger( Current_Ledger=True).Ledger_Accounts #Output = Current addresses within the ledger pool (list) self.BlockNumber = Dynamic_Public_Ledger().Calculate_Block().Block #Output = Current block number since genesis (int) return self
def Get_Current_Address_From_PublicKey(self, PublicKey): List = Dynamic_Public_Ledger().Check_User_In_Ledger( Current_Ledger=True).Ledger_Accounts for i in List: if i[1] == PublicKey: Current_Address = i[0] else: Current_Address = None return Current_Address
def Catch_Up(self): self.Build_LedgerDB() Accounts = self.Read_From_Json(directory=self.Ledger_Accounts_Dir) if self.Last_Block_Online != self.Current_Block: self.Write_To_Json( directory=str(self.UserFolder + "/" + self.PathFolder + "/" + self.Current_Ledger_Accounts), Dictionary={}) self.Write_To_Json(directory=self.TrustedNodes_Dir, Dictionary={}) self.Write_To_Json(directory=self.Ping_Dir, Dictionary={}) self.Last_Block_Online = self.Last_Block_Online - 1 BlockDifference = int(self.Current_Block - self.Last_Block_Online) if BlockDifference >= self.Replay: Upperbound_Block = self.Last_Block_Online + self.Replay Sync = "Syncing node." else: Upperbound_Block = self.Last_Block_Online + BlockDifference if BlockDifference == 1: Sync = "Node synced." else: Sync = "Syncing node." for i in Dynamic_Public_Ledger().Check_User_In_Ledger( ScanAll=True, From=self.Last_Block_Online, To=Upperbound_Block).All_Accounts: Accounts = self.Add_To_Dictionary(Input_Dictionary=Accounts, Entry_Label=i[0], Entry_Value=i[1]) self.Write_To_Json(directory=self.Ledger_Accounts_Dir, Dictionary=Accounts) Inbox_Manager().Read_Tangle(IOTA_Instance=self.PrivateIOTA, From=self.Last_Block_Online - 2, To=Upperbound_Block) self.Write_To_Json(directory=self.Last_Block_Dir, Dictionary=self.Add_To_Dictionary( Input_Dictionary={}, Entry_Label="Block", Entry_Value=Upperbound_Block)) self.Output = str("Scanning from: " + str(self.Last_Block_Online) + " To: " + str(Upperbound_Block) + " Status: " + Sync) self.Last_Block_Online = Upperbound_Block if self.Current_Block == self.Last_Block_Online: Inbox_Manager().Read_Tangle(IOTA_Instance=self.PrivateIOTA, Block=self.Current_Block) return self
def __init__(self): Tools.__init__(self) Configuration.__init__(self) User_Profile.__init__(self) self.Ledger_Accounts_Dir = str(self.UserFolder + "/" + self.PathFolder + "/" + self.Ledger_Accounts_File) self.Last_Block_Dir = str(self.UserFolder + "/" + self.PathFolder + "/" + self.Last_Block) self.Ping_Dir = str(self.UserFolder + "/" + self.PathFolder + "/" + self.Trajectory_Ping) self.Incoming_Shrapnells = str(self.UserFolder + "/" + self.MessageFolder + "/" + Configuration().ReceivedMessages + "/" + Configuration().ReceivedMessages + ".txt") self.TrustedNodes_Dir = str(self.UserFolder + "/" + self.PathFolder + "/" + self.Trusted_Nodes) self.Current_Block = Dynamic_Public_Ledger().Calculate_Block().Block self.PrivateIOTA = IOTA_Module(Seed=self.Private_Seed)
def Link_Address_To_PubKey(self, Address_To_Search="0" * 81, Public_Key_To_Search="", User_Name=""): All_Ledger_DB = Dynamic_Public_Ledger().Check_User_In_Ledger( ScanAll=True).All_Accounts self.Public_Key_Found = "0" * 81 self.Other_Identities = [] self.Saved = False if isinstance(All_Ledger_DB, list) == True: if Address_To_Search != "0" * 81: for i in All_Ledger_DB: Address = i[0] PubKey = i[1] if Address == Address_To_Search: self.Public_Key_Found = PubKey elif Public_Key_To_Search != "": self.Public_Key_Found = Public_Key_To_Search Temp_List = [] for i in All_Ledger_DB: if i[1] == self.Public_Key_Found: Temp_List.append(i[0]) self.Other_Identities = [self.Public_Key_Found, Temp_List] if User_Name != "": Contact_List = self.Read_From_Json( directory=self.Contacts_File_Dir) if self.Label_In_Dictionary(Input_Dictionary=Contact_List, Label=User_Name) == False: Contact_List = self.Add_To_Dictionary( Input_Dictionary=Contact_List, Entry_Label=User_Name, Entry_Value=str(self.Other_Identities)) self.Write_To_Json(directory=self.Contacts_File_Dir, Dictionary=Contact_List) self.Saved = True return self
def Reconstruction_Of_Message(self, Verify): #Make sure there is a file: self.Create_DB() #Read the file Client_Dictionary = self.Read_From_Json(directory=self.Received_Dir) Unique_SymKeys = [] for i in Client_Dictionary.values(): Unique_SymKeys.append(i) Unique_SymKeys = set(Unique_SymKeys) Message = [] for i in Unique_SymKeys: Pieces_From_SymKey = [] Unmodified_Labels = [] for Cipher, Symkey in Client_Dictionary.items(): if i == Symkey: Pieces_From_SymKey.append( str(Cipher).replace(Configuration().MessageIdentifier, '')) Unmodified_Labels.append(str(Cipher)) Sym_Key = self.Base64_To_String(str(i)) Format_To_Digest = [Pieces_From_SymKey, Sym_Key] Output = Dynamic_Public_Ledger().Rebuild_Shrapnells( String=Format_To_Digest, Verify=Verify) if isinstance(Output, list): Message.append(Output) for z in Unmodified_Labels: Client_Dictionary = self.Remove_From_Dictionary( Input_Dictionary=Client_Dictionary, Label=z) self.Write_To_Json(directory=self.Received_Dir, Dictionary=Client_Dictionary) self.Completed_Messages(Input=Message) if len(Message) == 0: return [[False, False, False]] else: return Message
def Completed_Messages(self, Input=[]): #Add the message input later #First create the inbox DB self.Build_DB(File=self.Message_Inbox) Inbox = self.Read_From_Json(directory=self.Message_Inbox) Current_TangleTime = Dynamic_Public_Ledger( ).PublicIOTA.LatestTangleTime().TangleTime for i in Input: From_Address = i[0] try: hex = i[1].split(self.Identifier) int(hex, 16) Ping = True except: Message = self.String_To_Base64(String=i[1]) Ping = False if Ping == False: Inbox = self.Add_To_Dictionary(Input_Dictionary=Inbox, Entry_Label=Message, Entry_Value=From_Address) print("New Message!!!\n") self.Write_To_Json(directory=self.Message_Inbox, Dictionary=Inbox) return self
def Update_Contacts(self): for i in Dynamic_Public_Ledger().Check_User_In_Ledger( ScanAll=True).All_Accounts: Address = i[0] self.Retrieve_UserName_From_Address(Address_To_Search=Address) return self
def Get_Current_Address(self): self.Current_Address = Dynamic_Public_Ledger( ).PrivateIOTA.Generate_Address( Index=Dynamic_Public_Ledger().Calculate_Block().Block) #Output = Address of client at current block height (String) return self
def run(self): if self.Function == "Dynamic_Public_Ledger": while self.RunTime: try: x = Dynamic_Public_Ledger() x.Start_Ledger() if x.ChangeBlock == True: delay = 10 elif x.ChangeBlock == False: delay = 20 self.Echo = str(x.Calculate_Block().Block) HayStack().Refresh_Contact_List() except IOError: HayStack().Build_All_Directories() delay = 30 for i in range(delay): sleep(1) if self.RunTime == False: print("Shutting down Dynamic Public Ledger...\n") break print("Dynamic Public Ledger... Offline\n") elif self.Function == "Sync_Messanger": while self.RunTime: x = Trusted_Paths() try: x.Catch_Up() self.Echo = x.Output x.Scan_Paths() except IOError: HayStack().Build_All_Directories() print("Error") except: print("\nLikely BadApi error. Ignore this.\n") try: HayStack().Inbox() for i in range(10): sleep(1) if self.RunTime == False: config.RunTime = False print("Shutting down Messanger client...\n") break except KeyError: print("Error with Sync") print("Messanger client... Offline\n") elif self.Function == "Ping_Function": while self.RunTime: delay = random.randint(120, 999) for i in range(delay): sleep(1) if self.RunTime == False: print("Shutting down ping function...") break if self.RunTime == True: try: HayStack().Ping_Function() print("\nPing has been sent.\n") except IndexError: print("\nPing Error...\n") print("Ping function... Offline") return self
def run(self): if self.Function == "Dynamic_Public_Ledger": delay = 30 print("Please wait whilst HayStack searches for nodes.") while self.RunTime: for i in range(delay): sleep(1) if self.RunTime == False: print("Shutting down Dynamic Public Ledger...\n") break try: x = Dynamic_Public_Ledger() x.Start_Ledger() if x.ChangeBlock == True: delay = 10 elif x.ChangeBlock == False: delay = 20 self.Echo = str(x.Calculate_Block().Block) HayStack().Refresh_Contact_List() except IOError: try: HayStack().Build_All_Directories() delay = 30 except: print("Connection Error. You are not online") delay = 30 except: if "BadApiResponse: 400 response from node:" in str( sys.exc_info()[0]): print("Your IOTA node is not in sync.") print("Dynamic Public Ledger... Offline\n") elif self.Function == "Sync_Messanger": delay = 30 while self.RunTime: for i in range(delay): sleep(1) if self.RunTime == False: config.RunTime = False print("Shutting down Messanger client...\n") break try: x = Trusted_Paths() x.Catch_Up() self.Echo = x.Output x.Scan_Paths() except IOError: try: HayStack().Build_All_Directories() except: if "ConnectionError: HTTPConnectionPool" in str( sys.exc_info()[0]): print("Connection Error. You are not online") except: pass try: HayStack().Inbox() except KeyError: print("Error with Sync") except: if "ConnectionError: HTTPConnectionPool" in str( sys.exc_info()[0]): print("Connection Error. You are not online") delay = 10 print("Messanger client... Offline\n") elif self.Function == "Ping_Function": while self.RunTime: delay = random.randint(120, 999) for i in range(delay): sleep(1) if self.RunTime == False: print("Shutting down ping function...") break if self.RunTime == True: try: HayStack().Ping_Function() print("\nPing has been sent.\n") except IndexError: print("\nPing Error...\n") except: pass print("Ping function... Offline") elif self.Function == "Node_Testing": while self.RunTime == True: Node_Finder().Test_Nodes() for i in range(30): if self.RunTime == False: print("Shutting down node finder...") break else: sleep(1) print("Node finder... Offline...") return self