@@ -9,7 +9,6 @@ use std::{collections::HashMap, path::PathBuf};
9
9
10
10
use crate :: {
11
11
CommandContext ,
12
- commands:: SharedArgs ,
13
12
commands:: cardano_db:: CardanoDbCommandsBackend ,
14
13
configuration:: { ConfigError , ConfigParameters , ConfigSource } ,
15
14
utils:: { self , JSON_CAUTION_KEY } ,
@@ -24,9 +23,6 @@ pub struct CardanoDbDownloadCommand {
24
23
#[ arg( short, long, value_enum, default_value_t) ]
25
24
backend : CardanoDbCommandsBackend ,
26
25
27
- #[ clap( flatten) ]
28
- shared_args : SharedArgs ,
29
-
30
26
/// Digest of the Cardano db snapshot to download or `latest` for the latest artifact
31
27
///
32
28
/// Use the `list` command to get that information.
@@ -74,59 +70,61 @@ pub struct CardanoDbDownloadCommand {
74
70
}
75
71
76
72
impl CardanoDbDownloadCommand {
77
- fn is_json_output_enabled ( & self ) -> bool {
78
- self . shared_args . json
79
- }
80
-
81
73
/// Command execution
82
74
pub async fn execute ( & self , context : CommandContext ) -> MithrilResult < ( ) > {
83
75
let params = context. config_parameters ( ) ?. add_source ( self ) ?;
84
76
85
77
match self . backend {
86
78
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
89
81
}
90
82
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
93
85
}
94
86
}
95
87
}
96
88
97
- fn prepare_v1 ( & self , params : & ConfigParameters ) -> MithrilResult < PreparedCardanoDbV1Download > {
89
+ fn prepare_v1 (
90
+ & self ,
91
+ params : & ConfigParameters ,
92
+ context : & CommandContext ,
93
+ ) -> MithrilResult < PreparedCardanoDbV1Download > {
98
94
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 ) ;
100
96
}
101
97
102
98
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 ) ;
104
100
Some ( params. require ( "ancillary_verification_key" ) ?)
105
101
} else {
106
- self . warn_fast_bootstrap_not_available ( ) ;
102
+ self . warn_fast_bootstrap_not_available ( context ) ;
107
103
None
108
104
} ;
109
105
110
106
Ok ( PreparedCardanoDbV1Download {
111
- shared_args : self . shared_args . clone ( ) ,
112
107
digest : self . digest . clone ( ) ,
113
108
download_dir : params. require ( "download_dir" ) ?,
114
109
include_ancillary : self . include_ancillary ,
115
110
ancillary_verification_key,
116
111
} )
117
112
}
118
113
119
- fn prepare_v2 ( & self , params : & ConfigParameters ) -> MithrilResult < PreparedCardanoDbV2Download > {
114
+ fn prepare_v2 (
115
+ & self ,
116
+ params : & ConfigParameters ,
117
+ context : & CommandContext ,
118
+ ) -> MithrilResult < PreparedCardanoDbV2Download > {
120
119
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 ) ;
122
121
Some ( params. require ( "ancillary_verification_key" ) ?)
123
122
} else {
124
- self . warn_fast_bootstrap_not_available ( ) ;
123
+ self . warn_fast_bootstrap_not_available ( context ) ;
125
124
None
126
125
} ;
127
126
128
127
Ok ( PreparedCardanoDbV2Download {
129
- shared_args : self . shared_args . clone ( ) ,
130
128
hash : self . digest . clone ( ) ,
131
129
download_dir : params. require ( "download_dir" ) ?,
132
130
start : self . start ,
@@ -138,8 +136,8 @@ impl CardanoDbDownloadCommand {
138
136
}
139
137
140
138
/// 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 ( ) {
143
141
let json = serde_json:: json!( {
144
142
JSON_CAUTION_KEY : "The fast bootstrap of the Cardano node is not available with the current parameters used in this command" ,
145
143
"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
165
163
}
166
164
}
167
165
168
- fn warn_ancillary_not_signed_by_mithril ( & self ) {
166
+ fn warn_ancillary_not_signed_by_mithril ( & self , context : & CommandContext ) {
169
167
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 ( ) {
171
169
eprintln ! ( r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"# ) ;
172
170
} else {
173
171
eprintln ! ( "{message}" ) ;
174
172
}
175
173
}
176
174
177
- fn warn_unused_parameter_with_v1_backend ( & self ) {
175
+ fn warn_unused_parameter_with_v1_backend ( & self , context : & CommandContext ) {
178
176
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 ( ) {
180
178
eprintln ! ( r#"{{"{JSON_CAUTION_KEY}":"{message}"}}"# ) ;
181
179
} else {
182
180
eprintln ! ( "{message}" ) ;
@@ -227,7 +225,6 @@ mod tests {
227
225
fn dummy_command ( ) -> CardanoDbDownloadCommand {
228
226
CardanoDbDownloadCommand {
229
227
backend : Default :: default ( ) ,
230
- shared_args : SharedArgs { json : false } ,
231
228
digest : "whatever_digest" . to_string ( ) ,
232
229
download_dir : Some ( std:: path:: PathBuf :: from ( "whatever_dir" ) ) ,
233
230
genesis_verification_key : "whatever" . to_string ( ) . into ( ) ,
@@ -249,6 +246,7 @@ mod tests {
249
246
let command_context = CommandContext :: new (
250
247
ConfigBuilder :: default ( ) ,
251
248
false ,
249
+ true ,
252
250
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
253
251
) ;
254
252
@@ -274,14 +272,14 @@ mod tests {
274
272
. set_default ( "ancillary_verification_key" , "value from config" )
275
273
. expect ( "Failed to build config builder" ) ;
276
274
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!( ) ) ) ;
278
276
let config_parameters = command_context
279
277
. config_parameters ( )
280
278
. unwrap ( )
281
279
. add_source ( & command)
282
280
. unwrap ( ) ;
283
281
284
- let result = command. prepare_v1 ( & config_parameters) ;
282
+ let result = command. prepare_v1 ( & config_parameters, & command_context ) ;
285
283
286
284
assert ! ( result. is_ok( ) ) ;
287
285
}
@@ -292,9 +290,10 @@ mod tests {
292
290
download_dir : None ,
293
291
..dummy_command ( )
294
292
} ;
295
- let command_context = CommandContext :: new (
293
+ let command_context = & CommandContext :: new (
296
294
ConfigBuilder :: default ( ) ,
297
295
false ,
296
+ true ,
298
297
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
299
298
) ;
300
299
let config_parameters = command_context
@@ -303,7 +302,7 @@ mod tests {
303
302
. add_source ( & command)
304
303
. unwrap ( ) ;
305
304
306
- let result = command. prepare_v1 ( & config_parameters) ;
305
+ let result = command. prepare_v1 ( & config_parameters, command_context ) ;
307
306
308
307
assert ! ( result. is_err( ) ) ;
309
308
assert_eq ! (
@@ -326,14 +325,14 @@ mod tests {
326
325
. set_default ( "ancillary_verification_key" , "value from config" )
327
326
. expect ( "Failed to build config builder" ) ;
328
327
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!( ) ) ) ;
330
329
let config_parameters = command_context
331
330
. config_parameters ( )
332
331
. unwrap ( )
333
332
. add_source ( & command)
334
333
. unwrap ( ) ;
335
334
336
- let result = command. prepare_v2 ( & config_parameters) ;
335
+ let result = command. prepare_v2 ( & config_parameters, & command_context ) ;
337
336
338
337
assert ! ( result. is_ok( ) ) ;
339
338
}
@@ -347,6 +346,7 @@ mod tests {
347
346
let command_context = CommandContext :: new (
348
347
ConfigBuilder :: default ( ) ,
349
348
false ,
349
+ true ,
350
350
Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
351
351
) ;
352
352
let config_parameters = command_context
@@ -355,7 +355,7 @@ mod tests {
355
355
. add_source ( & command)
356
356
. unwrap ( ) ;
357
357
358
- let result = command. prepare_v2 ( & config_parameters) ;
358
+ let result = command. prepare_v2 ( & config_parameters, & command_context ) ;
359
359
360
360
assert ! ( result. is_err( ) ) ;
361
361
assert_eq ! (
0 commit comments