January 2019
Beginner to intermediate
372 pages
11h 17m
English
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): ...