use async_trait::async_trait;
use std::fmt::Debug;
use crate::{
StdResult,
entities::{
BlockNumber, BlockNumberOffset, CardanoBlocksTransactionsSnapshot, CardanoDatabaseSnapshot,
CardanoDbBeacon, CardanoStakeDistribution, CardanoTransactionsSnapshot, Epoch,
MithrilStakeDistribution, ProtocolMessage, ProtocolMessagePartValue, Snapshot,
},
};
#[cfg(test)]
use mockall::automock;
pub trait Beacon: Send + Sync {}
#[cfg_attr(not(target_family = "wasm"), typetag::serde(tag = "type"))]
pub trait Artifact: Debug + Send + Sync {
fn get_id(&self) -> String;
}
#[cfg_attr(test, automock)]
#[async_trait]
pub trait SignableBuilder<U>: Send + Sync
where
U: Beacon,
{
async fn compute_protocol_message(&self, beacon: U) -> StdResult<ProtocolMessage>;
}
#[cfg_attr(test, automock)]
#[async_trait]
pub trait SignableSeedBuilder: Send + Sync {
async fn compute_next_aggregate_verification_key_for_concatenation(
&self,
) -> StdResult<ProtocolMessagePartValue>;
async fn compute_next_aggregate_verification_key_for_snark(
&self,
) -> StdResult<Option<ProtocolMessagePartValue>>;
async fn compute_next_protocol_parameters(&self) -> StdResult<ProtocolMessagePartValue>;
async fn compute_current_epoch(&self) -> StdResult<ProtocolMessagePartValue>;
}
impl Beacon for BlockNumber {}
impl Beacon for CardanoDbBeacon {}
impl Beacon for Epoch {}
impl Beacon for (BlockNumber, BlockNumberOffset) {}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for CardanoDatabaseSnapshot {
fn get_id(&self) -> String {
self.hash.clone()
}
}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for CardanoStakeDistribution {
fn get_id(&self) -> String {
self.hash.clone()
}
}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for CardanoTransactionsSnapshot {
fn get_id(&self) -> String {
self.hash.clone()
}
}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for CardanoBlocksTransactionsSnapshot {
fn get_id(&self) -> String {
self.hash.clone()
}
}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for MithrilStakeDistribution {
fn get_id(&self) -> String {
self.hash.clone()
}
}
#[cfg_attr(not(target_family = "wasm"), typetag::serde)]
impl Artifact for Snapshot {
fn get_id(&self) -> String {
self.digest.clone()
}
}