A blockchain written in Python 3.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_chain.py 614B

1234567891011121314151617181920
  1. import os, time
  2. from block import Block
  3. from blockchain import Blockchain
  4. if not os.path.exists("blocks"):
  5. os.makedirs("blocks")
  6. testBlockchain = Blockchain(4, 42)
  7. for i in range(100):
  8. block = Block(len(testBlockchain.chain), time.ctime())
  9. print("".join(["[Info] Mining block ", str(block.index), " with difficulty ", str(testBlockchain.difficulty), "... "]))
  10. testBlockchain.addBlock(block)
  11. if testBlockchain.isValid():
  12. print("\n[Info] Is blockchain valid? ", str(testBlockchain.isValid()))
  13. else:
  14. print("\n[Error] Is blockchain valid? ",str(testBlockchain.isValid()))