block.rs 984 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. use std::hash::{Hash, Hasher};
  2. use super::vote::Vote;
  3. /// This struct represents a tuple of the form (h, e, txs).
  4. /// Each blocks parent hash h may be computed simply as a hash of the parent block.
  5. #[derive(Debug, Clone)]
  6. pub struct Block {
  7. /// parent hash
  8. pub h: String,
  9. /// epoch number
  10. pub e: i64,
  11. /// transactions payload
  12. pub txs: Vec<String>,
  13. /// Epoch votes
  14. pub votes: Vec<Vote>,
  15. /// block notarization flag
  16. pub notarized: bool,
  17. /// block finalization flag
  18. pub finalized: bool,
  19. }
  20. impl Block {
  21. pub fn new(h: String, e: i64, txs: Vec<String>) -> Block {
  22. Block { h, e, txs, votes: Vec::new(), notarized: false, finalized: false }
  23. }
  24. }
  25. impl PartialEq for Block {
  26. fn eq(&self, other: &Self) -> bool {
  27. self.h == other.h && self.e == other.e && self.txs == other.txs
  28. }
  29. }
  30. impl Hash for Block {
  31. fn hash<H: Hasher>(&self, hasher: &mut H) {
  32. (&self.h, &self.e, &self.txs).hash(hasher);
  33. }
  34. }