Skip to content

Commit 0c3793a

Browse files
committed
Add DependencyManager #120
* Implement a dependency manager * Add a snashot storer as a dependency * Use snapshot storer dependency in server routes
1 parent 87f379d commit 0c3793a

File tree

8 files changed

+280
-50
lines changed

8 files changed

+280
-50
lines changed

mithril-network/mithril-aggregator/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build test debug run help doc
1+
.PHONY: all build test check debug run help doc
22

33
CARGO = cargo
44

@@ -17,6 +17,10 @@ debug:
1717
test:
1818
${CARGO} test
1919

20+
check:
21+
${CARGO} check --all-targets
22+
${CARGO} clippy --all-targets
23+
2024
help:
2125
@${CARGO} run -- -h
2226

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"network": "testnet",
3+
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-testnet/snapshots.json"
4+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::sync::Arc;
2+
use tokio::sync::RwLock;
3+
4+
use crate::entities::*;
5+
use crate::snapshot_store::SnapshotStorer;
6+
7+
pub struct DependencyManager {
8+
pub config: Config,
9+
pub snapshot_storer: Option<Arc<RwLock<dyn SnapshotStorer + Sync + Send>>>,
10+
}
11+
12+
impl DependencyManager {
13+
/// DependencyManager factory
14+
pub fn new(config: Config) -> Self {
15+
Self {
16+
config,
17+
snapshot_storer: None,
18+
}
19+
}
20+
21+
/// With SnapshotStorer
22+
pub fn with_snapshot_storer(
23+
&mut self,
24+
snapshot_storer: Arc<RwLock<dyn SnapshotStorer + Sync + Send>>,
25+
) -> &mut Self {
26+
self.snapshot_storer = Some(snapshot_storer);
27+
self
28+
}
29+
}

mithril-network/mithril-aggregator/src/entities.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
use serde::{Deserialize, Serialize};
77

8+
/// Aggregator configuration
9+
#[derive(Debug, Clone, Serialize, Deserialize)]
10+
pub struct Config {
11+
/// Cardano network
12+
pub network: String,
13+
14+
/// Snapshots manifest location
15+
pub url_snapshot_manifest: String,
16+
}
17+
818
/// Beacon represents a point in the Cardano chain at which a Mithril certificate should be produced
919
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
1020
pub struct Beacon {
@@ -141,7 +151,7 @@ impl Certificate {
141151
pub struct Error {
142152
/// error code
143153
#[serde(rename = "code")]
144-
pub code: Option<serde_json::Value>,
154+
pub code: String,
145155

146156
/// error message
147157
#[serde(rename = "message")]
@@ -150,7 +160,7 @@ pub struct Error {
150160

151161
impl Error {
152162
/// Error factory
153-
pub fn new(code: Option<serde_json::Value>, message: String) -> Error {
163+
pub fn new(code: String, message: String) -> Error {
154164
Error { code, message }
155165
}
156166
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub const OPEN_CONFIG_FILE: &str = "impossible to open config file";
2+
3+
pub const PARSE_CONFIG_FILE: &str = "impossible to parse config file";

0 commit comments

Comments
 (0)