Skip to content

Commit ba7df39

Browse files
Seonpyo Kimmergify[bot]
authored andcommitted
Add base-path option to the codechin cli arguments
1 parent 1a0b239 commit ba7df39

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

codechain/codechain.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ args:
5050
long: chain
5151
help: Set the blockchain type out of solo, simple_poa, tendermint, cuckoo, blake_pow, corgi, mainnet or a path to chain scheme file.
5252
takes_value: true
53+
- base-path:
54+
long: base-path
55+
value_name: PATH
56+
help: Specify the base directory path on which the "db" and "keys" directory will be created.
57+
takes_value: true
5358
- db-path:
5459
long: db-path
5560
value_name: PATH

codechain/config/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub struct Ipc {
202202
pub struct Operating {
203203
pub quiet: Option<bool>,
204204
pub instance_id: Option<usize>,
205+
pub base_path: Option<String>,
205206
pub db_path: Option<String>,
206207
pub keys_path: Option<String>,
207208
pub password_path: Option<String>,
@@ -314,6 +315,9 @@ impl Operating {
314315
if other.instance_id.is_some() {
315316
self.instance_id = other.instance_id;
316317
}
318+
if other.base_path.is_some() {
319+
self.base_path = other.base_path.clone();
320+
}
317321
if other.db_path.is_some() {
318322
self.db_path = other.db_path.clone();
319323
}
@@ -335,6 +339,9 @@ impl Operating {
335339
if let Some(instance_id) = matches.value_of("instance-id") {
336340
self.instance_id = Some(instance_id.parse().map_err(|e| format!("{}", e))?);
337341
}
342+
if let Some(base_path) = matches.value_of("base-path") {
343+
self.base_path = Some(base_path.to_string());
344+
}
338345
if let Some(db_path) = matches.value_of("db-path") {
339346
self.db_path = Some(db_path.to_string());
340347
}

codechain/config/presets/config.dev.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[codechain]
22
quiet = false
3-
db_path = "db"
4-
keys_path = "keys"
3+
base_path = "."
54
chain = "solo"
65

76
[mining]

codechain/config/presets/config.prod.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[codechain]
22
quiet = false
3-
db_path = "db"
4-
keys_path = "keys"
3+
base_path = "."
54
chain = "mainnet"
65

76
[mining]

codechain/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
pub const DEFAULT_KEYS_PATH: &str = "keys";
18+
pub const DEFAULT_DB_PATH: &str = "db";

codechain/run_node.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use kvdb_rocksdb::{Database, DatabaseConfig};
4141
use parking_lot::{Condvar, Mutex};
4242

4343
use crate::config::{self, load_config};
44-
use crate::constants::DEFAULT_KEYS_PATH;
44+
use crate::constants::{DEFAULT_DB_PATH, DEFAULT_KEYS_PATH};
4545
use crate::dummy_network_service::DummyNetworkService;
4646
use crate::json::PasswordFile;
4747
use crate::rpc::{rpc_http_start, rpc_ipc_start, rpc_ws_start};
@@ -202,8 +202,9 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
202202
}
203203

204204
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<KeyValueDB>, String> {
205-
let db_path = cfg.db_path.as_ref().map(String::as_str).unwrap();
206-
let client_path = Path::new(db_path);
205+
let base_path = cfg.base_path.as_ref().unwrap().clone();
206+
let db_path = cfg.db_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_DB_PATH);
207+
let client_path = Path::new(&db_path);
207208
let mut db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
208209

209210
db_config.memory_budget = client_config.db_cache_size;
@@ -251,11 +252,10 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
251252
clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized");
252253

253254
let pf = load_password_file(&config.operating.password_path)?;
254-
let keys_path = match config.operating.keys_path {
255-
Some(ref keys_path) => keys_path,
256-
None => DEFAULT_KEYS_PATH,
257-
};
258-
let ap = prepare_account_provider(keys_path)?;
255+
let base_path = config.operating.base_path.as_ref().unwrap().clone();
256+
let keys_path =
257+
config.operating.keys_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_KEYS_PATH);
258+
let ap = prepare_account_provider(&keys_path)?;
259259
unlock_accounts(&*ap, &pf)?;
260260

261261
let client_config: ClientConfig = Default::default();

0 commit comments

Comments
 (0)