rgb_node/
opts.rs

1// RGB node providing smart contracts functionality for Bitcoin & Lightning.
2//
3// Written in 2022 by
4//     Dr. Maxim Orlovsky <orlovsky@lnp-bp.org>
5//
6// Copyright (C) 2022 by LNP/BP Standards Association, Switzerland.
7//
8// You should have received a copy of the MIT License along with this software.
9// If not, see <https://opensource.org/licenses/MIT>.
10
11use 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/// Command-line arguments
36#[derive(Parser)]
37#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
38pub struct Opts {
39    /// Set verbosity level.
40    ///
41    /// Can be used multiple times to increase verbosity
42    #[clap(short, long, global = true, parse(from_occurrences))]
43    pub verbose: u8,
44
45    /// Data directory path.
46    ///
47    /// Path to the directory that contains stored data, and where ZMQ RPC
48    /// socket files are located
49    #[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    /// ZMQ socket for connecting storage daemon.
60    #[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    /// ZMQ socket for internal service bus.
71    ///
72    /// A user needs to specify this socket usually if it likes to distribute daemons
73    /// over different server instances. In this case all daemons within the same node
74    /// must use the same socket address.
75    ///
76    /// Socket can be either TCP address in form of `<ipv4 | ipv6>:<port>` – or a path
77    /// to an IPC file.
78    ///
79    /// Defaults to `ctl` file inside `--data-dir` directory, unless `--threaded-daemons`
80    /// is specified; in that cases uses in-memory communication protocol.
81    #[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    /// Blockchain to use
92    #[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    /// Electrum server to use.
103    #[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    /// Customize Electrum server port number. By default the wallet will use port
113    /// matching the selected network.
114    #[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}