mithril_common/signable_builder/
interface.rs

1use async_trait::async_trait;
2use std::fmt::Debug;
3
4use crate::{
5    StdResult,
6    entities::{
7        BlockNumber, CardanoBlocksTransactionsSnapshot, CardanoDatabaseSnapshot, CardanoDbBeacon,
8        CardanoStakeDistribution, CardanoTransactionsSnapshot, Epoch, MithrilStakeDistribution,
9        ProtocolMessage, ProtocolMessagePartValue, Snapshot,
10    },
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 for concatenation protocol message part value
42    async fn compute_next_aggregate_verification_key_for_concatenation(
43        &self,
44    ) -> StdResult<ProtocolMessagePartValue>;
45
46    /// Compute next protocol parameters protocol message part value
47    async fn compute_next_protocol_parameters(&self) -> StdResult<ProtocolMessagePartValue>;
48
49    /// Compute current epoch protocol message part value
50    async fn compute_current_epoch(&self) -> StdResult<ProtocolMessagePartValue>;
51}
52
53impl Beacon for BlockNumber {}
54
55impl Beacon for CardanoDbBeacon {}
56
57impl Beacon for Epoch {}
58
59#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
60impl Artifact for CardanoDatabaseSnapshot {
61    fn get_id(&self) -> String {
62        self.hash.clone()
63    }
64}
65
66#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
67impl Artifact for CardanoStakeDistribution {
68    fn get_id(&self) -> String {
69        self.hash.clone()
70    }
71}
72
73#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
74impl Artifact for CardanoTransactionsSnapshot {
75    fn get_id(&self) -> String {
76        self.hash.clone()
77    }
78}
79
80#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
81impl Artifact for CardanoBlocksTransactionsSnapshot {
82    fn get_id(&self) -> String {
83        self.hash.clone()
84    }
85}
86
87#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
88impl Artifact for MithrilStakeDistribution {
89    fn get_id(&self) -> String {
90        self.hash.clone()
91    }
92}
93
94#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
95impl Artifact for Snapshot {
96    fn get_id(&self) -> String {
97        self.digest.clone()
98    }
99}