January 2019
Beginner to intermediate
372 pages
11h 17m
English
The Block and Blockchain class methods are similar to those used in the previous chapter to build a simple blockchain, with the only enhancement being the validation methods used to validate the received blocks.
The following method is invoked to verify that every block is linked to its previous block:
def is_valid_new_block(self, new_block, previous_block):
The following condition validates the index of the new block:
if previous_block.index + 1 != new_block.index:
logger.warning('invalid index')
return False
This condition performs hash validation by comparing the hash values of the blocks:
if previous_block.hash != new_block.previous_hash:
logger.warning('invalid previous hash')
return False
This condition ...