January 2019
Beginner to intermediate
372 pages
11h 17m
English
Let's consider a simple block whose header and data are combined to create a data structure called Block. Each Block will contain the following: an index, the previous hash, a timestamp, data, and its own hash value:
class Block(object):
"""A class representing the block for the blockchain"""
def __init__(self, index, previous_hash, timestamp, data, hash):
self.index = index
self.previous_hash = previous_hash
self.timestamp = timestamp
self.data = data
self.hash = hash
The preceding code snippet defines a Python class called Block that has all the basic attributes of a blockchain block. Usually, a block will contain both a header and a body, with the header containing metadata about the block. However, the preceding example ...