Skip to content

Commit 5a09ae0

Browse files
committed
chore(aggregator): use 'DmqNetwork' model
1 parent 605f238 commit 5a09ae0

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::{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();
@@ -409,15 +426,21 @@ pub struct ServeCommandConfiguration {
409426
/// is why it has to be manually given to the Aggregator
410427
pub cardano_node_version: String,
411428

412-
/// Cardano Network Magic number
429+
/// Cardano network
430+
#[example = "`mainnet` or `preprod` or `devnet`"]
431+
pub network: String,
432+
433+
/// Cardano network magic number
413434
///
414435
/// useful for TestNet & DevNet
415436
#[example = "`1097911063` or `42`"]
416437
pub network_magic: Option<u64>,
417438

418-
/// Cardano network
419-
#[example = "`mainnet` or `preprod` or `devnet`"]
420-
pub network: String,
439+
/// Dmq network magic number
440+
///
441+
/// useful for TestNet & DevNet
442+
#[example = "`1097911063` or `42`"]
443+
pub dmq_network_magic: Option<u64>,
421444

422445
/// Cardano chain observer type
423446
pub chain_observer_type: ChainObserverType,
@@ -636,8 +659,9 @@ impl ServeCommandConfiguration {
636659
cardano_node_socket_path: PathBuf::new(),
637660
dmq_node_socket_path: None,
638661
cardano_node_version: "0.0.1".to_string(),
639-
network_magic: Some(42),
640662
network: "devnet".to_string(),
663+
network_magic: Some(42),
664+
dmq_network_magic: Some(3141592),
641665
chain_observer_type: ChainObserverType::Fake,
642666
protocol_parameters: ProtocolParameters {
643667
k: 5,
@@ -722,12 +746,16 @@ impl ConfigurationSource for ServeCommandConfiguration {
722746
self.cardano_node_version.clone()
723747
}
724748

749+
fn network(&self) -> String {
750+
self.network.clone()
751+
}
752+
725753
fn network_magic(&self) -> Option<u64> {
726754
self.network_magic
727755
}
728756

729-
fn network(&self) -> String {
730-
self.network.clone()
757+
fn dmq_network_magic(&self) -> Option<u64> {
758+
self.dmq_network_magic
731759
}
732760

733761
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)