Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
user defaults are network-dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Aug 29, 2016
1 parent bf8bf17 commit ac24cfd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
24 changes: 15 additions & 9 deletions parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,18 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
// create dirs used by parity
try!(cmd.dirs.create_dirs());

// load spec file
let spec = try!(cmd.spec.spec());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);

// load user defaults
let mut user_defaults = try!(UserDefaults::load(cmd.dirs.user_defaults_path()));
let mut user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(cmd.tracing, &user_defaults));

// load spec file
let spec = try!(cmd.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

Expand Down Expand Up @@ -226,7 +229,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
// save user defaults
user_defaults.pruning = algorithm;
user_defaults.tracing = tracing;
try!(user_defaults.save(cmd.dirs.user_defaults_path()));
try!(user_defaults.save(&user_defaults_path));

Ok("Import completed.".into())
}
Expand All @@ -238,17 +241,20 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
// create dirs used by parity
try!(cmd.dirs.create_dirs());

// load spec file
let spec = try!(cmd.spec.spec());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);

// load user defaults
let user_defaults = try!(UserDefaults::load(cmd.dirs.user_defaults_path()));
let user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(cmd.tracing, &user_defaults));

let format = cmd.format.unwrap_or_else(Default::default);

// load spec file
let spec = try!(cmd.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

Expand Down
7 changes: 5 additions & 2 deletions parity/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ impl Directories {
}

/// Get user defaults path
pub fn user_defaults_path(&self) -> PathBuf {
pub fn user_defaults_path(&self, fork_name: &Option<String>) -> PathBuf {
let mut dir = Path::new(&self.db).to_path_buf();
dir.push("user_defaults");
match *fork_name {
Some(ref name) => dir.push(format!("user_defaults_{}", name)),
None => dir.push("user_defaults"),
}
dir
}
}
Expand Down
12 changes: 8 additions & 4 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,21 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
// create dirs used by parity
try!(cmd.dirs.create_dirs());

// load spec
let spec = try!(cmd.spec.spec());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);

// load user defaults
let mut user_defaults = try!(UserDefaults::load(cmd.dirs.user_defaults_path()));
let mut user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(cmd.tracing, &user_defaults));

// set up logger
let logger = try!(setup_log(&cmd.logger_config));

// load spec
let spec = try!(cmd.spec.spec());
let fork_name = spec.fork_name.clone();

// load genesis hash
Expand Down Expand Up @@ -264,7 +268,7 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
// save user defaults
user_defaults.pruning = algorithm;
user_defaults.tracing = tracing;
try!(user_defaults.save(cmd.dirs.user_defaults_path()));
try!(user_defaults.save(&user_defaults_path));

// Handle exit
wait_for_exit(panic_handler, http_server, ipc_server, dapps_server, signer_server);
Expand Down
11 changes: 7 additions & 4 deletions parity/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ impl SnapshotCommand {
// Setup panic handler
let panic_handler = PanicHandler::new_in_arc();

// load spec file
let spec = try!(self.spec.spec());

// user defaults path
let user_defaults_path = self.dirs.user_defaults_path(&spec.fork_name);

// load user defaults
let user_defaults = try!(UserDefaults::load(self.dirs.user_defaults_path()));
let user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(self.tracing, &user_defaults));

// load spec file
let spec = try!(self.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

Expand Down

0 comments on commit ac24cfd

Please sign in to comment.