metadata.rs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use serde::{Deserialize, Serialize};
  2. use super::{
  3. util::{get_current_time, Timestamp},
  4. vote::Vote,
  5. };
  6. /// This struct represents additional Block information used by the consensus protocol.
  7. #[derive(Debug, Clone, Deserialize, Serialize)]
  8. pub struct Metadata {
  9. /// Block information used by Ouroboros consensus
  10. pub om: OuroborosMetadata,
  11. /// Block information used by Streamlet consensus
  12. pub sm: StreamletMetadata,
  13. /// Block creation timestamp
  14. pub timestamp: Timestamp,
  15. }
  16. impl Metadata {
  17. pub fn new(proof: String, r: String, s: String) -> Metadata {
  18. Metadata {
  19. om: OuroborosMetadata::new(proof, r, s),
  20. sm: StreamletMetadata::new(),
  21. timestamp: get_current_time(),
  22. }
  23. }
  24. }
  25. /// This struct represents Block information used by Ouroboros consensus protocol.
  26. #[derive(Debug, Clone, Deserialize, Serialize)]
  27. pub struct OuroborosMetadata {
  28. /// Proof the stakeholder is the block owner
  29. pub proof: String,
  30. /// Random seed for VRF
  31. pub r: String,
  32. /// Block owner signature
  33. pub s: String,
  34. }
  35. impl OuroborosMetadata {
  36. pub fn new(proof: String, r: String, s: String) -> OuroborosMetadata {
  37. OuroborosMetadata { proof, r, s }
  38. }
  39. }
  40. /// This struct represents Block information used by Streamlet consensus protocol.
  41. #[derive(Debug, Clone, Deserialize, Serialize)]
  42. pub struct StreamletMetadata {
  43. /// Epoch votes
  44. pub votes: Vec<Vote>,
  45. /// Block notarization flag
  46. pub notarized: bool,
  47. /// Block finalization flag
  48. pub finalized: bool,
  49. }
  50. impl StreamletMetadata {
  51. pub fn new() -> StreamletMetadata {
  52. StreamletMetadata { votes: Vec::new(), notarized: false, finalized: false }
  53. }
  54. }