Skip to content

Instantly share code, notes, and snippets.

@laurentsenta
Last active October 11, 2017 07:39
Show Gist options
  • Save laurentsenta/af4839501520b8c4f8dc2528493243b1 to your computer and use it in GitHub Desktop.
Save laurentsenta/af4839501520b8c4f8dc2528493243b1 to your computer and use it in GitHub Desktop.
SingularGarden - How to implement a Blockchain - Append
# https://github.com/singulargarden/ouroboros/blob/v0.1/ouroboros/blockchain/__init__.py
def prepare_block(root_path, payload):
# Load the current blockchain state
current_descr = load_descr(root_path)
# Create the new block attached to the current head of the chain
current_block_hash = current_descr.head_hash
new_block = make_block(current_block_hash, payload)
# Prepare the new blockchain state
new_descr = update_descr_with_new_head(current_descr, new_block.hash)
return new_descr, new_block
def append(root_path, payload):
"""
Append a new block to our chain using the given payload.
Returns the block to share with others participants.
"""
new_descr, block = prepare_block(root_path, payload)
store_new_block(root_path, new_descr, block) # just write down to disk
return block.hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment