@@ -10,7 +10,7 @@ use std::{collections::HashMap, path::PathBuf};
10
10
use crate :: {
11
11
CommandContext ,
12
12
commands:: cardano_db:: CardanoDbCommandsBackend ,
13
- configuration:: { ConfigError , ConfigParameters , ConfigSource } ,
13
+ configuration:: { ConfigError , ConfigSource } ,
14
14
utils:: { self , JSON_CAUTION_KEY } ,
15
15
} ;
16
16
use mithril_client:: { MithrilResult , common:: ImmutableFileNumber } ;
@@ -71,62 +71,54 @@ pub struct CardanoDbDownloadCommand {
71
71
72
72
impl CardanoDbDownloadCommand {
73
73
/// 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 ) ?;
76
76
77
77
match self . backend {
78
78
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
81
81
}
82
82
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
85
85
}
86
86
}
87
87
}
88
88
89
- fn prepare_v1 (
90
- & self ,
91
- params : & ConfigParameters ,
92
- context : & CommandContext ,
93
- ) -> MithrilResult < PreparedCardanoDbV1Download > {
89
+ fn prepare_v1 ( & self , context : & CommandContext ) -> MithrilResult < PreparedCardanoDbV1Download > {
94
90
if self . allow_override || self . start . is_some ( ) || self . end . is_some ( ) {
95
91
self . warn_unused_parameter_with_v1_backend ( context) ;
96
92
}
97
93
98
94
let ancillary_verification_key = if self . include_ancillary {
99
95
self . warn_ancillary_not_signed_by_mithril ( context) ;
100
- Some ( params . require ( "ancillary_verification_key" ) ?)
96
+ Some ( context . config_parameters ( ) . require ( "ancillary_verification_key" ) ?)
101
97
} else {
102
98
self . warn_fast_bootstrap_not_available ( context) ;
103
99
None
104
100
} ;
105
101
106
102
Ok ( PreparedCardanoDbV1Download {
107
103
digest : self . digest . clone ( ) ,
108
- download_dir : params . require ( "download_dir" ) ?,
104
+ download_dir : context . config_parameters ( ) . require ( "download_dir" ) ?,
109
105
include_ancillary : self . include_ancillary ,
110
106
ancillary_verification_key,
111
107
} )
112
108
}
113
109
114
- fn prepare_v2 (
115
- & self ,
116
- params : & ConfigParameters ,
117
- context : & CommandContext ,
118
- ) -> MithrilResult < PreparedCardanoDbV2Download > {
110
+ fn prepare_v2 ( & self , context : & CommandContext ) -> MithrilResult < PreparedCardanoDbV2Download > {
119
111
let ancillary_verification_key = if self . include_ancillary {
120
112
self . warn_ancillary_not_signed_by_mithril ( context) ;
121
- Some ( params . require ( "ancillary_verification_key" ) ?)
113
+ Some ( context . config_parameters ( ) . require ( "ancillary_verification_key" ) ?)
122
114
} else {
123
115
self . warn_fast_bootstrap_not_available ( context) ;
124
116
None
125
117
} ;
126
118
127
119
Ok ( PreparedCardanoDbV2Download {
128
120
hash : self . digest . clone ( ) ,
129
- download_dir : params . require ( "download_dir" ) ?,
121
+ download_dir : context . config_parameters ( ) . require ( "download_dir" ) ?,
130
122
start : self . start ,
131
123
end : self . end ,
132
124
include_ancillary : self . include_ancillary ,
@@ -217,9 +209,10 @@ impl ConfigSource for CardanoDbDownloadCommand {
217
209
218
210
#[ cfg( test) ]
219
211
mod tests {
220
- use config:: ConfigBuilder ;
221
212
use slog:: Logger ;
222
213
214
+ use crate :: ConfigParameters ;
215
+
223
216
use super :: * ;
224
217
225
218
fn dummy_command ( ) -> CardanoDbDownloadCommand {
@@ -244,7 +237,7 @@ mod tests {
244
237
..dummy_command ( )
245
238
} ;
246
239
let command_context = CommandContext :: new (
247
- ConfigBuilder :: default ( ) ,
240
+ ConfigParameters :: default ( ) ,
248
241
false ,
249
242
true ,
250
243
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
@@ -268,18 +261,15 @@ mod tests {
268
261
ancillary_verification_key : None ,
269
262
..dummy_command ( )
270
263
} ;
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 =
275
269
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 ( ) ;
281
271
282
- let result = command. prepare_v1 ( & config_parameters , & command_context) ;
272
+ let result = command. prepare_v1 ( & command_context) ;
283
273
284
274
assert ! ( result. is_ok( ) ) ;
285
275
}
@@ -290,19 +280,16 @@ mod tests {
290
280
download_dir : None ,
291
281
..dummy_command ( )
292
282
} ;
293
- let command_context = & CommandContext :: new (
294
- ConfigBuilder :: default ( ) ,
283
+ let mut command_context = CommandContext :: new (
284
+ ConfigParameters :: default ( ) ,
295
285
false ,
296
286
true ,
297
287
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
298
288
) ;
299
- let config_parameters = command_context
300
- . config_parameters ( )
301
- . unwrap ( )
302
- . add_source ( & command)
303
- . unwrap ( ) ;
304
289
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) ;
306
293
307
294
assert ! ( result. is_err( ) ) ;
308
295
assert_eq ! (
@@ -321,18 +308,16 @@ mod tests {
321
308
ancillary_verification_key : None ,
322
309
..dummy_command ( )
323
310
} ;
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 =
328
316
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 ( ) ;
334
317
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) ;
336
321
337
322
assert ! ( result. is_ok( ) ) ;
338
323
}
@@ -343,19 +328,16 @@ mod tests {
343
328
download_dir : None ,
344
329
..dummy_command ( )
345
330
} ;
346
- let command_context = CommandContext :: new (
347
- ConfigBuilder :: default ( ) ,
331
+ let mut command_context = CommandContext :: new (
332
+ ConfigParameters :: default ( ) ,
348
333
false ,
349
334
true ,
350
335
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
351
336
) ;
352
- let config_parameters = command_context
353
- . config_parameters ( )
354
- . unwrap ( )
355
- . add_source ( & command)
356
- . unwrap ( ) ;
357
337
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) ;
359
341
360
342
assert ! ( result. is_err( ) ) ;
361
343
assert_eq ! (
0 commit comments