January 2019
Beginner to intermediate
372 pages
11h 17m
English
Now that we have defined all the required functionalities of a simple blockchain linker, we'll emulate one by creating both a few blocks and a blockchain:
new_chain = Blockchain() new_chain.add_block(data="first block data") new_chain.add_block(data="second block data") new_chain.add_block(data="third block data") print(json.dumps(new_chain.chain)) new_chain.reset() new_chain.add_block(data="first block data") new_chain.add_block(data="second block data") new_chain.add_block(data="third block data") print(json.dumps(new_chain.chain))
The preceding code snippet creates a Blockchain object and adds three blocks to it, along with an existing genesis block. This operation is performed again after resetting the blockchain. ...