You will build a small blockchain with real SHA-256 hashes and write the check that finds a changed block.
Your tasks.
add_block, make a new block from data. Its prev is the hash of the last block in chain (or "0" * 8 if the chain is empty). Its hash is make_hash(prev, data). Append it to chain.is_valid, return True only if two things hold. Every block's hash equals make_hash of its own prev and data. Every block after the first has a prev equal to the hash of the block before.first_bad to the number (1, 2, 3, ...) of the first block whose stored prev does not match after the change below, using a loop.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…