Skip to content

Commit

Permalink
Fix openethereum#6209 - introduce standalone dir crate
Browse files Browse the repository at this point in the history
Done so far:

* created the dir crate in util
* moved code from `ethstore/src/dir/paths.rs` to dir crate
* rename `dir` module in ethstore to `accounts_dir` to distinguish it
  from the dir crate

Is there a need to mutualize some code in the newly created
`util/dir/src/lib.rs` ? If so, I would need some guidance as of which
functions are to be mutualized.
  • Loading branch information
Nicolas Ochem authored and Nicolas Ochem committed Nov 1, 2017
1 parent d525d1e commit 6685af9
Show file tree
Hide file tree
Showing 31 changed files with 173 additions and 141 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ parity-rpc-client = { path = "rpc_client" }
parity-updater = { path = "updater" }
parity-whisper = { path = "whisper" }
path = { path = "util/path" }
dir = { path = "util/dir" }
panic_hook = { path = "panic_hook" }
hash = { path = "util/hash" }
migration = { path = "util/migration" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/account_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use ethstore::{
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret,
};
use ethstore::dir::MemoryDirectory;
use ethstore::accounts_dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator};
use ethjson::misc::AccountMeta;
use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};
Expand Down
1 change: 1 addition & 0 deletions ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ itertools = "0.5"
parking_lot = "0.4"
ethcrypto = { path = "../ethcrypto" }
ethcore-bigint = { path = "../util/bigint" }
dir = { path = "../util/dir" }
smallvec = "0.4"
parity-wordlist = "1.0"
tempdir = "0.3"
Expand Down
1 change: 1 addition & 0 deletions ethstore/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ serde = "1.0"
serde_derive = "1.0"
docopt = "0.8"
ethstore = { path = "../" }
dir = { path = '../../util/dir' }
panic_hook = { path = "../../panic_hook" }

[[bin]]
Expand Down
9 changes: 5 additions & 4 deletions ethstore/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

extern crate rustc_hex;
extern crate docopt;
extern crate dir;
extern crate serde;
#[macro_use]
extern crate serde_derive;
Expand All @@ -26,7 +27,7 @@ use std::{env, process, fs, fmt};
use std::io::Read;
use docopt::Docopt;
use ethstore::ethkey::Address;
use ethstore::dir::{paths, KeyDirectory, RootDiskDirectory};
use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory};
use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, PresaleWallet,
SecretVaultRef, StoreAccountRef};

