mithril_client_cli/commands/cardano_transaction/
snapshot_list.rs1use clap::Parser;
2use cli_table::format::Justify;
3use cli_table::{Cell, Table, print_stdout};
4
5use crate::CommandContext;
6use crate::commands::client_builder_with_fallback_genesis_key;
7use mithril_client::MithrilResult;
8
9#[derive(Parser, Debug, Clone)]
11pub struct CardanoTransactionSnapshotListCommand {}
12
13impl CardanoTransactionSnapshotListCommand {
14 pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
16 let client = client_builder_with_fallback_genesis_key(context.config_parameters())?
17 .with_logger(context.logger().clone())
18 .build()?;
19 let lines = client.cardano_transaction().list_snapshots().await?;
20
21 if context.is_json_output_enabled() {
22 println!("{}", serde_json::to_string(&lines)?);
23 } else {
24 let lines = lines
25 .into_iter()
26 .map(|item| {
27 vec![
28 format!("{}", item.epoch).cell(),
29 format!("{}", item.block_number).cell(),
30 item.hash.cell(),
31 item.certificate_hash.cell(),
32 item.created_at.to_string().cell(),
33 ]
34 })
35 .collect::<Vec<_>>()
36 .table()
37 .title(vec![
38 "Epoch".cell(),
39 "Block Number".cell(),
40 "Hash".cell(),
41 "Certificate Hash".cell(),
42 "Created".cell().justify(Justify::Right),
43 ]);
44 print_stdout(lines)?;
45 }
46
47 Ok(())
48 }
49}