mithril_common/signable_builder/
interface.rs

1use async_trait::async_trait;
2use std::fmt::Debug;
3
4use crate::{
5    entities::{
6        BlockNumber, CardanoDatabaseSnapshot, CardanoDbBeacon, CardanoStakeDistribution,
7        CardanoTransactionsSnapshot, Epoch, MithrilStakeDistribution, ProtocolMessage,
8        ProtocolMessagePartValue, Snapshot,
9    },
10    StdResult,
11};
12
13#[cfg(test)]
14use mockall::automock;
15
16/// Beacon trait
17pub trait Beacon: Send + Sync {}
18
19/// Artifact is a trait for types that represent signed artifacts
20#[cfg_attr(not(target_family = "wasm"), typetag::serde(tag = "type"))]
21pub trait Artifact: Debug + Send + Sync {
22    /// Get artifact identifier
23    fn get_id(&self) -> String;
24}
25
26/// SignableBuilder is a trait for building a protocol message for a beacon
27#[cfg_attr(test, automock)]
28#[async_trait]
29pub trait SignableBuilder<U>: Send + Sync
30where
31    U: Beacon,
32{
33    /// Compute a protocol message
34    async fn compute_protocol_message(&self, beacon: U) -> StdResult<ProtocolMessage>;
35}
36
37/// SignableSeedBuilder is a trait for building seed protocol message part values
38#[cfg_attr(test, automock)]
39#[async_trait]
40pub trait SignableSeedBuilder: Send + Sync {
41    /// Compute next aggregate verification key protocol message part value
42    async fn compute_next_aggregate_verification_key(&self) -> StdResult<ProtocolMessagePartValue>;
43
44    /// Compute next protocol parameters protocol message part value
45    async fn compute_next_protocol_parameters(&self) -> StdResult<ProtocolMessagePartValue>;
46
47    /// Compute current epoch protocol message part value
48    async fn compute_current_epoch(&self) -> StdResult<ProtocolMessagePartValue>;
49}
50
51impl Beacon for BlockNumber {}
52
53impl Beacon for CardanoDbBeacon {}
54
55impl Beacon for Epoch {}
56
57#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
58impl Artifact for CardanoDatabaseSnapshot {
59    fn get_id(&self) -> String {
60        self.hash.clone()
61    }
62}
63
64#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
65impl Artifact for CardanoStakeDistribution {
66    fn get_id(&self) -> String {
67        self.hash.clone()
68    }
69}
70
71#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
72impl Artifact for CardanoTransactionsSnapshot {
73    fn get_id(&self) -> String {
74        self.hash.clone()
75    }
76}
77
78#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
79impl Artifact for MithrilStakeDistribution {
80    fn get_id(&self) -> String {
81        self.hash.clone()
82    }
83}
84
85#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
86impl Artifact for Snapshot {
87    fn get_id(&self) -> String {
88        self.digest.clone()
89    }
90}