def __init__(self,place_id,choices): self.place_id = place_id self.choices = choices self.len_choices = len(self.choices) self.kernel = BlockChain(self.place_id) os.system('cls') p("Election Procedure Started!",'red') self.list_keys = [key for key in self.choices]
def safeModeOn(database, table): try: for db in databases: #verifica si la base de datos existe if db.get("name") == database: for tb in db.get("tables"): #verifica si la tabla existe if tb.get("name") == table: #verifica si el modo seguro esta activado if tb.get("safeMode"): #Modo seguro existente return 4 tb["safeMode"] = True #_________________________________________________________ bc = BlockChain(str(database) + "_" + str(table)) for tp in tb.get("tuples"): bc.addNode(tp.get("register")) bc.generateJsonSafeMode() listBlockChain.append(bc) #_________________________________________________________ #tabel inexistente return 3 #database inexistente return 2 except: #Error en la operación return 1
class Election: def __init__(self,place_id,choices): self.place_id = place_id self.choices = choices self.len_choices = len(self.choices) self.kernel = BlockChain(self.place_id) os.system('cls') p("Election Procedure Started!",'red') self.list_keys = [key for key in self.choices] def show_choices(self): os.system('cls') for key in self.choices: strx = key + " - " + self.choices[key] p(strx) def vote(self,voter_data): if(voter_data != None): strx = json.dumps(voter_data) self.kernel.insert(strx) else: p("Enter Valid Details!",'red') def export_logs(self,filename): data = self.kernel.export_chain() fw = open(filename,'w') fw.write(data) fw.close() def construct(self,voter_data,choice): if(choice in self.list_keys): data = { 'id':voter_data, 'choice':choice, 'cand':self.choices[choice] } return data
from BlockChain.BlockChain import BlockChain import time DATA_FILE_NAME = "ExampleFile.txt" OUT_FILE_NAME = "EncryptedBlockChain.txt" raw_data = open(DATA_FILE_NAME,'r').read() kernel = BlockChain(0xFF) total_len = len(raw_data) last_time = time.time() for i in range(total_len): perc = 100*(i+1)/total_len try: rate = 1/(time.time()-last_time) except ZeroDivisionError: rate = 0xFF # No idea how to handle this ! last_time = time.time() eta = (total_len - i -1)/rate status = "Percentage : {:3.3f} % -> Rate : {:4.2f} BlocksPerSecond -> ETA : {:.2f} Seconds ".format(perc,rate,eta) print(status) kernel.insert(raw_data[i]) print("Exported Data Sucessfully!") enc_data = kernel.export_chain() open(OUT_FILE_NAME,'w').write(enc_data)