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

Commit

Permalink
Merge branch 'master' into jg-shapeshift-store
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Jan 5, 2017
2 parents ef6b2b6 + a076ffa commit 5e0b116
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
6 changes: 4 additions & 2 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! Blockchain block.

use std::cmp;
use std::sync::Arc;
use std::collections::HashSet;

Expand Down Expand Up @@ -266,8 +267,9 @@ impl<'x> OpenBlock<'x> {
r.block.base.header.set_extra_data(extra_data);
r.block.base.header.note_dirty();

let gas_floor_target = ::std::cmp::max(gas_range_target.0, engine.params().min_gas_limit);
engine.populate_from_parent(&mut r.block.base.header, parent, gas_floor_target, gas_range_target.1);
let gas_floor_target = cmp::max(gas_range_target.0, engine.params().min_gas_limit);
let gas_ceil_target = cmp::max(gas_range_target.1, gas_floor_target);
engine.populate_from_parent(&mut r.block.base.header, parent, gas_floor_target, gas_ceil_target);
engine.on_new_block(&mut r.block);
Ok(r)
}
Expand Down
6 changes: 3 additions & 3 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#[macro_use]
mod usage;
use dir::default_data_path;
use dir;

usage! {
{
Expand Down Expand Up @@ -90,8 +90,8 @@ usage! {
flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(),
flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(),
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
flag_base_path: String = default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(),
flag_db_path: String = "$BASE/chains", or |c: &Config| otry!(c.parity).db_path.clone(),
flag_base_path: String = dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(),
flag_db_path: String = dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone(),
flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(),
flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),

Expand Down
2 changes: 1 addition & 1 deletion parity/cli/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Legacy Options:
testnet --keys-path $HOME/parity/testnet-keys.
Overrides the --keys-path option.
--import-geth-keys Attempt to import keys from Geth client.
--datadir PATH Equivalent to --db-path PATH.
--datadir PATH Equivalent to --base-path PATH.
--networkid INDEX Equivalent to --network-id INDEX.
--peers NUM Equivalent to --min-peers NUM.
--nodekey KEY Equivalent to --node-key KEY.
Expand Down
11 changes: 8 additions & 3 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use ethcore::verification::queue::VerifierSettings;
use rpc::{IpcConfiguration, HttpConfiguration};
use ethcore_rpc::NetworkSettings;
use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home,
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_for_db,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig;
use dir::{Directories, default_hypervisor_path};
use dir::{Directories, default_hypervisor_path, default_local_path};
use dapps::Configuration as DappsConfiguration;
use signer::{Configuration as SignerConfiguration};
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
Expand Down Expand Up @@ -707,9 +707,14 @@ impl Configuration {
fn directories(&self) -> Directories {
use util::path;

let local_path = default_local_path();
let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_base_path));

let db_path = replace_home(&data_path, &self.args.flag_db_path);
let db_path = if self.args.flag_datadir.is_some() {
replace_home(&data_path, &self.args.flag_db_path)
} else {
replace_home_for_db(&data_path, &local_path, &self.args.flag_db_path)
};
let keys_path = replace_home(&data_path, &self.args.flag_keys_path);
let dapps_path = replace_home(&data_path, &self.args.flag_dapps_path);
let ui_path = replace_home(&data_path, &self.args.flag_ui_path);
Expand Down
21 changes: 17 additions & 4 deletions parity/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::fs;
use std::path::{PathBuf, Path};
use util::{H64, H256};
use util::journaldb::Algorithm;
use helpers::replace_home;
use helpers::{replace_home, replace_home_for_db};
use app_dirs::{AppInfo, get_app_root, AppDataType};

#[cfg(target_os = "macos")] const AUTHOR: &'static str = "Parity";
Expand All @@ -31,6 +31,9 @@ use app_dirs::{AppInfo, get_app_root, AppDataType};
#[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT: &'static str = "io.parity.ethereum";
#[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT_HYPERVISOR: &'static str = "io.parity.ethereum-updates";

#[cfg(target_os = "windows")] pub const CHAINS_PATH: &'static str = "$LOCAL/chains";
#[cfg(not(target_os = "windows"))] pub const CHAINS_PATH: &'static str = "$BASE/chains";

// this const is irrelevent cause we do have migrations now,
// but we still use it for backwards compatibility
const LEGACY_CLIENT_DB_VER_STR: &'static str = "5.3";
Expand All @@ -47,9 +50,10 @@ pub struct Directories {
impl Default for Directories {
fn default() -> Self {
let data_dir = default_data_path();
let local_dir = default_local_path();
Directories {
base: replace_home(&data_dir, "$BASE"),
db: replace_home(&data_dir, "$BASE/chains"),
db: replace_home_for_db(&data_dir, &local_dir, CHAINS_PATH),
keys: replace_home(&data_dir, "$BASE/keys"),
signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"),
Expand Down Expand Up @@ -209,6 +213,11 @@ pub fn default_data_path() -> String {
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
}

pub fn default_local_path() -> String {
let app_info = AppInfo { name: PRODUCT, author: AUTHOR };
get_app_root(AppDataType::UserCache, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
}

pub fn default_hypervisor_path() -> String {
let app_info = AppInfo { name: PRODUCT_HYPERVISOR, author: AUTHOR };
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned())
Expand All @@ -217,14 +226,18 @@ pub fn default_hypervisor_path() -> String {
#[cfg(test)]
mod tests {
use super::Directories;
use helpers::replace_home;
use helpers::{replace_home, replace_home_for_db};

#[test]
fn test_default_directories() {
let data_dir = super::default_data_path();
let local_dir = super::default_local_path();
let expected = Directories {
base: replace_home(&data_dir, "$BASE"),
db: replace_home(&data_dir, "$BASE/chains"),
db: replace_home_for_db(&data_dir, &local_dir,
if cfg!(target_os = "windows") { "$LOCAL/chains" }
else { "$BASE/chains" }
),
keys: replace_home(&data_dir, "$BASE/keys"),
signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"),
Expand Down
9 changes: 7 additions & 2 deletions parity/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ pub fn to_price(s: &str) -> Result<f32, String> {
pub fn replace_home(base: &str, arg: &str) -> String {
// the $HOME directory on mac os should be `~/Library` or `~/Library/Application Support`
let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap());
let r = r.replace("$BASE", base );
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string() )
let r = r.replace("$BASE", base);
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string())
}

pub fn replace_home_for_db(base: &str, local: &str, arg: &str) -> String {
let r = replace_home(base, arg);
r.replace("$LOCAL", local)
}

/// Flush output buffer.
Expand Down

0 comments on commit 5e0b116

Please sign in to comment.