Created
August 12, 2018 15:23
-
-
Save cx0der/ad4bff9042bc82acd27c10fb61016bc9 to your computer and use it in GitHub Desktop.
Authenticate the Block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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