soroban_cli/commands/
fee_stats.rs

1use crate::{commands::global, config::network, rpc};
2
3#[derive(thiserror::Error, Debug)]
4pub enum Error {
5    #[error(transparent)]
6    Serde(#[from] serde_json::Error),
7    #[error(transparent)]
8    Network(#[from] network::Error),
9    #[error(transparent)]
10    Rpc(#[from] rpc::Error),
11}
12
13#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum, Default)]
14pub enum OutputFormat {
15    /// Text output of network info
16    #[default]
17    Text,
18    /// JSON result of the RPC request
19    Json,
20    /// Formatted (multiline) JSON output of the RPC request
21    JsonFormatted,
22}
23
24#[derive(Debug, clap::Parser)]
25pub struct Cmd {
26    #[command(flatten)]
27    pub network: network::Args,
28
29    /// Format of the output
30    #[arg(long, value_enum, default_value_t)]
31    pub output: OutputFormat,
32}
33
34impl Cmd {
35    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
36        let network = self.network.get(&global_args.locator)?;
37        let client = network.rpc_client()?;
38        let fee_stats = client.get_fee_stats().await?;
39
40        match self.output {
41            OutputFormat::Text => {
42                println!(
43                    "Max Soroban Inclusion Fee: {}",
44                    fee_stats.soroban_inclusion_fee.max
45                );
46                println!("Max Inclusion Fee: {}", fee_stats.inclusion_fee.max);
47                println!("Latest Ledger: {}", fee_stats.latest_ledger);
48            }
49            OutputFormat::Json => println!("{}", serde_json::to_string(&fee_stats)?),
50            OutputFormat::JsonFormatted => {
51                println!("{}", serde_json::to_string_pretty(&fee_stats)?);
52            }
53        }
54
55        Ok(())
56    }
57}