gateway_cli/
config_commands.rs

1use clap::Subcommand;
2use fedimint_core::Amount;
3use fedimint_core::config::FederationId;
4use fedimint_gateway_client::GatewayRpcClient;
5use fedimint_gateway_common::{ConfigPayload, SetFeesPayload};
6
7use crate::print_response;
8
9#[derive(Subcommand)]
10pub enum ConfigCommands {
11    /// Gets each connected federation's JSON client config
12    ClientConfig {
13        #[clap(long)]
14        federation_id: Option<FederationId>,
15    },
16    /// Gets the Gateway's configured configuration for each federation
17    Display {
18        #[clap(long)]
19        federation_id: Option<FederationId>,
20    },
21    /// Set the gateway's lightning or transaction fees
22    SetFees {
23        #[clap(long)]
24        federation_id: Option<FederationId>,
25
26        #[clap(long)]
27        ln_base: Option<Amount>,
28
29        #[clap(long)]
30        ln_ppm: Option<u64>,
31
32        #[clap(long)]
33        tx_base: Option<Amount>,
34
35        #[clap(long)]
36        tx_ppm: Option<u64>,
37    },
38}
39
40impl ConfigCommands {
41    pub async fn handle(
42        self,
43        create_client: impl Fn() -> GatewayRpcClient + Send + Sync,
44    ) -> anyhow::Result<()> {
45        match self {
46            Self::ClientConfig { federation_id } => {
47                let response = create_client()
48                    .get_config(ConfigPayload { federation_id })
49                    .await?;
50
51                print_response(response);
52            }
53            Self::Display { federation_id } => {
54                let info = create_client().get_info().await?;
55                let federations = info
56                    .federations
57                    .into_iter()
58                    .filter_map(|f| match federation_id {
59                        Some(id) if id == f.federation_id => Some(f.config),
60                        Some(_) => None,
61                        None => Some(f.config),
62                    })
63                    .collect::<Vec<_>>();
64                print_response(federations);
65            }
66            Self::SetFees {
67                federation_id,
68                ln_base,
69                ln_ppm,
70                tx_base,
71                tx_ppm,
72            } => {
73                create_client()
74                    .set_fees(SetFeesPayload {
75                        federation_id,
76                        lightning_base: ln_base,
77                        lightning_parts_per_million: ln_ppm,
78                        transaction_base: tx_base,
79                        transaction_parts_per_million: tx_ppm,
80                    })
81                    .await?;
82            }
83        }
84
85        Ok(())
86    }
87}