1- use std:: collections:: BTreeSet ;
1+ use std:: { collections:: BTreeSet , sync :: Arc } ;
22
3- use crate :: entities:: AggregatorEpochSettings ;
3+ use crate :: {
4+ ConfigurationSource ,
5+ dependency_injection:: { DependenciesBuilder , Result } ,
6+ entities:: AggregatorEpochSettings ,
7+ get_dependency,
8+ } ;
49use async_trait:: async_trait;
5- use mithril_common:: { StdResult , entities:: SignedEntityTypeDiscriminants , test:: double:: Dummy } ;
10+ use mithril_common:: {
11+ StdResult ,
12+ entities:: { Epoch , SignedEntityTypeDiscriminants } ,
13+ } ;
614use mithril_protocol_config:: {
7- interface:: MithrilNetworkConfigurationProvider , model:: MithrilNetworkConfiguration ,
15+ interface:: MithrilNetworkConfigurationProvider ,
16+ model:: { MithrilNetworkConfiguration , SignedEntityTypeConfiguration } ,
817} ;
918
1019pub struct LocalMithrilNetworkConfigurationProvider {
@@ -13,10 +22,12 @@ pub struct LocalMithrilNetworkConfigurationProvider {
1322}
1423
1524impl LocalMithrilNetworkConfigurationProvider {
16- pub fn new (
17- epoch_settings : AggregatorEpochSettings ,
18- allowed_discriminants : BTreeSet < SignedEntityTypeDiscriminants > ,
19- ) -> Self {
25+ pub fn new ( configuration : Arc < dyn ConfigurationSource > ) -> Self {
26+ let epoch_settings = configuration. get_epoch_settings_configuration ( ) ;
27+ let allowed_discriminants = configuration
28+ . compute_allowed_signed_entity_types_discriminants ( )
29+ . expect ( "Failed to compute allowed signed entity types discriminants" ) ;
30+
2031 Self {
2132 epoch_settings,
2233 allowed_discriminants,
@@ -26,7 +37,42 @@ impl LocalMithrilNetworkConfigurationProvider {
2637
2738#[ async_trait]
2839impl MithrilNetworkConfigurationProvider for LocalMithrilNetworkConfigurationProvider {
29- async fn get ( & self ) -> StdResult < MithrilNetworkConfiguration > {
30- Ok ( MithrilNetworkConfiguration :: dummy ( ) )
40+ async fn get_network_configuration ( & self ) -> StdResult < MithrilNetworkConfiguration > {
41+ let epoch = Epoch ( 42 ) ; // TODO implement proper epoch retrieval
42+ let signer_registration_protocol_parameters =
43+ self . epoch_settings . protocol_parameters . clone ( ) ;
44+ let available_signed_entity_types = self . allowed_discriminants . clone ( ) ;
45+ let signed_entity_types_config = SignedEntityTypeConfiguration {
46+ cardano_transactions : Some (
47+ self . epoch_settings . cardano_transactions_signing_config . clone ( ) ,
48+ ) ,
49+ } ;
50+
51+ let config = MithrilNetworkConfiguration {
52+ epoch, //TODO implement
53+ signer_registration_protocol_parameters,
54+ available_signed_entity_types,
55+ signed_entity_types_config,
56+ } ;
57+ Ok ( config)
58+ }
59+ }
60+
61+ impl DependenciesBuilder {
62+ async fn build_mithril_network_configuration_provider (
63+ & mut self ,
64+ ) -> Result < Arc < dyn MithrilNetworkConfigurationProvider > > {
65+ let network_configuration_provider = Arc :: new (
66+ LocalMithrilNetworkConfigurationProvider :: new ( self . configuration . clone ( ) ) ,
67+ ) ;
68+
69+ Ok ( network_configuration_provider)
70+ }
71+
72+ /// [MithrilNetworkConfigurationProvider][mithril_protocol_config::interface::MithrilNetworkConfigurationProvider] service
73+ pub async fn get_mithril_network_configuration_provider (
74+ & mut self ,
75+ ) -> Result < Arc < dyn MithrilNetworkConfigurationProvider > > {
76+ get_dependency ! ( self . mithril_network_configuration_provider)
3177 }
3278}
0 commit comments