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