def write_default_blockchain() -> str: """Returns the string representation of the default Blockchain data.""" genesis_block = Block() genesis_block.data = "This is the sickest Blockchain implementation ever." genesis_block.timestamp = time.time() genesis_block.previous_hash = "" # Create a temporary chain which we can convert to JSON. default_chain = Blockchain([]) default_chain.blocks.append(genesis_block) save_chain(default_chain) return default_chain.to_json()
def save_chain(chain: Blockchain, location: str = "chain_data.json") -> bool: """ Returns a bool indicating whether or not the data was saved. Parameters: chain -- the Blockchain to write to the file. location -- the path to the file in which the data will be written. """ try: with open(location, "w") as chain_data_h: chain_data_h.write(chain.to_json()) return True except: return False