mistake ex3

This commit is contained in:
“Spekulaas” 2023-09-22 15:57:57 +02:00
parent e3e587a74e
commit 3a411c2819

View File

@ -63,6 +63,12 @@ class CBlock:
# Make sure to compute the hash value of the current block and store it properly
def mine(self, leading_zeros):
self.nonce = 0
if self.previousBlock:
self.previousHash = self.previousBlock.blockHash
else:
self.previousHash = None
while True:
digest = self.computeHash()
@ -72,15 +78,23 @@ class CBlock:
break
self.nonce += 1
# TODO 4: Check if the current block contains valid hash digest values
# Make sure to distinguish between the genesis block and other blocks
# Make sure to compare both hash digest values:
# The computed digest of the current block
# The stored digest of the previous block
# return the result of all comparisons as a boolean value
# def is_valid_hash(self):
# if(self.previousBlock == None):
# return True
# if(self.computeHash() != self.blockHash or self.previousBlock.blockHash != self.previousBlock.computeHash()):
# return False
# return self.previousBlock.is_valid_hash()
def is_valid_hash(self):
if self.previousBlock == None:
return True
if self.previousBlock:
self.previousHash = self.previousBlock.computeHash()
return self.computeHash() == self.blockHash