1use std::path::PathBuf;
12
13use clap::{Parser, ValueHint};
14use internet2::addr::ServiceAddr;
15use lnpbp::chain::Chain;
16use store_rpc::STORED_RPC_ENDPOINT;
17
18#[cfg(any(target_os = "linux"))]
19pub const RGB_NODE_DATA_DIR: &str = "~/.rgb_node";
20#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
21pub const RGB_NODE_DATA_DIR: &str = "~/.rgb_node";
22#[cfg(target_os = "macos")]
23pub const RGB_NODE_DATA_DIR: &str = "~/Library/Application Support/RGB Node";
24#[cfg(target_os = "windows")]
25pub const RGB_NODE_DATA_DIR: &str = "~\\AppData\\Local\\RGB Node";
26#[cfg(target_os = "ios")]
27pub const RGB_NODE_DATA_DIR: &str = "~/Documents";
28#[cfg(target_os = "android")]
29pub const RGB_NODE_DATA_DIR: &str = ".";
30
31pub const RGB_NODE_CTL_ENDPOINT: &str = "{data_dir}/ctl";
32
33pub const RGB_NODE_CONFIG: &str = "{data_dir}/rgb_node.toml";
34
35#[derive(Parser)]
37#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
38pub struct Opts {
39 #[clap(short, long, global = true, parse(from_occurrences))]
43 pub verbose: u8,
44
45 #[clap(
50 short,
51 long,
52 global = true,
53 default_value = RGB_NODE_DATA_DIR,
54 env = "RGB_NODE_DATA_DIR",
55 value_hint = ValueHint::DirPath
56 )]
57 pub data_dir: PathBuf,
58
59 #[clap(
61 short = 'S',
62 long = "store",
63 global = true,
64 env = "STORED_RPC_ENDPOINT",
65 default_value = STORED_RPC_ENDPOINT,
66 value_hint = ValueHint::FilePath
67 )]
68 pub store_endpoint: ServiceAddr,
69
70 #[clap(
82 short = 'X',
83 long = "ctl",
84 global = true,
85 env = "RGB_NODE_CTL_ENDPOINT",
86 default_value = RGB_NODE_CTL_ENDPOINT,
87 value_hint = ValueHint::FilePath
88 )]
89 pub ctl_endpoint: ServiceAddr,
90
91 #[clap(
93 short = 'n',
94 long,
95 global = true,
96 alias = "network",
97 default_value = "signet",
98 env = "RGB_NODE_NETWORK"
99 )]
100 pub chain: Chain,
101
102 #[clap(
104 long,
105 global = true,
106 default_value("blockstream.info"),
107 env = "RGB_NODE_ELECTRUM_SERVER",
108 value_hint = ValueHint::Hostname
109 )]
110 pub electrum_server: String,
111
112 #[clap(long, global = true, env = "RGB_NODE_ELECTRUM_PORT")]
115 pub electrum_port: Option<u16>,
116}
117
118#[cfg(feature = "server")]
119impl Opts {
120 pub fn process<'s>(&'s mut self, other: impl IntoIterator<Item = &'s mut ServiceAddr>) {
121 let mut services = vec![&mut self.ctl_endpoint, &mut self.store_endpoint];
122 services.extend(other);
123 microservices::shell::shell_setup(self.verbose, services, &mut self.data_dir, &[(
124 "{chain}",
125 self.chain.to_string(),
126 )]);
127 }
128}