Skip to content

Commit 14f5d28

Browse files
committed
Add ArtifactBuilder trait
1 parent 9b9d1f6 commit 14f5d28

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::marker::PhantomData;
2+
3+
use async_trait::async_trait;
4+
use mithril_common::{entities::Certificate, signable_builder::DummyBeacon, StdResult};
5+
use serde::{Deserialize, Serialize};
6+
7+
use crate::artifact_builder::{Artifact, ArtifactBuilder};
8+
9+
/// Dummy artifact
10+
#[derive(Serialize, Deserialize, PartialEq, Debug)]
11+
pub struct DummyArtifact<'a> {
12+
message: String,
13+
beacon: DummyBeacon,
14+
phantom: PhantomData<&'a DummyBeacon>,
15+
}
16+
17+
impl<'a> DummyArtifact<'a> {
18+
/// Dummy artifact factory
19+
pub fn new(message: String, beacon: DummyBeacon) -> Self {
20+
Self {
21+
message,
22+
beacon,
23+
phantom: PhantomData,
24+
}
25+
}
26+
}
27+
28+
impl<'a> Artifact<'a> for DummyArtifact<'a> {}
29+
30+
/// A [DummyArtifact] builder
31+
pub struct DummyArtifactBuilder {}
32+
33+
impl DummyArtifactBuilder {
34+
/// Dummy artifact builder factory
35+
pub fn new() -> Self {
36+
Self {}
37+
}
38+
}
39+
40+
impl Default for DummyArtifactBuilder {
41+
fn default() -> Self {
42+
Self::new()
43+
}
44+
}
45+
46+
#[async_trait]
47+
impl<'a> ArtifactBuilder<'a, DummyBeacon, DummyArtifact<'a>> for DummyArtifactBuilder {
48+
async fn compute_artifact(
49+
&'a self,
50+
beacon: DummyBeacon,
51+
certificate: Certificate,
52+
) -> StdResult<DummyArtifact> {
53+
Ok(DummyArtifact::new(
54+
format!("certificate id is {}", certificate.hash),
55+
beacon,
56+
))
57+
}
58+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use async_trait::async_trait;
2+
use mithril_common::{entities::Certificate, signable_builder::Beacon, StdResult};
3+
use serde::{Deserialize, Serialize};
4+
use std::fmt::Debug;
5+
6+
/// Artifact is a trait for types that represent signed artifacts
7+
pub trait Artifact<'a>: Serialize + Deserialize<'a> + PartialEq + Debug {}
8+
9+
/// ArtifactBuilder is trait for building an artifact
10+
#[async_trait]
11+
pub trait ArtifactBuilder<'a, U, W>
12+
where
13+
U: Beacon,
14+
W: Artifact<'a>,
15+
{
16+
/// Compute an artifact
17+
async fn compute_artifact(&'a self, beacon: U, certificate: Certificate) -> StdResult<W>;
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! The module used for building artifact
2+
3+
mod dummy_artifact;
4+
mod interface;
5+
6+
pub use dummy_artifact::*;
7+
pub use interface::*;

mithril-aggregator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! signed certificates.
1212
//! You can find more information on how it works reading the [documentation website](https://mithril.network/doc/mithril/mithril-network/aggregator).
1313
14+
mod artifact_builder;
1415
mod certificate_creator;
1516
mod command_args;
1617
mod configuration;

0 commit comments

Comments
 (0)