gateway_cli/
config_commands.rs

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