gateway_cli/
config_commands.rs1use 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};
6use fedimint_gateway_common::{ConfigPayload, SetFeesPayload};
7use fedimint_ln_common::client::GatewayApi;
8
9use crate::print_response;
10
11#[derive(Subcommand)]
12pub enum ConfigCommands {
13 ClientConfig {
15 #[clap(long)]
16 federation_id: Option<FederationId>,
17 },
18 Display {
20 #[clap(long)]
21 federation_id: Option<FederationId>,
22 },
23 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}
41
42impl ConfigCommands {
43 pub async fn handle(self, client: &GatewayApi, base_url: &SafeUrl) -> anyhow::Result<()> {
44 match self {
45 Self::ClientConfig { federation_id } => {
46 let response =
47 get_config(client, base_url, ConfigPayload { federation_id }).await?;
48
49 print_response(response);
50 }
51 Self::Display { federation_id } => {
52 let info = get_info(client, base_url).await?;
53 let federations = info
54 .federations
55 .into_iter()
56 .filter_map(|f| match federation_id {
57 Some(id) if id == f.federation_id => Some(f.config),
58 Some(_) => None,
59 None => Some(f.config),
60 })
61 .collect::<Vec<_>>();
62 print_response(federations);
63 }
64 Self::SetFees {
65 federation_id,
66 ln_base,
67 ln_ppm,
68 tx_base,
69 tx_ppm,
70 } => {
71 set_fees(
72 client,
73 base_url,
74 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 )
82 .await?;
83 }
84 }
85
86 Ok(())
87 }
88}