Skip to content

Instantly share code, notes, and snippets.

@laurentsenta
Created October 9, 2017 09:43
Show Gist options
  • Save laurentsenta/48da3faa338fcb411c69e0cbbd1db6ee to your computer and use it in GitHub Desktop.
Save laurentsenta/48da3faa338fcb411c69e0cbbd1db6ee to your computer and use it in GitHub Desktop.
SingularGarden - How to implement a Blockchain - Add
# https://github.com/singulargarden/ouroboros/blob/v0.1/ouroboros/blockchain/__init__.py
def add(root_path, proposed_block_hash, payload):
"""
Make sure we agree on the proposed hash add the block to our chain.
Use this when a block comes from an external source.
"""
new_descr, block = prepare_block(root_path, payload)
# Identical to append but we verify the hash!
if block.hash != proposed_block_hash:
raise HashDoNotMatchException()
store_new_block(root_path, new_descr, block)
return block.hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment