Skip to main content

ckb_app_config/
args.rs

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