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