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

Blockchain functionality

The block linking process consists of several elements, such as creating a structure from the information, calculating the hash of the block, and appending it to the blockchain.

Let's break down each of these functionalities into blockchain methods:

class Blockchain(object): 
    """A class representing list of blocks""" 
 
    def __init__(self): 
 
        self._chain = [self.get_genesis_block()] 
        self.timestamp = int(datetime.now().timestamp()

The preceding class is a collection of class methods that create a valid blockchain using a hash function. The constructor of the Blockchain will initialize a chain by appending a genesis block, which is the first block of the blockchain, and doesn't have any reference to a previous block:

def get_genesis_block(self): ...
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