vote.rs 863 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use std::io;
  2. use super::block::BlockProposal;
  3. use crate::{
  4. crypto::{keypair::PublicKey, schnorr::Signature},
  5. impl_vec, net,
  6. util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable, VarInt},
  7. Result,
  8. };
  9. /// This struct represents a tuple of the form (vote, B, id).
  10. #[derive(Debug, Clone, PartialEq, SerialDecodable, SerialEncodable)]
  11. pub struct Vote {
  12. /// Node public key
  13. pub node_public_key: PublicKey,
  14. /// signed block
  15. pub vote: Signature,
  16. /// block proposal to vote on
  17. pub block: BlockProposal,
  18. /// node id
  19. pub id: u64,
  20. }
  21. impl Vote {
  22. pub fn new(node_public_key: PublicKey, vote: Signature, block: BlockProposal, id: u64) -> Vote {
  23. Vote { node_public_key, vote, block, id }
  24. }
  25. }
  26. impl net::Message for Vote {
  27. fn name() -> &'static str {
  28. "vote"
  29. }
  30. }
  31. impl_vec!(Vote);