@@ -9,7 +9,6 @@ use std::{collections::HashMap, path::PathBuf};
99
1010use crate :: {
1111 CommandContext ,
12- commands:: SharedArgs ,
1312 commands:: cardano_db:: CardanoDbCommandsBackend ,
1413 configuration:: { ConfigError , ConfigParameters , ConfigSource } ,
1514 utils:: { self , JSON_CAUTION_KEY } ,
@@ -24,9 +23,6 @@ pub struct CardanoDbDownloadCommand {
2423 #[ arg( short, long, value_enum, default_value_t) ]
2524 backend : CardanoDbCommandsBackend ,
2625
27- #[ clap( flatten) ]
28- shared_args : SharedArgs ,
29-
3026 /// Digest of the Cardano db snapshot to download or `latest` for the latest artifact
3127 ///
3228 /// Use the `list` command to get that information.
@@ -74,59 +70,61 @@ pub struct CardanoDbDownloadCommand {
7470}
7571
7672impl CardanoDbDownloadCommand {
77- fn is_json_output_enabled ( & self ) -> bool {
78- self . shared_args . json
79- }
80-
8173 /// Command execution
8274 pub async fn execute ( & self , context : CommandContext ) -> MithrilResult < ( ) > {
8375 let params = context. config_parameters ( ) ?. add_source ( self ) ?;
8476
8577 match self . backend {
8678 CardanoDbCommandsBackend :: V1 => {
87- let prepared_command = self . prepare_v1 ( & params) ?;
88- prepared_command. execute ( context. logger ( ) , params) . await
79+ let prepared_command = self . prepare_v1 ( & params, & context ) ?;
80+ prepared_command. execute ( & context, params) . await
8981 }
9082 CardanoDbCommandsBackend :: V2 => {
91- let prepared_command = self . prepare_v2 ( & params) ?;
92- prepared_command. execute ( context. logger ( ) , params) . await
83+ let prepared_command = self . prepare_v2 ( & params, & context ) ?;
84+ prepared_command. execute ( & context, params) . await
9385 }
9486 }
9587 }
9688
97- fn prepare_v1 ( & self , params : & ConfigParameters ) -> MithrilResult < PreparedCardanoDbV1Download > {
89+ fn prepare_v1 (
90+ & self ,
91+ params : & ConfigParameters ,
92+ context : & CommandContext ,
93+ ) -> MithrilResult < PreparedCardanoDbV1Download > {
9894 if self . allow_override || self . start . is_some ( ) || self . end . is_some ( ) {
99- self . warn_unused_parameter_with_v1_backend ( ) ;
95+ self . warn_unused_parameter_with_v1_backend ( context ) ;
10096 }
10197
10298 let ancillary_verification_key = if self . include_ancillary {
103- self . warn_ancillary_not_signed_by_mithril ( ) ;
99+ self . warn_ancillary_not_signed_by_mithril ( context ) ;
104100 Some ( params. require ( "ancillary_verification_key" ) ?)
105101 } else {
106- self . warn_fast_bootstrap_not_available ( ) ;
102+ self . warn_fast_bootstrap_not_available ( context ) ;
107103 None
108104 } ;
109105
110106 Ok ( PreparedCardanoDbV1Download {
111- shared_args : self . shared_args . clone ( ) ,
112107 digest : self . digest . clone ( ) ,
113108 download_dir : params. require ( "download_dir" ) ?,
114109 include_ancillary : self . include_ancillary ,
115110 ancillary_verification_key,
116111 } )
117112 }
118113
119- fn prepare_v2 ( & self , params : & ConfigParameters ) -> MithrilResult < PreparedCardanoDbV2Download > {
114+ fn prepare_v2 (
115+ & self ,
116+ params : & ConfigParameters ,
117+ context : & CommandContext ,
118+ ) -> MithrilResult < PreparedCardanoDbV2Download > {
120119 let ancillary_verification_key = if self . include_ancillary {
121- self . warn_ancillary_not_signed_by_mithril ( ) ;
120+ self . warn_ancillary_not_signed_by_mithril ( context ) ;
122121 Some ( params. require ( "ancillary_verification_key" ) ?)
123122 } else {
124- self . warn_fast_bootstrap_not_available ( ) ;
123+ self . warn_fast_bootstrap_not_available ( context ) ;
125124 None
126125 } ;
127126
128127 Ok ( PreparedCardanoDbV2Download {
129- shared_args : self . shared_args . clone ( ) ,
130128 hash : self . digest . clone ( ) ,
131129 download_dir : params. require ( "download_dir" ) ?,
132130 start : self . start ,
@@ -138,8 +136,8 @@ impl CardanoDbDownloadCommand {
138136 }
139137
140138 /// Provides guidance on how to enable fast bootstrap by including ancillary files
141- fn warn_fast_bootstrap_not_available ( & self ) {
142- if self . is_json_output_enabled ( ) {
139+ fn warn_fast_bootstrap_not_available ( & self , context : & CommandContext ) {
140+ if context . is_json_output_enabled ( ) {
143141 let json = serde_json:: json!( {
144142 JSON_CAUTION_KEY : "The fast bootstrap of the Cardano node is not available with the current parameters used in this command" ,
145143 "impact" : "The ledger state will be recomputed from genesis at startup of the Cardano node" ,
@@ -165,18 +163,18 @@ For more information, please refer to the network configuration page of the docu
165163 }
166164 }
167165
168- fn warn_ancillary_not_signed_by_mithril ( & self ) {
166+ fn warn_ancillary_not_signed_by_mithril ( & self , context : & CommandContext ) {
169167 let message = "Ancillary verification does not use the Mithril certification: as a mitigation, IOG owned keys are used to sign these files." ;
170- if self . is_json_output_enabled ( ) {
168+ if context . is_json_output_enabled ( ) {
171169 eprintln ! ( r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"# ) ;
172170 } else {
173171 eprintln ! ( "{message}" ) ;
174172 }
175173 }
176174
177- fn warn_unused_parameter_with_v1_backend ( & self ) {
175+ fn warn_unused_parameter_with_v1_backend ( & self , context : & CommandContext ) {
178176 let message = "`--start`, `--end`, and `--allow-override` are only available with the `v2` backend. They will be ignored." ;
179- if self . is_json_output_enabled ( ) {
177+ if context . is_json_output_enabled ( ) {
180178 eprintln ! ( r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"# ) ;
181179 } else {
182180 eprintln ! ( "{message}" ) ;
@@ -227,7 +225,6 @@ mod tests {
227225 fn dummy_command ( ) -> CardanoDbDownloadCommand {
228226 CardanoDbDownloadCommand {
229227 backend : Default :: default ( ) ,
230- shared_args : SharedArgs { json : false } ,
231228 digest : "whatever_digest" . to_string ( ) ,
232229 download_dir : Some ( std:: path:: PathBuf :: from ( "whatever_dir" ) ) ,
233230 genesis_verification_key : "whatever" . to_string ( ) . into ( ) ,
@@ -249,6 +246,7 @@ mod tests {
249246 let command_context = CommandContext :: new (
250247 ConfigBuilder :: default ( ) ,
251248 false ,
249+ true ,
252250 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
253251 ) ;
254252
@@ -274,14 +272,14 @@ mod tests {
274272 . set_default ( "ancillary_verification_key" , "value from config" )
275273 . expect ( "Failed to build config builder" ) ;
276274 let command_context =
277- CommandContext :: new ( config, false , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
275+ CommandContext :: new ( config, false , true , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
278276 let config_parameters = command_context
279277 . config_parameters ( )
280278 . unwrap ( )
281279 . add_source ( & command)
282280 . unwrap ( ) ;
283281
284- let result = command. prepare_v1 ( & config_parameters) ;
282+ let result = command. prepare_v1 ( & config_parameters, & command_context ) ;
285283
286284 assert ! ( result. is_ok( ) ) ;
287285 }
@@ -292,9 +290,10 @@ mod tests {
292290 download_dir : None ,
293291 ..dummy_command ( )
294292 } ;
295- let command_context = CommandContext :: new (
293+ let command_context = & CommandContext :: new (
296294 ConfigBuilder :: default ( ) ,
297295 false ,
296+ true ,
298297 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
299298 ) ;
300299 let config_parameters = command_context
@@ -303,7 +302,7 @@ mod tests {
303302 . add_source ( & command)
304303 . unwrap ( ) ;
305304
306- let result = command. prepare_v1 ( & config_parameters) ;
305+ let result = command. prepare_v1 ( & config_parameters, command_context ) ;
307306
308307 assert ! ( result. is_err( ) ) ;
309308 assert_eq ! (
@@ -326,14 +325,14 @@ mod tests {
326325 . set_default ( "ancillary_verification_key" , "value from config" )
327326 . expect ( "Failed to build config builder" ) ;
328327 let command_context =
329- CommandContext :: new ( config, false , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
328+ CommandContext :: new ( config, false , true , Logger :: root ( slog:: Discard , slog:: o!( ) ) ) ;
330329 let config_parameters = command_context
331330 . config_parameters ( )
332331 . unwrap ( )
333332 . add_source ( & command)
334333 . unwrap ( ) ;
335334
336- let result = command. prepare_v2 ( & config_parameters) ;
335+ let result = command. prepare_v2 ( & config_parameters, & command_context ) ;
337336
338337 assert ! ( result. is_ok( ) ) ;
339338 }
@@ -347,6 +346,7 @@ mod tests {
347346 let command_context = CommandContext :: new (
348347 ConfigBuilder :: default ( ) ,
349348 false ,
349+ true ,
350350 Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
351351 ) ;
352352 let config_parameters = command_context
@@ -355,7 +355,7 @@ mod tests {
355355 . add_source ( & command)
356356 . unwrap ( ) ;
357357
358- let result = command. prepare_v2 ( & config_parameters) ;
358+ let result = command. prepare_v2 ( & config_parameters, & command_context ) ;
359359
360360 assert ! ( result. is_err( ) ) ;
361361 assert_eq ! (
0 commit comments