1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use super::*;
use raw::RawCommit;
use simperby_network::Error;
use simperby_network::*;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct PayloadCommit {
    pub commit: RawCommit,
    pub hash: CommitHash,
    pub parent_hash: CommitHash,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum BranchType {
    Agenda,
    AgendaProof,
    Block,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct PayloadBranch {
    pub branch_type: BranchType,
    /// The list of commit hashes in the branch, starting from
    /// **the next commit** of the `finalized` commit.
    pub commit_hashes: Vec<CommitHash>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Message {
    Commit(PayloadCommit),
    Branch(PayloadBranch),
}

impl ToHash256 for Message {
    fn to_hash256(&self) -> Hash256 {
        Hash256::hash(serde_spb::to_vec(self).unwrap())
    }
}

impl DmsMessage for Message {
    fn check(&self) -> Result<(), Error> {
        Ok(())
    }
}

pub async fn flush(
    _raw: Arc<RwLock<RawRepository>>,
    _dms: Arc<RwLock<Dms<Message>>>,
) -> Result<(), Error> {
    todo!()
}

/// Updates the repository module with the latest messages from the DMS.
///
/// Note that it never finalizes a block.
/// Finalization is done by the consensus module, or the `sync` method.
pub async fn update(
    _raw: Arc<RwLock<RawRepository>>,
    _dms: Arc<RwLock<Dms<Message>>>,
) -> Result<(), Error> {
    todo!()
}