def miningBlock(self, higher): stringOfZeros = "0" * int(self.POW) d = Date() block = NodeMemory._get_new_hash(self, higher, self.POW, d.get_date(), '') # while stringHash not found if block[1].startswith(stringOfZeros): # On affiche un message print('New block mined with hash ' + block[2] + '\n' + block[0] + '\n') # Retourne l'ID du bloc miné return block[2] return False
def miningBlock(self): higher = Node.getHigherBlock(self) if higher != False: stringOfZeros = "0" * int(self.POW) d = Date() transactions = self.pendingTransactions.listValidTrans( self.accounts) block = Node._get_new_hash(self, higher, self.POW, d.get_date(), ' '.join(transactions)) # while stringHash not found if block[1].startswith(stringOfZeros): # On valide les transactions for t in transactions: # Copié la transaction depuis celles en attente vers celles valides current = self.pendingTransactions.readTrans(t) self.pendingTransactions.transDelete(t) self.transactions.writeTrans(current['from'], current['to'], current['amount'], current['fees']) # Met à jour les comptes self.accounts.modify_account( current['from'], self.accounts.get_account_amount(current['from']) - float(current['amount']) - float(current['fees'])) self.accounts.modify_account( current['to'], self.accounts.get_account_amount(current['to']) + float(current['amount'])) # On crée le bloc self.blocks.writeBlockFromString(block[0], block[2]) # On affiche un message print('\nNew block mined with hash ' + block[2] + '\n' + block[0] + '\n') return True return False