Skip to content

Instantly share code, notes, and snippets.

@cx0der
Created August 12, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cx0der/ad4bff9042bc82acd27c10fb61016bc9 to your computer and use it in GitHub Desktop.
Save cx0der/ad4bff9042bc82acd27c10fb61016bc9 to your computer and use it in GitHub Desktop.
Authenticate the Block
def is_block_valid(next_block, last_block):
if last_block.index + 1 != int(new_block["index"]):
return False
if last_block.hash != new_block["prev_hash"]:
return False
block_val = str(new_block["index"]) + str(new_block["nonce"]) + new_block["prev_hash"] + \
str(new_block["timestamp"]) + new_block["data"]
if calculate_hash(block_val) != new_block["hash"]:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment