ckb_app_config/
args.rs

1use crate::{CKBAppConfig, MemoryTrackerConfig, MinerConfig};
2use ckb_chain_spec::consensus::Consensus;
3use ckb_jsonrpc_types::ScriptHashType;
4use ckb_pow::PowEngine;
5use ckb_systemtime::unix_time_as_millis;
6use ckb_types::packed::Byte32;
7use std::path::PathBuf;
8use std::sync::Arc;
9
10/// Parsed command line arguments for `ckb export`.
11pub struct ExportArgs {
12    /// Parsed `ckb.toml`.
13    pub config: Box<CKBAppConfig>,
14    /// Loaded consensus.
15    pub consensus: Consensus,
16    /// The target directory to save the exported file.
17    pub target: PathBuf,
18}
19
20#[derive(Debug)]
21/// Parsed command line arguments for `ckb daemon`.
22pub struct DaemonArgs {
23    /// Check the daemon status
24    pub check: bool,
25    /// Stop daemon process
26    pub stop: bool,
27    /// The pid file path
28    pub pid_file: PathBuf,
29}
30
31/// Parsed command line arguments for `ckb import`.
32pub struct ImportArgs {
33    /// Parsed `ckb.toml`.
34    pub config: Box<CKBAppConfig>,
35    /// Loaded consensus.
36    pub consensus: Consensus,
37    /// The path to the file to be imported.
38    pub source: PathBuf,
39}
40
41/// Parsed command line arguments for `ckb run`.
42pub struct RunArgs {
43    /// Parsed `ckb.toml`.
44    pub config: Box<CKBAppConfig>,
45    /// Loaded consensus.
46    pub consensus: Consensus,
47    /// Whether allow advanced block assembler options.
48    pub block_assembler_advanced: bool,
49    /// Whether skip chain spec hash check
50    pub skip_chain_spec_check: bool,
51    /// Whether overwrite the chain spec hash in the database with [`RunArgs::chain_spec_hash`]
52    ///
53    /// [`RunArgs::chain_spec_hash`]: ./struct.RunArgs.html#structfield.chain_spec_hash
54    pub overwrite_chain_spec: bool,
55    /// Hash of serialized configured chain spec
56    pub chain_spec_hash: Byte32,
57    /// Whether start indexer, default false
58    pub indexer: bool,
59    /// Whether start rich-indexer, default false
60    pub rich_indexer: bool,
61    /// Whether start in daemon mode
62    #[cfg(not(target_os = "windows"))]
63    pub daemon: bool,
64}
65
66/// Enable profile on blocks in the range `[from, to]`.
67pub type ProfileArgs = Option<(Option<u64>, Option<u64>)>;
68
69/// Parsed command line arguments for `ckb replay`.
70pub struct ReplayArgs {
71    /// Parsed `ckb.toml`.
72    pub config: Box<CKBAppConfig>,
73    /// Loaded consensus.
74    pub consensus: Consensus,
75    /// The directory to store the temporary files during the replay.
76    pub tmp_target: PathBuf,
77    /// Enable profile on blocks in the range `[from, to]`.
78    pub profile: ProfileArgs,
79    /// Enable sanity check.
80    pub sanity_check: bool,
81    /// Enable full verification.
82    pub full_verification: bool,
83}
84
85/// Parsed command line arguments for `ckb miner`.
86pub struct MinerArgs {
87    /// Parsed `ckb-miner.toml`.
88    pub config: MinerConfig,
89    /// Selected PoW algorithm.
90    pub pow_engine: Arc<dyn PowEngine>,
91    /// Options to configure the memory tracker.
92    pub memory_tracker: MemoryTrackerConfig,
93    /// The miner process will exit when there are `limit` nonces (puzzle solutions) found. Set it
94    /// to 0 to loop forever.
95    pub limit: u128,
96}
97
98/// Parsed command line arguments for `ckb stats`.
99pub struct StatsArgs {
100    /// Parsed `ckb.toml`.
101    pub config: Box<CKBAppConfig>,
102    /// Loaded consensus.
103    pub consensus: Consensus,
104    /// Specifies the starting block number. The default is 1.
105    pub from: Option<u64>,
106    /// Specifies the ending block number. The default is the tip block in the database.
107    pub to: Option<u64>,
108}
109
110/// Parsed command line arguments for `ckb init`.
111pub struct InitArgs {
112    /// Whether to prompt user inputs interactively.
113    pub interactive: bool,
114    /// The CKB root directory.
115    pub root_dir: PathBuf,
116    /// The chain name that this node will join.
117    pub chain: String,
118    /// RPC port.
119    pub rpc_port: String,
120    /// P2P port.
121    pub p2p_port: String,
122    /// Whether to save the logs into the log file.
123    pub log_to_file: bool,
124    /// Whether to print the logs on the process stdout.
125    pub log_to_stdout: bool,
126    /// Asks to list available chains.
127    pub list_chains: bool,
128    /// Force file overwriting.
129    pub force: bool,
130    /// Block assembler lock script code hash.
131    pub block_assembler_code_hash: Option<String>,
132    /// Block assembler lock script args.
133    pub block_assembler_args: Vec<String>,
134    /// Block assembler lock script hash type.
135    pub block_assembler_hash_type: ScriptHashType,
136    /// Block assembler cellbase transaction message.
137    pub block_assembler_message: Option<String>,
138    /// Import the spec file.
139    ///
140    /// When this is set to `-`, the spec file is imported from stdin and the file content must be
141    /// encoded by base64. Otherwise it must be a path to the spec file.
142    ///
143    /// The spec file will be saved into `specs/{CHAIN}.toml`, where `CHAIN` is the chain name.
144    pub import_spec: Option<String>,
145    /// Customize parameters for chain spec or not.
146    ///
147    /// Only works for dev chains.
148    pub customize_spec: CustomizeSpec,
149}
150
151/// Customize parameters for chain spec.
152pub struct CustomizeSpec {
153    /// Specify a string as the genesis message.
154    pub genesis_message: Option<String>,
155}
156
157/// Parsed command line arguments for `ckb reset-data`.
158pub struct ResetDataArgs {
159    /// Reset without asking for user confirmation.
160    pub force: bool,
161    /// Reset all data.
162    pub all: bool,
163    /// Reset database.
164    pub database: bool,
165    /// Reset indexer.
166    pub indexer: bool,
167    /// Reset rich-indexer.
168    pub rich_indexer: bool,
169    /// Reset all network data, including the secret key and peer store.
170    pub network: bool,
171    /// Reset network peer store.
172    pub network_peer_store: bool,
173    /// Reset network secret key.
174    pub network_secret_key: bool,
175    /// Clean logs directory.
176    pub logs: bool,
177    /// The path to the CKB data directory.
178    pub data_dir: PathBuf,
179    /// The path to the database directory.
180    pub db_path: PathBuf,
181    /// The path to the indexer directory.
182    pub indexer_path: PathBuf,
183    /// The path to the rich-indexer directory.
184    pub rich_indexer_path: PathBuf,
185    /// The path to the network data directory.
186    pub network_dir: PathBuf,
187    /// The path to the network peer store directory.
188    pub network_peer_store_path: PathBuf,
189    /// The path to the network secret key.
190    pub network_secret_key_path: PathBuf,
191    /// The path to the logs directory.
192    pub logs_dir: Option<PathBuf>,
193}
194
195/// Parsed command line arguments for `ckb peer-id`.
196pub struct PeerIDArgs {
197    /// The peer ID read from the secret key file.
198    pub peer_id: secio::PeerId,
199}
200
201/// Parsed command line arguments for `ckb migrate`.
202pub struct MigrateArgs {
203    /// The parsed `ckb.toml.`
204    pub config: Box<CKBAppConfig>,
205    /// Loaded consensus.
206    pub consensus: Consensus,
207    /// Check whether it is required to do migration instead of really perform the migration.
208    pub check: bool,
209    /// Do migration without interactive prompt.
210    pub force: bool,
211    /// Whether include background migrations
212    pub include_background: bool,
213}
214
215impl CustomizeSpec {
216    /// No specified parameters for chain spec.
217    pub fn is_unset(&self) -> bool {
218        self.genesis_message.is_none()
219    }
220
221    /// Generates a vector of key-value pairs.
222    pub fn key_value_pairs(&self) -> Vec<(&'static str, String)> {
223        let mut vec = Vec::new();
224        let genesis_message = self
225            .genesis_message
226            .clone()
227            .unwrap_or_else(|| unix_time_as_millis().to_string());
228        vec.push(("genesis_message", genesis_message));
229        vec
230    }
231}