def get_blockchain(): blockchain = Blockchain() blockchain_db = Table("blockchain", "number", "nonce", "hash_previous", "hash_current", "data") for block_db in blockchain_db.getall(): blockchain.add_block(Block(int(block_db.get('number')), int(block_db.get('nonce')), block_db.get('hash_previous'), block_db.get('data'))) return blockchain
def create_chain_from_dump(chain_dump): generated_blockchain = Blockchain() generated_blockchain.create_genesis_block() for idx, block_data in enumerate(chain_dump): if idx == 0: continue # skip genesis block block = Block(block_data["index"], block_data["transactions"], block_data["timestamp"], block_data["previous_hash"], block_data["nonce"]) proof = block_data['hash'] added = generated_blockchain.add_block(block, proof) if not added: raise Exception("The chain dump is tampered!!") return generated_blockchain