@@ -10,7 +10,7 @@ use std::{collections::HashMap, path::PathBuf};
1010use crate :: {
1111 CommandContext ,
1212 commands:: cardano_db:: CardanoDbCommandsBackend ,
13- configuration:: { ConfigError , ConfigParameters , ConfigSource } ,
13+ configuration:: { ConfigError , ConfigSource } ,
1414 utils:: { self , JSON_CAUTION_KEY } ,
1515} ;
1616use mithril_client:: { MithrilResult , common:: ImmutableFileNumber } ;
@@ -71,62 +71,54 @@ pub struct CardanoDbDownloadCommand {
7171
7272impl CardanoDbDownloadCommand {
7373 /// Command execution
74- pub async fn execute ( & self , context : CommandContext ) -> MithrilResult < ( ) > {
75- let params = context. config_parameters ( ) ? . add_source ( self ) ?;
74+ pub async fn execute ( & self , mut context : CommandContext ) -> MithrilResult < ( ) > {
75+ context. config_parameters_mut ( ) . add_source ( self ) ?;
7676
7777 match self . backend {
7878 CardanoDbCommandsBackend :: V1 => {
79- let prepared_command = self . prepare_v1 ( & params , & context) ?;
80- prepared_command. execute ( & context, params ) . await
79+ let prepared_command = self . prepare_v1 ( & context) ?;
80+ prepared_command. execute ( & context) . await
8181 }
8282 CardanoDbCommandsBackend :: V2 => {
83- let prepared_command = self . prepare_v2 ( & params , & context) ?;
84- prepared_command. execute ( & context, params ) . await
83+ let prepared_command = self . prepare_v2 ( & context) ?;
84+ prepared_command. execute ( & context) . await
8585 }
8686 }
8787 }
8888
89- fn prepare_v1 (
90- & self ,
91- params : & ConfigParameters ,
92- context : & CommandContext ,
93- ) -> MithrilResult < PreparedCardanoDbV1Download > {
89+ fn prepare_v1 ( & self , context : & CommandContext ) -> MithrilResult < PreparedCardanoDbV1Download > {
9490 if self . allow_override || self . start . is_some ( ) || self . end . is_some ( ) {
9591 self . warn_unused_parameter_with_v1_backend ( context) ;
9692 }
9793
9894 let ancillary_verification_key = if self . include_ancillary {
9995 self . warn_ancillary_not_signed_by_mithril ( context) ;
100- Some ( params . require ( "ancillary_verification_key" ) ?)
96+ Some ( context . config_parameters ( ) . require ( "ancillary_verification_key" ) ?)
10197 } else {
10298 self . warn_fast_bootstrap_not_available ( context) ;
10399 None
104100 } ;
105101
106102 Ok ( PreparedCardanoDbV1Download {
107103 digest : self . digest . clone ( ) ,
108- download_dir : params . require ( "download_dir" ) ?,
104+ download_dir : context . config_parameters ( ) . require ( "download_dir" ) ?,
109105 include_ancillary : self . include_ancillary ,
110106 ancillary_verification_key,
111107 } )
112108 }
113109
114- fn prepare_v2 (
115- & self ,
116- params : & ConfigParameters ,
117- context : & CommandContext ,
118- ) -> MithrilResult < PreparedCardanoDbV2Download > {
110+ fn prepare_v2 ( & self , context : & CommandContext ) -> MithrilResult < PreparedCardanoDbV2Download > {
119111 let ancillary_verification_key = if self . include_ancillary {
120112 self . warn_ancillary_not_signed_by_mithril ( context) ;
121- Some ( params . require ( "ancillary_verification_key" ) ?)
113+ Some ( context . config_parameters ( ) . require ( "ancillary_verification_key" ) ?)
122114 } else {
123115 self . warn_fast_bootstrap_not_available ( context) ;
124116 None
125117 } ;
126118
127119 Ok ( PreparedCardanoDbV2Download {
128120 hash : self . digest . clone ( ) ,
129- download_dir : params . require ( "download_dir" ) ?,
121+ download_dir : context . config_parameters ( ) . require ( "download_dir" ) ?,
130122 start : self . start ,
131123 end : self . end ,
132124 include_ancillary : self . include_ancillary ,
@@ -217,9 +209,10 @@ impl ConfigSource for CardanoDbDownloadCommand {
217209
218210#[ cfg( test) ]
219211mod tests {
220- use config:: ConfigBuilder ;
221212 use slog:: Logger ;
222213
214+ use crate :: ConfigParameters ;
215+
223216 use super :: * ;
224217
225218 fn dummy_command ( ) -> CardanoDbDownloadCommand {
@@ -244,7 +237,7 @@ mod tests {
244237 ..dummy_command ( )
245238 } ;
246239 let command_context = CommandContext :: new (
247- ConfigBuilder :: default ( ) ,
240+ ConfigParameters :: default ( ) ,
248241 false ,
249242 true ,
250243 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
@@ -268,18 +261,15 @@ mod tests {
268261 ancillary_verification_key : None ,
269262 ..dummy_command ( )
270263 } ;
271- let config = config:: Config :: builder ( )
272- . set_default ( "ancillary_verification_key" , "value from config" )
273- . expect ( "Failed to build config builder" ) ;
274- let command_context =
264+ let config = ConfigParameters :: new ( HashMap :: from ( [ (
265+ "ancillary_verification_key" . to_string ( ) ,
266+ "value from config" . to_string ( ) ,
267+ ) ] ) ) ;
268+ let mut command_context =
275269 CommandContext :: new ( config, false , true , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
276- let config_parameters = command_context
277- . config_parameters ( )
278- . unwrap ( )
279- . add_source ( & command)
280- . unwrap ( ) ;
270+ command_context. config_parameters_mut ( ) . add_source ( & command) . unwrap ( ) ;
281271
282- let result = command. prepare_v1 ( & config_parameters , & command_context) ;
272+ let result = command. prepare_v1 ( & command_context) ;
283273
284274 assert ! ( result. is_ok( ) ) ;
285275 }
@@ -290,19 +280,16 @@ mod tests {
290280 download_dir : None ,
291281 ..dummy_command ( )
292282 } ;
293- let command_context = & CommandContext :: new (
294- ConfigBuilder :: default ( ) ,
283+ let mut command_context = CommandContext :: new (
284+ ConfigParameters :: default ( ) ,
295285 false ,
296286 true ,
297287 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
298288 ) ;
299- let config_parameters = command_context
300- . config_parameters ( )
301- . unwrap ( )
302- . add_source ( & command)
303- . unwrap ( ) ;
304289
305- let result = command. prepare_v1 ( & config_parameters, command_context) ;
290+ command_context. config_parameters_mut ( ) . add_source ( & command) . unwrap ( ) ;
291+
292+ let result = command. prepare_v1 ( & command_context) ;
306293
307294 assert ! ( result. is_err( ) ) ;
308295 assert_eq ! (
@@ -321,18 +308,16 @@ mod tests {
321308 ancillary_verification_key : None ,
322309 ..dummy_command ( )
323310 } ;
324- let config = config:: Config :: builder ( )
325- . set_default ( "ancillary_verification_key" , "value from config" )
326- . expect ( "Failed to build config builder" ) ;
327- let command_context =
311+ let config = ConfigParameters :: new ( HashMap :: from ( [ (
312+ "ancillary_verification_key" . to_string ( ) ,
313+ "value from config" . to_string ( ) ,
314+ ) ] ) ) ;
315+ let mut command_context =
328316 CommandContext :: new ( config, false , true , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
329- let config_parameters = command_context
330- . config_parameters ( )
331- . unwrap ( )
332- . add_source ( & command)
333- . unwrap ( ) ;
334317
335- let result = command. prepare_v2 ( & config_parameters, & command_context) ;
318+ command_context. config_parameters_mut ( ) . add_source ( & command) . unwrap ( ) ;
319+
320+ let result = command. prepare_v2 ( & command_context) ;
336321
337322 assert ! ( result. is_ok( ) ) ;
338323 }
@@ -343,19 +328,16 @@ mod tests {
343328 download_dir : None ,
344329 ..dummy_command ( )
345330 } ;
346- let command_context = CommandContext :: new (
347- ConfigBuilder :: default ( ) ,
331+ let mut command_context = CommandContext :: new (
332+ ConfigParameters :: default ( ) ,
348333 false ,
349334 true ,
350335 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
351336 ) ;
352- let config_parameters = command_context
353- . config_parameters ( )
354- . unwrap ( )
355- . add_source ( & command)
356- . unwrap ( ) ;
357337
358- let result = command. prepare_v2 ( & config_parameters, & command_context) ;
338+ command_context. config_parameters_mut ( ) . add_source ( & command) . unwrap ( ) ;
339+
340+ let result = command. prepare_v2 ( & command_context) ;
359341
360342 assert ! ( result. is_err( ) ) ;
361343 assert_eq ! (
0 commit comments