|
@@ -1,18 +1,14 @@
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde::{Deserialize, Serialize};
|
|
|
-use std::io;
|
|
|
|
|
|
|
|
|
|
use super::{
|
|
use super::{
|
|
|
util::{get_current_time, Timestamp},
|
|
util::{get_current_time, Timestamp},
|
|
|
vote::Vote,
|
|
vote::Vote,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-use crate::{
|
|
|
|
|
- util::serial::{Decodable, Encodable},
|
|
|
|
|
- Result,
|
|
|
|
|
-};
|
|
|
|
|
|
|
+use crate::util::serial::{SerialDecodable, SerialEncodable};
|
|
|
|
|
|
|
|
/// This struct represents additional Block information used by the consensus protocol.
|
|
/// This struct represents additional Block information used by the consensus protocol.
|
|
|
-#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
|
|
|
|
|
+#[derive(Debug, Clone, Deserialize, Serialize, SerialEncodable, SerialDecodable)]
|
|
|
pub struct Metadata {
|
|
pub struct Metadata {
|
|
|
/// Block information used by Ouroboros consensus
|
|
/// Block information used by Ouroboros consensus
|
|
|
pub om: OuroborosMetadata,
|
|
pub om: OuroborosMetadata,
|
|
@@ -32,27 +28,8 @@ impl Metadata {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-impl Encodable for Metadata {
|
|
|
|
|
- fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
|
|
|
|
- let mut len = 0;
|
|
|
|
|
- len += self.om.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.sm.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.timestamp.encode(&mut s).unwrap();
|
|
|
|
|
- Ok(len)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-impl Decodable for Metadata {
|
|
|
|
|
- fn decode<D: io::Read>(mut d: D) -> Result<Self> {
|
|
|
|
|
- let om = Decodable::decode(&mut d)?;
|
|
|
|
|
- let sm = Decodable::decode(&mut d)?;
|
|
|
|
|
- let timestamp = Decodable::decode(&mut d)?;
|
|
|
|
|
- Ok(Self { om, sm, timestamp })
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/// This struct represents Block information used by Ouroboros consensus protocol.
|
|
/// This struct represents Block information used by Ouroboros consensus protocol.
|
|
|
-#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
|
|
|
|
|
+#[derive(Debug, Clone, Deserialize, Serialize, SerialEncodable, SerialDecodable)]
|
|
|
pub struct OuroborosMetadata {
|
|
pub struct OuroborosMetadata {
|
|
|
/// Proof the stakeholder is the block owner
|
|
/// Proof the stakeholder is the block owner
|
|
|
pub proof: String,
|
|
pub proof: String,
|
|
@@ -68,27 +45,8 @@ impl OuroborosMetadata {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-impl Encodable for OuroborosMetadata {
|
|
|
|
|
- fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
|
|
|
|
- let mut len = 0;
|
|
|
|
|
- len += self.proof.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.r.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.s.encode(&mut s).unwrap();
|
|
|
|
|
- Ok(len)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-impl Decodable for OuroborosMetadata {
|
|
|
|
|
- fn decode<D: io::Read>(mut d: D) -> Result<Self> {
|
|
|
|
|
- let proof = Decodable::decode(&mut d)?;
|
|
|
|
|
- let r = Decodable::decode(&mut d)?;
|
|
|
|
|
- let s = Decodable::decode(&mut d)?;
|
|
|
|
|
- Ok(Self { proof, r, s })
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/// This struct represents Block information used by Streamlet consensus protocol.
|
|
/// This struct represents Block information used by Streamlet consensus protocol.
|
|
|
-#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
|
|
|
|
|
+#[derive(Debug, Clone, Deserialize, Serialize, SerialEncodable, SerialDecodable)]
|
|
|
pub struct StreamletMetadata {
|
|
pub struct StreamletMetadata {
|
|
|
/// Epoch votes
|
|
/// Epoch votes
|
|
|
pub votes: Vec<Vote>,
|
|
pub votes: Vec<Vote>,
|
|
@@ -103,22 +61,3 @@ impl StreamletMetadata {
|
|
|
StreamletMetadata { votes: Vec::new(), notarized: false, finalized: false }
|
|
StreamletMetadata { votes: Vec::new(), notarized: false, finalized: false }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-impl Encodable for StreamletMetadata {
|
|
|
|
|
- fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
|
|
|
|
- let mut len = 0;
|
|
|
|
|
- len += self.votes.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.notarized.encode(&mut s).unwrap();
|
|
|
|
|
- len += self.finalized.encode(&mut s).unwrap();
|
|
|
|
|
- Ok(len)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-impl Decodable for StreamletMetadata {
|
|
|
|
|
- fn decode<D: io::Read>(mut d: D) -> Result<Self> {
|
|
|
|
|
- let votes = Decodable::decode(&mut d)?;
|
|
|
|
|
- let notarized = Decodable::decode(&mut d)?;
|
|
|
|
|
- let finalized = Decodable::decode(&mut d)?;
|
|
|
|
|
- Ok(Self { votes, notarized, finalized })
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|