ckb_app_config/
args.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
use crate::{CKBAppConfig, MemoryTrackerConfig, MinerConfig};
use ckb_chain_spec::consensus::Consensus;
use ckb_jsonrpc_types::ScriptHashType;
use ckb_pow::PowEngine;
use ckb_systemtime::unix_time_as_millis;
use ckb_types::packed::Byte32;
use std::path::PathBuf;
use std::sync::Arc;

/// Parsed command line arguments for `ckb export`.
pub struct ExportArgs {
    /// Parsed `ckb.toml`.
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// The target directory to save the exported file.
    pub target: PathBuf,
}

#[derive(Debug)]
/// Parsed command line arguments for `ckb daemon`.
pub struct DaemonArgs {
    /// Check the daemon status
    pub check: bool,
    /// Stop daemon process
    pub stop: bool,
    /// The pid file path
    pub pid_file: PathBuf,
}

/// Parsed command line arguments for `ckb import`.
pub struct ImportArgs {
    /// Parsed `ckb.toml`.
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// The path to the file to be imported.
    pub source: PathBuf,
}

/// Parsed command line arguments for `ckb run`.
pub struct RunArgs {
    /// Parsed `ckb.toml`.
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// Whether allow advanced block assembler options.
    pub block_assembler_advanced: bool,
    /// Whether skip chain spec hash check
    pub skip_chain_spec_check: bool,
    /// Whether overwrite the chain spec hash in the database with [`RunArgs::chain_spec_hash`]
    ///
    /// [`RunArgs::chain_spec_hash`]: ./struct.RunArgs.html#structfield.chain_spec_hash
    pub overwrite_chain_spec: bool,
    /// Hash of serialized configured chain spec
    pub chain_spec_hash: Byte32,
    /// Whether start indexer, default false
    pub indexer: bool,
    /// Whether start rich-indexer, default false
    pub rich_indexer: bool,
    /// Whether start in daemon mode
    #[cfg(not(target_os = "windows"))]
    pub daemon: bool,
}

/// Enable profile on blocks in the range `[from, to]`.
pub type ProfileArgs = Option<(Option<u64>, Option<u64>)>;

/// Parsed command line arguments for `ckb replay`.
pub struct ReplayArgs {
    /// Parsed `ckb.toml`.
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// The directory to store the temporary files during the replay.
    pub tmp_target: PathBuf,
    /// Enable profile on blocks in the range `[from, to]`.
    pub profile: ProfileArgs,
    /// Enable sanity check.
    pub sanity_check: bool,
    /// Enable full verification.
    pub full_verification: bool,
}

/// Parsed command line arguments for `ckb miner`.
pub struct MinerArgs {
    /// Parsed `ckb-miner.toml`.
    pub config: MinerConfig,
    /// Selected PoW algorithm.
    pub pow_engine: Arc<dyn PowEngine>,
    /// Options to configure the memory tracker.
    pub memory_tracker: MemoryTrackerConfig,
    /// The miner process will exit when there are `limit` nonces (puzzle solutions) found. Set it
    /// to 0 to loop forever.
    pub limit: u128,
}

/// Parsed command line arguments for `ckb stats`.
pub struct StatsArgs {
    /// Parsed `ckb.toml`.
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// Specifies the starting block number. The default is 1.
    pub from: Option<u64>,
    /// Specifies the ending block number. The default is the tip block in the database.
    pub to: Option<u64>,
}

/// Parsed command line arguments for `ckb init`.
pub struct InitArgs {
    /// Whether to prompt user inputs interactively.
    pub interactive: bool,
    /// The CKB root directory.
    pub root_dir: PathBuf,
    /// The chain name that this node will join.
    pub chain: String,
    /// RPC port.
    pub rpc_port: String,
    /// P2P port.
    pub p2p_port: String,
    /// Whether to save the logs into the log file.
    pub log_to_file: bool,
    /// Whether to print the logs on the process stdout.
    pub log_to_stdout: bool,
    /// Asks to list available chains.
    pub list_chains: bool,
    /// Force file overwriting.
    pub force: bool,
    /// Block assembler lock script code hash.
    pub block_assembler_code_hash: Option<String>,
    /// Block assembler lock script args.
    pub block_assembler_args: Vec<String>,
    /// Block assembler lock script hash type.
    pub block_assembler_hash_type: ScriptHashType,
    /// Block assembler cellbase transaction message.
    pub block_assembler_message: Option<String>,
    /// Import the spec file.
    ///
    /// When this is set to `-`, the spec file is imported from stdin and the file content must be
    /// encoded by base64. Otherwise it must be a path to the spec file.
    ///
    /// The spec file will be saved into `specs/{CHAIN}.toml`, where `CHAIN` is the chain name.
    pub import_spec: Option<String>,
    /// Customize parameters for chain spec or not.
    ///
    /// Only works for dev chains.
    pub customize_spec: CustomizeSpec,
}

/// Customize parameters for chain spec.
pub struct CustomizeSpec {
    /// Specify a string as the genesis message.
    pub genesis_message: Option<String>,
}

/// Parsed command line arguments for `ckb reset-data`.
pub struct ResetDataArgs {
    /// Reset without asking for user confirmation.
    pub force: bool,
    /// Reset all data.
    pub all: bool,
    /// Reset database.
    pub database: bool,
    /// Reset indexer.
    pub indexer: bool,
    /// Reset rich-indexer.
    pub rich_indexer: bool,
    /// Reset all network data, including the secret key and peer store.
    pub network: bool,
    /// Reset network peer store.
    pub network_peer_store: bool,
    /// Reset network secret key.
    pub network_secret_key: bool,
    /// Clean logs directory.
    pub logs: bool,
    /// The path to the CKB data directory.
    pub data_dir: PathBuf,
    /// The path to the database directory.
    pub db_path: PathBuf,
    /// The path to the indexer directory.
    pub indexer_path: PathBuf,
    /// The path to the rich-indexer directory.
    pub rich_indexer_path: PathBuf,
    /// The path to the network data directory.
    pub network_dir: PathBuf,
    /// The path to the network peer store directory.
    pub network_peer_store_path: PathBuf,
    /// The path to the network secret key.
    pub network_secret_key_path: PathBuf,
    /// The path to the logs directory.
    pub logs_dir: Option<PathBuf>,
}

/// Parsed command line arguments for `ckb peer-id`.
pub struct PeerIDArgs {
    /// The peer ID read from the secret key file.
    pub peer_id: secio::PeerId,
}

/// Parsed command line arguments for `ckb migrate`.
pub struct MigrateArgs {
    /// The parsed `ckb.toml.`
    pub config: Box<CKBAppConfig>,
    /// Loaded consensus.
    pub consensus: Consensus,
    /// Check whether it is required to do migration instead of really perform the migration.
    pub check: bool,
    /// Do migration without interactive prompt.
    pub force: bool,
    /// Whether include background migrations
    pub include_background: bool,
}

impl CustomizeSpec {
    /// No specified parameters for chain spec.
    pub fn is_unset(&self) -> bool {
        self.genesis_message.is_none()
    }

    /// Generates a vector of key-value pairs.
    pub fn key_value_pairs(&self) -> Vec<(&'static str, String)> {
        let mut vec = Vec::new();
        let genesis_message = self
            .genesis_message
            .clone()
            .unwrap_or_else(|| unix_time_as_millis().to_string());
        vec.push(("genesis_message", genesis_message));
        vec
    }
}