importa hashlib importa numpy as np importa classe casuale Blocco: def init(self, indice, timestamp, dati, previous_hash): self.index = indice self.timestamp = timestamp self.data = dati self.previous_hash = previous_hash self.hash = self .calculate_hash() def calcola_hash(self): block_string = json.dumps(self.__dict__, sort_keys=True) return hashlib.sha256(block_string.encode()).hexdigest() class Blockchain: def init(self): self. chain = [] def add_block(self, data): indice = len(self.chain) + 1 timestamp = time.time() if indice > 1: previous_hash = self.chain[-1].hash else: previous_hash = " 0" * 64 blocco = Blocco(indice, timestamp, dati, hash_precedente) self.chain.append(blocco) def validate_chain(self): for i in range(1, len(self.chain)): current_block = self.chain [i] blocco_precedente = self.chain[i-1] if blocco_corrente.hash_precedente != blocco_precedente.hash: return False if blocco_corrente.hash != blocco_corrente.calculate_hash(): return False return True class Node: def init(self, id , blockchain): self.id = id self.blockchain = blockchain self.connections = [] def connect_to_node(


class Nodo: def init(self, id, blockchain): self.id = id self.blockchain = blockchain self.connections = [] def connect_to_node(self, nodo): self.connections.append(node) def broadcast(self, messaggio): for nodo in self.connections: node.receive(messaggio) def ricezione(self, messaggio): # Elabora il passaggio del messaggio ricevuto

#BNBAnalysis >#binance >#BinanceBlockchainWeek