block.py 899 B

12345678910111213141516171819202122
  1. class Block:
  2. ''' This class represents a tuple of the form (h, e, txs).
  3. Each blocks parent hash h may be computed simply as a hash of the parent block. '''
  4. def __init__(self, h, e, txs):
  5. self.h = h # parent hash
  6. self.e = e # epoch number
  7. self.txs = txs # transactions payload
  8. self.votes = [] # Epoch votes
  9. self.notarized = False # block notarization flag
  10. self.finalized = False # block finalization flag
  11. def __repr__(self):
  12. return "Block=[h={0}, e={1}, txs={2}, notarized={3}, finalized={4}]".format(self.h, self.e, self.txs, self.notarized, self.finalized)
  13. def __hash__(self):
  14. return hash((self.h, self.e, str(self.txs))) # python hash is used for demostranation porpuses only.
  15. def __eq__(self, other):
  16. return self.h == other.h and self.e == other.e and self.txs == other.txs
  17. def encode(self):
  18. return(("{0},{1},{2}".format(self.h, self.e, self.txs)).encode())