Skip to content

Commit d1ac164

Browse files
committed
Introduce DEFAULT_KEYS_PATH constant
1 parent e4d78e6 commit d1ac164

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

codechain/account_command.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use ckeystore::KeyStore;
2424
use clap::ArgMatches;
2525
use clogger::{self, LoggerConfig};
2626

27+
use super::constants::DEFAULT_KEYS_PATH;
28+
2729
pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
2830
if matches.subcommand.is_none() {
2931
println!("{}", matches.usage());
@@ -32,7 +34,7 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
3234

3335
clogger::init(&LoggerConfig::new(0)).expect("Logger must be successfully initialized");
3436

35-
let keys_path = matches.value_of("keys-path").unwrap_or("keys");
37+
let keys_path = matches.value_of("keys-path").unwrap_or(DEFAULT_KEYS_PATH);
3638
let dir = RootDiskDirectory::create(keys_path).expect("Cannot read key path directory");
3739
let keystore = KeyStore::open(Box::new(dir)).unwrap();
3840
let ap = AccountProvider::new(keystore);

codechain/config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Operating {
5353
pub quiet: bool,
5454
pub instance_id: Option<usize>,
5555
pub db_path: String,
56-
pub keys_path: String,
56+
pub keys_path: Option<String>,
5757
pub chain: ChainType,
5858
}
5959

@@ -171,7 +171,7 @@ impl Operating {
171171
self.db_path = db_path.to_string();
172172
}
173173
if let Some(keys_path) = matches.value_of("keys-path") {
174-
self.keys_path = keys_path.to_string();
174+
self.keys_path = Some(keys_path.to_string());
175175
}
176176
if let Some(chain) = matches.value_of("chain") {
177177
self.chain = chain.parse()?;

codechain/constants.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
pub const DEFAULT_KEYS_PATH: &'static str = "keys";

codechain/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern crate toml;
4949

5050
mod account_command;
5151
mod config;
52+
mod constants;
5253
mod rpc;
5354
mod rpc_apis;
5455

@@ -255,8 +256,11 @@ fn run_node(matches: ArgMatches) -> Result<(), String> {
255256
clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized");
256257

257258
// FIXME: Handle IO error.
258-
let keystore_dir =
259-
RootDiskDirectory::create(config.operating.keys_path.clone()).expect("Cannot read key path directory");
259+
let keys_path = match config.operating.keys_path {
260+
Some(ref keys_path) => keys_path.clone(),
261+
None => constants::DEFAULT_KEYS_PATH.to_string(),
262+
};
263+
let keystore_dir = RootDiskDirectory::create(keys_path).expect("Cannot read key path directory");
260264
let keystore = KeyStore::open(Box::new(keystore_dir)).unwrap();
261265
let ap = AccountProvider::new(keystore);
262266
let miner = new_miner(&config, &spec, ap.clone())?;

0 commit comments

Comments
 (0)