|
| 1 | +use std::marker::PhantomData; |
| 2 | + |
| 3 | +use async_trait::async_trait; |
| 4 | +use mithril_common::{ |
| 5 | + entities::Certificate, |
| 6 | + signable_builder::{DummyBeacon, DummySignable}, |
| 7 | + StdResult, |
| 8 | +}; |
| 9 | +use serde::{Deserialize, Serialize}; |
| 10 | + |
| 11 | +use crate::artifact_builder::{Artifact, ArtifactRestorer}; |
| 12 | + |
| 13 | +/// Dummy artifact |
| 14 | +#[derive(Serialize, Deserialize, PartialEq, Debug)] |
| 15 | +pub struct DummyArtifact<'a> { |
| 16 | + message: String, |
| 17 | + beacon: DummyBeacon, |
| 18 | + phantom: PhantomData<&'a DummyBeacon>, |
| 19 | +} |
| 20 | + |
| 21 | +impl<'a> DummyArtifact<'a> { |
| 22 | + /// Dummy artifact factory |
| 23 | + pub fn new(message: String, beacon: DummyBeacon) -> Self { |
| 24 | + Self { |
| 25 | + message, |
| 26 | + beacon, |
| 27 | + phantom: PhantomData, |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +impl<'a> Artifact<'a> for DummyArtifact<'a> {} |
| 33 | + |
| 34 | +/// A [DummyArtifact] restorer |
| 35 | +pub struct DummyArtifactRestorer {} |
| 36 | + |
| 37 | +impl DummyArtifactRestorer { |
| 38 | + /// Dummy artifact builder restorer |
| 39 | + pub fn new() -> Self { |
| 40 | + Self {} |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +impl Default for DummyArtifactRestorer { |
| 45 | + fn default() -> Self { |
| 46 | + Self::new() |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +#[async_trait] |
| 51 | +impl<'a> ArtifactRestorer<'a, DummyBeacon, DummyArtifact<'a>> for DummyArtifactRestorer { |
| 52 | + async fn compute_artifact( |
| 53 | + &'a self, |
| 54 | + beacon: DummyBeacon, |
| 55 | + certificate: &Certificate, |
| 56 | + ) -> StdResult<DummyArtifact> { |
| 57 | + Ok(DummyArtifact::new( |
| 58 | + format!("certificate id is {}", certificate.hash), |
| 59 | + beacon, |
| 60 | + )) |
| 61 | + } |
| 62 | + |
| 63 | + /// Compute a signable from an artifact |
| 64 | + async fn compute_signable(&self, artifact: DummyArtifact) -> StdResult<DummySignable> { |
| 65 | + Ok(DummySignable::new(artifact.message, artifact.beacon)) |
| 66 | + } |
| 67 | + |
| 68 | + /// Restore an artifact |
| 69 | + async fn restore_artifact(&'a self, artifact: DummyArtifact) -> StdResult<()> { |
| 70 | + Ok(()) |
| 71 | + } |
| 72 | +} |
0 commit comments