use std::net::SocketAddr;
use std::path::PathBuf;
use bitcoin::Network;
use clap::Parser;
use fedimint_core::util::SafeUrl;
use fedimint_ln_common::config::GatewayFee;
use super::envs;
use super::lightning::LightningMode;
use super::rpc::V1_API_ENDPOINT;
#[derive(Parser)]
#[command(version)]
pub struct GatewayOpts {
#[clap(subcommand)]
pub mode: LightningMode,
#[arg(long = "data-dir", env = envs::FM_GATEWAY_DATA_DIR_ENV)]
pub data_dir: PathBuf,
#[arg(long = "listen", env = envs::FM_GATEWAY_LISTEN_ADDR_ENV)]
listen: SocketAddr,
#[arg(long = "api-addr", env = envs::FM_GATEWAY_API_ADDR_ENV)]
api_addr: SafeUrl,
#[arg(long = "password", env = envs::FM_GATEWAY_PASSWORD_ENV)]
password: Option<String>,
#[arg(long = "network", env = envs::FM_GATEWAY_NETWORK_ENV)]
network: Option<Network>,
#[arg(long = "fees", env = envs::FM_GATEWAY_FEES_ENV)]
fees: Option<GatewayFee>,
#[arg(
long = "num-route-hints",
env = envs::FM_NUMBER_OF_ROUTE_HINTS_ENV,
default_value_t = super::DEFAULT_NUM_ROUTE_HINTS
)]
num_route_hints: u32,
}
impl GatewayOpts {
pub fn to_gateway_parameters(&self) -> anyhow::Result<GatewayParameters> {
let versioned_api = self.api_addr.join(V1_API_ENDPOINT).map_err(|e| {
anyhow::anyhow!(
"Failed to version gateway API address: {api_addr:?}, error: {e:?}",
api_addr = self.api_addr,
)
})?;
Ok(GatewayParameters {
listen: self.listen,
versioned_api,
password: self.password.clone(),
network: self.network,
num_route_hints: self.num_route_hints,
fees: self.fees.clone(),
})
}
}
#[derive(Clone, Debug)]
pub struct GatewayParameters {
pub listen: SocketAddr,
pub versioned_api: SafeUrl,
pub password: Option<String>,
pub network: Option<Network>,
pub num_route_hints: u32,
pub fees: Option<GatewayFee>,
}