Skip to content

Commit 9e162a0

Browse files
committed
chore(aggregator): use 'DmqNetwork' model
1 parent 6a03fcd commit 9e162a0

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

mithril-aggregator/src/configuration.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use anyhow::Context;
2-
use config::{ConfigError, Map, Source, Value, ValueKind};
3-
use serde::{Deserialize, Serialize};
41
use std::collections::{BTreeSet, HashMap, HashSet};
52
use std::path::PathBuf;
63
use std::str::FromStr;
74

5+
use anyhow::Context;
6+
use config::{ConfigError, Map, Source, Value, ValueKind};
7+
use serde::{Deserialize, Serialize};
8+
89
use mithril_cardano_node_chain::chain_observer::ChainObserverType;
910
use mithril_cli_helper::{register_config_value, serde_deserialization};
1011
use mithril_common::crypto_helper::{ManifestSigner, ProtocolGenesisSigner};
@@ -14,6 +15,7 @@ use mithril_common::entities::{
1415
SignedEntityTypeDiscriminants,
1516
};
1617
use mithril_common::{AggregateSignatureType, CardanoNetwork, StdResult};
18+
use mithril_dmq::DmqNetwork;
1719
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};
1820
use mithril_era::adapters::EraReaderAdapterType;
1921

@@ -80,16 +82,24 @@ pub trait ConfigurationSource {
8082
panic!("cardano_node_version is not implemented.");
8183
}
8284

85+
/// Cardano network
86+
fn network(&self) -> String {
87+
panic!("network is not implemented.");
88+
}
89+
8390
/// Cardano Network Magic number
8491
///
8592
/// useful for TestNet & DevNet
8693
fn network_magic(&self) -> Option<u64> {
8794
panic!("network_magic is not implemented.");
8895
}
8996

90-
/// Cardano network
91-
fn network(&self) -> String {
92-
panic!("network is not implemented.");
97+
/// DMQ Network Magic number
98+
///
99+
/// useful for TestNet & DevNet
100+
#[cfg(feature = "future_dmq")]
101+
fn dmq_network_magic(&self) -> Option<u64> {
102+
panic!("dmq_network_magic is not implemented.");
93103
}
94104

95105
/// Cardano chain observer type
@@ -302,6 +312,13 @@ pub trait ConfigurationSource {
302312
.with_context(|| "Invalid network configuration")
303313
}
304314

315+
/// Get a representation of the DMQ network.
316+
#[cfg(feature = "future_dmq")]
317+
fn get_dmq_network(&self) -> StdResult<DmqNetwork> {
318+
DmqNetwork::from_code(self.network(), self.dmq_network_magic())
319+
.with_context(|| "Invalid DMQ network configuration")
320+
}
321+
305322
/// Get the directory of the SQLite stores.
306323
fn get_sqlite_dir(&self) -> PathBuf {
307324
let store_dir = &self.data_stores_directory();
@@ -414,15 +431,21 @@ pub struct ServeCommandConfiguration {
414431
/// is why it has to be manually given to the Aggregator
415432
pub cardano_node_version: String,
416433

417-
/// Cardano Network Magic number
434+
/// Cardano network
435+
#[example = "`mainnet` or `preprod` or `devnet`"]
436+
pub network: String,
437+
438+
/// Cardano network magic number
418439
///
419440
/// useful for TestNet & DevNet
420441
#[example = "`1097911063` or `42`"]
421442
pub network_magic: Option<u64>,
422443

423-
/// Cardano network
424-
#[example = "`mainnet` or `preprod` or `devnet`"]
425-
pub network: String,
444+
/// Dmq network magic number
445+
///
446+
/// useful for TestNet & DevNet
447+
#[example = "`1097911063` or `42`"]
448+
pub dmq_network_magic: Option<u64>,
426449

427450
/// Cardano chain observer type
428451
pub chain_observer_type: ChainObserverType,
@@ -644,8 +667,9 @@ impl ServeCommandConfiguration {
644667
cardano_node_socket_path: PathBuf::new(),
645668
dmq_node_socket_path: None,
646669
cardano_node_version: "0.0.1".to_string(),
647-
network_magic: Some(42),
648670
network: "devnet".to_string(),
671+
network_magic: Some(42),
672+
dmq_network_magic: Some(3141592),
649673
chain_observer_type: ChainObserverType::Fake,
650674
protocol_parameters: ProtocolParameters {
651675
k: 5,
@@ -731,12 +755,16 @@ impl ConfigurationSource for ServeCommandConfiguration {
731755
self.cardano_node_version.clone()
732756
}
733757

758+
fn network(&self) -> String {
759+
self.network.clone()
760+
}
761+
734762
fn network_magic(&self) -> Option<u64> {
735763
self.network_magic
736764
}
737765

738-
fn network(&self) -> String {
739-
self.network.clone()
766+
fn dmq_network_magic(&self) -> Option<u64> {
767+
self.dmq_network_magic
740768
}
741769

742770
fn chain_observer_type(&self) -> ChainObserverType {

mithril-aggregator/src/dependency_injection/builder/enablers/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl DependenciesBuilder {
9292
let dmq_consumer =
9393
Arc::new(DmqConsumerClientPallas::<RegisterSignatureMessageDmq>::new(
9494
dmq_node_socket_path,
95-
self.configuration.get_network()?,
95+
self.configuration.get_dmq_network()?,
9696
self.root_logger(),
9797
));
9898
Arc::new(SignatureConsumerDmq::new(dmq_consumer)) as Arc<dyn SignatureConsumer>

0 commit comments

Comments
 (0)