mining_strategy.py 483 B

12345678910111213
  1. from block import Block
  2. from datetime import datetime
  3. from merkle import merkle_tree
  4. def create_block(blockchain, unconfirmed_transactions):
  5. """
  6. Creates a new block that can be mined.
  7. """
  8. tree = merkle_tree(unconfirmed_transactions)
  9. head = blockchain.head
  10. difficulty = blockchain.compute_difficulty()
  11. return Block(None, head.hash, datetime.now(), 0, head.height + difficulty,
  12. None, difficulty, tree.get_hash(), unconfirmed_transactions)