def add_block(self, block): transactions = [ Transaction(tx['sender'], tx['recipient'], tx['signature'], tx['amount']) for tx in block['transactions'] ] proof_is_valid = Verification.valid_proof(transactions[:-1], block['previous_hash'], block['proof']) hashes_match = hash_block(self.chain[-1]) == block['previous_hash'] if not proof_is_valid or not hashes_match: return False converted_block = Block(block['index'], block['previous_hash'], transactions, block['proof'], block['timestamp']) self.__chain.append(converted_block) self.save_data() stored_transactions = self.__open_transactions[:] for itx in block['transactions']: for opentx in stored_transactions: if opentx.sender == itx['sender'] and opentx.recipient == itx['recipient'] and\ opentx.amount == itx['amount'] and opentx.signature == itx['signature']: try: self.__open_transactions.remove(opentx) except ValueError: print('Item was already removed') return True
def proof_of_work(): last_block = blockchain[-1] last_hash = hash_block(last_block) proof = 0 verifier = Verification() while not verifier.valid_proof(open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): last_block = self.chain[-1] last_hash = hash_block(last_block) proof = 0 v = Verification() while not v.valid_proof(self.open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): last_block = self.__chain[-1] last_hash = hash_util.hash_block(last_block) proof = 0 while not Verification.valid_proof(self.__open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): """Increment the proof number""" last_block = self.chain[-1] last_hash = hash_block(last_block) proof = 0 verifier = Verification() while not verifier.valid_proof(self.open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): last_block = self.__chain[-1] last_hash = hash_block(last_block) proof = 0 while not Verification.valid_proof(self.__open_transaction, last_hash, proof): proof += 1 # Printing the number of hashes done to check the proof. print(proof) return proof
def proof_of_work(self): """ Initiates the proof of work function to allow mining """ last_block = self.__chain[-1] last_hash = hash_block(last_block) proof = 0 while not Verification.valid_proof(self.__open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): """Generate a proof of work for the open transactions, the hash of the previous block and a random number (which is guessed until it fits).""" last_block = self.__chain[-1] last_hash = hash_block(last_block) proof = 0 # Try different PoW numbers and return the first valid one while not Verification.valid_proof(self.__open_transactions, last_hash, proof): proof += 1 return proof
def proof_of_work(self): last_block = self.blockchain[-1] last_hash = hash_block(last_block) proof = 0 counter = 0 while not Verification.valid_proof(self.__open_transactions, last_hash, proof): proof += 1 counter += 1 print(counter) return proof