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, set_mnemonic, set_payment_policy};
6use fedimint_gateway_common::{
7 ConfigPayload, SetFeesPayload, SetMnemonicPayload, SetPaymentPolicyPayload,
8};
9use fedimint_ln_common::client::GatewayApi;
10
11use crate::{CliOutput, CliOutputResult};
12
13#[derive(Subcommand)]
16pub enum ConfigCommands {
17 ClientConfig {
19 #[clap(long)]
20 federation_id: Option<FederationId>,
21 },
22 Display {
24 #[clap(long)]
25 federation_id: Option<FederationId>,
26 },
27 SetFees {
29 #[clap(long)]
30 federation_id: Option<FederationId>,
31
32 #[clap(long)]
33 ln_base: Option<Amount>,
34
35 #[clap(long)]
36 ln_ppm: Option<u64>,
37
38 #[clap(long)]
39 tx_base: Option<Amount>,
40
41 #[clap(long)]
42 tx_ppm: Option<u64>,
43 },
44 SetPaymentPolicy {
48 #[clap(long)]
49 federation_id: Option<FederationId>,
50
51 #[clap(long)]
55 receive_enabled: Option<bool>,
56 },
57 SetMnemonic {
60 #[clap(long)]
62 words: Option<String>,
63 #[clap(long)]
65 words_file: Option<std::path::PathBuf>,
66 },
67}
68
69impl ConfigCommands {
70 pub async fn handle(self, client: &GatewayApi, base_url: &SafeUrl) -> CliOutputResult {
71 match self {
72 Self::ClientConfig { federation_id } => {
73 let response =
74 get_config(client, base_url, ConfigPayload { federation_id }).await?;
75
76 Ok(CliOutput::Config(response))
77 }
78 Self::Display { federation_id } => {
79 let info = get_info(client, base_url).await?;
80 let federations = info
81 .federations
82 .into_iter()
83 .filter_map(|f| match federation_id {
84 Some(id) if id == f.federation_id => Some(f.config),
85 Some(_) => None,
86 None => Some(f.config),
87 })
88 .collect::<Vec<_>>();
89 Ok(CliOutput::FederationConfigs(federations))
90 }
91 Self::SetFees {
92 federation_id,
93 ln_base,
94 ln_ppm,
95 tx_base,
96 tx_ppm,
97 } => {
98 set_fees(
99 client,
100 base_url,
101 SetFeesPayload {
102 federation_id,
103 lightning_base: ln_base,
104 lightning_parts_per_million: ln_ppm,
105 transaction_base: tx_base,
106 transaction_parts_per_million: tx_ppm,
107 },
108 )
109 .await?;
110 Ok(CliOutput::Empty)
111 }
112 Self::SetPaymentPolicy {
113 federation_id,
114 receive_enabled,
115 } => {
116 set_payment_policy(
117 client,
118 base_url,
119 SetPaymentPolicyPayload {
120 federation_id,
121 receive_enabled,
122 },
123 )
124 .await?;
125 Ok(CliOutput::Empty)
126 }
127 Self::SetMnemonic { words, .. } => {
128 set_mnemonic(client, base_url, SetMnemonicPayload { words }).await?;
129 Ok(CliOutput::Empty)
130 }
131 }
132 }
133}