Skip to Content
Foundations of Blockchain
book

Foundations of Blockchain

by Koshik Raj
January 2019
Beginner to intermediate
372 pages
11h 17m
English
Packt Publishing
Content preview from Foundations of Blockchain

Block and blockchain interface

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Blockchain Basics

Blockchain Basics

Daniel Drescher
What Is Blockchain?

What Is Blockchain?

Sir John Hargrave, Evan Karnoupakis
Mastering Blockchain

Mastering Blockchain

Lorne Lantz, Daniel Cawrey

Publisher Resources

ISBN: 9781789139396Supplemental Content