use std::path::PathBuf;
use clap::{Parser, ValueHint};
use internet2::addr::ServiceAddr;
use lnpbp::chain::Chain;
use store_rpc::STORED_RPC_ENDPOINT;
#[cfg(any(target_os = "linux"))]
pub const RGB_NODE_DATA_DIR: &str = "~/.rgb_node";
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
pub const RGB_NODE_DATA_DIR: &str = "~/.rgb_node";
#[cfg(target_os = "macos")]
pub const RGB_NODE_DATA_DIR: &str = "~/Library/Application Support/RGB Node";
#[cfg(target_os = "windows")]
pub const RGB_NODE_DATA_DIR: &str = "~\\AppData\\Local\\RGB Node";
#[cfg(target_os = "ios")]
pub const RGB_NODE_DATA_DIR: &str = "~/Documents";
#[cfg(target_os = "android")]
pub const RGB_NODE_DATA_DIR: &str = ".";
pub const RGB_NODE_CTL_ENDPOINT: &str = "{data_dir}/ctl";
pub const RGB_NODE_CONFIG: &str = "{data_dir}/rgb_node.toml";
#[derive(Parser)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct Opts {
#[clap(short, long, global = true, parse(from_occurrences))]
pub verbose: u8,
#[clap(
short,
long,
global = true,
default_value = RGB_NODE_DATA_DIR,
env = "RGB_NODE_DATA_DIR",
value_hint = ValueHint::DirPath
)]
pub data_dir: PathBuf,
#[clap(
short = 'S',
long = "store",
global = true,
env = "STORED_RPC_ENDPOINT",
default_value = STORED_RPC_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub store_endpoint: ServiceAddr,
#[clap(
short = 'X',
long = "ctl",
global = true,
env = "RGB_NODE_CTL_ENDPOINT",
default_value = RGB_NODE_CTL_ENDPOINT,
value_hint = ValueHint::FilePath
)]
pub ctl_endpoint: ServiceAddr,
#[clap(
short = 'n',
long,
global = true,
alias = "network",
default_value = "signet",
env = "RGB_NODE_NETWORK"
)]
pub chain: Chain,
#[clap(
long,
global = true,
default_value("blockstream.info"),
env = "RGB_NODE_ELECTRUM_SERVER",
value_hint = ValueHint::Hostname
)]
pub electrum_server: String,
#[clap(long, global = true, env = "RGB_NODE_ELECTRUM_PORT")]
pub electrum_port: Option<u16>,
}
#[cfg(feature = "server")]
impl Opts {
pub fn process<'s>(&'s mut self, other: impl IntoIterator<Item = &'s mut ServiceAddr>) {
let mut services = vec![&mut self.ctl_endpoint, &mut self.store_endpoint];
services.extend(other);
microservices::shell::shell_setup(self.verbose, services, &mut self.data_dir, &[(
"{chain}",
self.chain.to_string(),
)]);
}
}