Expand Down Expand Up @@ -148,11 +149,11 @@ fn main() {

fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> {
let dir: Box<KeyDirectory> = match location {
"geth" => Box::new(RootDiskDirectory::create(paths::geth(false))?),
"geth-test" => Box::new(RootDiskDirectory::create(paths::geth(true))?),
"geth" => Box::new(RootDiskDirectory::create(dir::geth(false))?),
"geth-test" => Box::new(RootDiskDirectory::create(dir::geth(true))?),
path if path.starts_with("parity") => {
let chain = path.split('-').nth(1).unwrap_or("ethereum");
let path = paths::parity(chain);
let path = dir::parity(chain);
Box::new(RootDiskDirectory::create(path)?)
},
path => Box::new(RootDiskDirectory::create(path)?),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<T> DiskDirectory<T> where T: KeyFileManager {
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;

let mut hasher = DefaultHasher::new();
let mut hasher = DefaultHasher::new();
let files = self.files()?;
for file in files {
hasher.write(file.to_str().unwrap_or("").as_bytes())
Expand Down Expand Up @@ -291,7 +291,7 @@ mod test {

use std::{env, fs};
use super::RootDiskDirectory;
use dir::{KeyDirectory, VaultKey};
use super::{KeyDirectory, VaultKey};
use account::SafeAccount;
use ethkey::{Random, Generator};
use self::tempdir::TempDir;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use {SafeAccount, Error};
mod disk;
mod memory;
mod vault;
pub mod paths;

/// `VaultKeyDirectory::set_key` error
#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ mod test {
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use dir::VaultKey;
use super::VaultKey;
use super::{VAULT_FILE_NAME, check_vault_name, make_vault_dir_path, create_vault_file, read_vault_file, VaultDiskDirectory};
use self::tempdir::TempDir;

Expand Down
96 changes: 0 additions & 96 deletions ethstore/src/dir/paths.rs

This file was deleted.

4 changes: 2 additions & 2 deletions ethstore/src/ethstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::time::{Instant, Duration};
use crypto::KEY_ITERATIONS;
use random::Random;
use ethkey::{self, Signature, Address, Message, Secret, Public, KeyPair, ExtendedKeyPair};
use dir::{KeyDirectory, VaultKeyDirectory, VaultKey, SetKeyError};
use accounts_dir::{KeyDirectory, VaultKeyDirectory, VaultKey, SetKeyError};
use account::SafeAccount;
use presale::PresaleWallet;
use json::{self, Uuid, OpaqueKeyFile};
Expand Down Expand Up @@ -653,7 +653,7 @@ impl SimpleSecretStore for EthMultiStore {
mod tests {
extern crate tempdir;

use dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory};
use accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory};
use ethkey::{Random, Generator, KeyPair};
use secret_store::{SimpleSecretStore, SecretStore, SecretVaultRef, StoreAccountRef, Derivation};
use super::{EthStore, EthMultiStore};
Expand Down
7 changes: 4 additions & 3 deletions ethstore/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use std::path::Path;
use std::fs;

use ethkey::Address;
use dir::{paths, KeyDirectory, RootDiskDirectory, DiskKeyFileManager, KeyFileManager};
use accounts_dir::{KeyDirectory, RootDiskDirectory, DiskKeyFileManager, KeyFileManager};
use dir;
use Error;

/// Import an account from a file.
Expand Down Expand Up @@ -54,15 +55,15 @@ pub fn import_accounts(src: &KeyDirectory, dst: &KeyDirectory) -> Result<Vec<Add

/// Provide a `HashSet` of all accounts available for import from the Geth keystore.
pub fn read_geth_accounts(testnet: bool) -> Vec<Address> {
RootDiskDirectory::at(paths::geth(testnet))
RootDiskDirectory::at(dir::geth(testnet))
.load()
.map(|d| d.into_iter().map(|a| a.address).collect())
.unwrap_or_else(|_| Vec::new())
}

/// Import specific `desired` accounts from the Geth keystore into `dst`.
pub fn import_geth_accounts(dst: &KeyDirectory, desired: HashSet<Address>, testnet: bool) -> Result<Vec<Address>, Error> {
let src = RootDiskDirectory::at(paths::geth(testnet));
let src = RootDiskDirectory::at(dir::geth(testnet));
let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();

Expand Down
3 changes: 2 additions & 1 deletion ethstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![warn(missing_docs)]

extern crate crypto as rcrypto;
extern crate dir;
extern crate itertools;
extern crate libc;
extern crate parking_lot;
Expand All @@ -41,7 +42,7 @@ extern crate log;
#[macro_use]
extern crate serde_derive;

pub mod dir;
pub mod accounts_dir;
pub mod ethkey;

mod account;
Expand Down
2 changes: 1 addition & 1 deletion ethstore/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod util;

use ethstore::{EthStore, SimpleSecretStore, SecretVaultRef, StoreAccountRef};
use ethstore::ethkey::{Random, Generator, Secret, KeyPair, verify_address};
use ethstore::dir::RootDiskDirectory;
use ethstore::accounts_dir::RootDiskDirectory;
use util::TransientDir;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion ethstore/tests/util/transient_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::path::PathBuf;
use std::{env, fs};
use rand::{Rng, OsRng};
use ethstore::dir::{KeyDirectory, RootDiskDirectory};
use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory};
use ethstore::{Error, SafeAccount};

pub fn random_dir() -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion parity/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::path::PathBuf;
use ethcore::ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts};
use ethcore::ethstore::dir::RootDiskDirectory;
use ethcore::ethstore::accounts_dir::RootDiskDirectory;
use ethcore::ethstore::SecretVaultRef;
use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
use helpers::{password_prompt, password_from_file};
Expand Down
2 changes: 1 addition & 1 deletion parity/cli/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ macro_rules! usage {
use std::io::{Read, Write};
use util::version;
use clap::{Arg, App, SubCommand, AppSettings, Error as ClapError, ErrorKind as ClapErrorKind};
use helpers::replace_home;
use dir::helpers::replace_home;
use std::ffi::OsStr;
use std::collections::HashMap;

Expand Down
7 changes: 4 additions & 3 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration, UiConfiguration}
use rpc_apis::ApiSet;
use parity_rpc::NetworkSettings;
use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_and_local,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, geth_ipc_path, parity_ipc_path,
to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use dir::helpers::{replace_home, replace_home_and_local};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType};
use ethcore_logger::Config as LogConfig;
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
Expand Down Expand Up @@ -1841,7 +1842,7 @@ mod tests {

let base_path = ::dir::default_data_path();
let local_path = ::dir::default_local_path();
assert_eq!(std.directories().cache, ::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH));
assert_eq!(std.directories().cache, dir::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH));
assert_eq!(base.directories().cache, "/test/cache");
}
}
2 changes: 1 addition & 1 deletion parity/dapps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use futures::{future, IntoFuture, Future};
use jsonrpc_core::BoxFuture;
use hash_fetch::fetch::Client as FetchClient;
use hash_fetch::urlhint::ContractClient;
use helpers::replace_home;
use dir::helpers::replace_home;
use light::client::LightChainClient;
use light::on_demand::{self, OnDemand};
use node_health::{SyncStatus, NodeHealth};
Expand Down
Loading

0 comments on commit 6685af9

Please sign in to comment.