mithril_common/signable_builder/
interface.rs1use 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
16pub trait Beacon: Send + Sync {}
18
19#[cfg_attr(not(target_family = "wasm"), typetag::serde(tag = "type"))]
21pub trait Artifact: Debug + Send + Sync {
22 fn get_id(&self) -> String;
24}
25
26#[cfg_attr(test, automock)]
28#[async_trait]
29pub trait SignableBuilder<U>: Send + Sync
30where
31 U: Beacon,
32{
33 async fn compute_protocol_message(&self, beacon: U) -> StdResult<ProtocolMessage>;
35}
36
37#[cfg_attr(test, automock)]
39#[async_trait]
40pub trait SignableSeedBuilder: Send + Sync {
41 async fn compute_next_aggregate_verification_key(&self) -> StdResult<ProtocolMessagePartValue>;
43
44 async fn compute_next_protocol_parameters(&self) -> StdResult<ProtocolMessagePartValue>;
46
47 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}