diff --git a/simpleCoin/miner.py b/simpleCoin/miner.py index 3532eaa..491b925 100644 --- a/simpleCoin/miner.py +++ b/simpleCoin/miner.py @@ -174,9 +174,14 @@ def consensus(blockchain): def validate_blockchain(block): - """Validate the submitted chain. If hashes are not correct, return false + """Validate the submitted chain. If hashes are not correct, return False block(str): json """ + + for i in range(len(block)-1): + if not block[i].hash_block() == block[i+1].previous_hash: + return False + return True diff --git a/simpleCoin/wallet.py b/simpleCoin/wallet.py index 859ba03..530530e 100644 --- a/simpleCoin/wallet.py +++ b/simpleCoin/wallet.py @@ -22,6 +22,7 @@ import time import base64 import ecdsa +import json def wallet(): @@ -92,11 +93,11 @@ def check_transactions(): """ try: res = requests.get('http://localhost:5000/blocks') - print(res.text) + print(json.dumps(res.json(),indent=2)) except requests.ConnectionError: print('Connection error. Make sure that you have run miner.py in another terminal.') - + def generate_ECDSA_keys(): """This function takes care of creating your private and public (your address) keys.