Export account RPC (#4967)
* Export account RPC * Removing GethDirectory and ParityDirectory * Updating ethstore-cli help.
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use {SafeAccount, Error};
|
||||
use super::{KeyDirectory, RootDiskDirectory, DirectoryType};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn geth_dir_path() -> PathBuf {
|
||||
let mut home = env::home_dir().expect("Failed to get home dir");
|
||||
home.push("Library");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
/// Default path for ethereum installation on Windows
|
||||
pub fn geth_dir_path() -> PathBuf {
|
||||
let mut home = env::home_dir().expect("Failed to get home dir");
|
||||
home.push("AppData");
|
||||
home.push("Roaming");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
/// Default path for ethereum installation on posix system which is not Mac OS
|
||||
pub fn geth_dir_path() -> PathBuf {
|
||||
let mut home = env::home_dir().expect("Failed to get home dir");
|
||||
home.push(".ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
fn geth_keystore(t: DirectoryType) -> PathBuf {
|
||||
let mut dir = geth_dir_path();
|
||||
match t {
|
||||
DirectoryType::Testnet => {
|
||||
dir.push("testnet");
|
||||
dir.push("keystore");
|
||||
},
|
||||
DirectoryType::Main => {
|
||||
dir.push("keystore");
|
||||
}
|
||||
}
|
||||
dir
|
||||
}
|
||||
|
||||
pub struct GethDirectory {
|
||||
dir: RootDiskDirectory,
|
||||
}
|
||||
|
||||
impl GethDirectory {
|
||||
pub fn create(t: DirectoryType) -> Result<Self, Error> {
|
||||
let result = GethDirectory {
|
||||
dir: RootDiskDirectory::create(geth_keystore(t))?,
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn open(t: DirectoryType) -> Self {
|
||||
GethDirectory {
|
||||
dir: RootDiskDirectory::at(geth_keystore(t)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyDirectory for GethDirectory {
|
||||
fn load(&self) -> Result<Vec<SafeAccount>, Error> {
|
||||
self.dir.load()
|
||||
}
|
||||
|
||||
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
|
||||
self.dir.insert(account)
|
||||
}
|
||||
|
||||
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
|
||||
self.dir.update(account)
|
||||
}
|
||||
|
||||
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
|
||||
self.dir.remove(account)
|
||||
}
|
||||
|
||||
fn unique_repr(&self) -> Result<u64, Error> {
|
||||
self.dir.unique_repr()
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ use ethkey::Address;
|
||||
use {SafeAccount, Error};
|
||||
use super::KeyDirectory;
|
||||
|
||||
/// Accounts in-memory storage.
|
||||
#[derive(Default)]
|
||||
pub struct MemoryDirectory {
|
||||
accounts: RwLock<HashMap<Address, Vec<SafeAccount>>>,
|
||||
|
||||
@@ -14,19 +14,15 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Accounts Directory
|
||||
|
||||
use std::path::{PathBuf};
|
||||
use {SafeAccount, Error};
|
||||
|
||||
mod disk;
|
||||
mod geth;
|
||||
mod memory;
|
||||
mod parity;
|
||||
mod vault;
|
||||
|
||||
pub enum DirectoryType {
|
||||
Testnet,
|
||||
Main,
|
||||
}
|
||||
pub mod paths;
|
||||
|
||||
/// `VaultKeyDirectory::set_key` error
|
||||
#[derive(Debug)]
|
||||
@@ -54,7 +50,7 @@ pub trait KeyDirectory: Send + Sync {
|
||||
fn load(&self) -> Result<Vec<SafeAccount>, Error>;
|
||||
/// Insert new key to directory
|
||||
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
|
||||
//// Update key in directory
|
||||
/// Update key in the directory
|
||||
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
|
||||
/// Remove key from directory
|
||||
fn remove(&self, account: &SafeAccount) -> Result<(), Error>;
|
||||
@@ -95,9 +91,7 @@ pub trait VaultKeyDirectory: KeyDirectory {
|
||||
}
|
||||
|
||||
pub use self::disk::RootDiskDirectory;
|
||||
pub use self::geth::GethDirectory;
|
||||
pub use self::memory::MemoryDirectory;
|
||||
pub use self::parity::ParityDirectory;
|
||||
pub use self::vault::VaultDiskDirectory;
|
||||
|
||||
impl VaultKey {
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use {SafeAccount, Error};
|
||||
use super::{KeyDirectory, RootDiskDirectory, DirectoryType};
|
||||
|
||||
fn parity_dir_path() -> PathBuf {
|
||||
let mut home = env::home_dir().expect("Failed to get home dir");
|
||||
home.push(".parity");
|
||||
home
|
||||
}
|
||||
|
||||
fn parity_keystore(t: DirectoryType) -> PathBuf {
|
||||
let mut dir = parity_dir_path();
|
||||
match t {
|
||||
DirectoryType::Testnet => {
|
||||
dir.push("testnet_keys");
|
||||
},
|
||||
DirectoryType::Main => {
|
||||
dir.push("keys");
|
||||
}
|
||||
}
|
||||
dir
|
||||
}
|
||||
|
||||
pub struct ParityDirectory {
|
||||
dir: RootDiskDirectory,
|
||||
}
|
||||
|
||||
impl ParityDirectory {
|
||||
pub fn create(t: DirectoryType) -> Result<Self, Error> {
|
||||
let result = ParityDirectory {
|
||||
dir: RootDiskDirectory::create(parity_keystore(t))?,
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn open(t: DirectoryType) -> Self {
|
||||
ParityDirectory {
|
||||
dir: RootDiskDirectory::at(parity_keystore(t)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyDirectory for ParityDirectory {
|
||||
fn load(&self) -> Result<Vec<SafeAccount>, Error> {
|
||||
self.dir.load()
|
||||
}
|
||||
|
||||
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
|
||||
self.dir.insert(account)
|
||||
}
|
||||
|
||||
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
|
||||
self.dir.update(account)
|
||||
}
|
||||
|
||||
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
|
||||
self.dir.remove(account)
|
||||
}
|
||||
|
||||
fn unique_repr(&self) -> Result<u64, Error> {
|
||||
self.dir.unique_repr()
|
||||
}
|
||||
}
|
||||
96
ethstore/src/dir/paths.rs
Normal file
96
ethstore/src/dir/paths.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Common tools paths.
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn home() -> PathBuf {
|
||||
env::home_dir().expect("Failed to get home dir")
|
||||
}
|
||||
|
||||
/// Geth path
|
||||
pub fn geth(testnet: bool) -> PathBuf {
|
||||
let mut base = geth_base();
|
||||
if testnet {
|
||||
base.push("testnet");
|
||||
}
|
||||
base.push("keystore");
|
||||
base
|
||||
}
|
||||
|
||||
/// Parity path for specific chain
|
||||
pub fn parity(chain: &str) -> PathBuf {
|
||||
let mut base = parity_base();
|
||||
base.push(chain);
|
||||
base
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn parity_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push("Library");
|
||||
home.push("Application Support");
|
||||
home.push("io.parity.ethereum");
|
||||
home.push("keys");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn parity_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push("AppData");
|
||||
home.push("Roaming");
|
||||
home.push("Parity");
|
||||
home.push("Ethereum");
|
||||
home.push("keys");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
fn parity_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push(".local");
|
||||
home.push("share");
|
||||
home.push("io.parity.ethereum");
|
||||
home.push("keys");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn geth_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push("Library");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn geth_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push("AppData");
|
||||
home.push("Roaming");
|
||||
home.push("Ethereum");
|
||||
home
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
fn geth_base() -> PathBuf {
|
||||
let mut home = home();
|
||||
home.push(".ethereum");
|
||||
home
|
||||
}
|
||||
Reference in New Issue
Block a user