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

Commit

Permalink
address grumbles
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed May 13, 2018
1 parent eb293f8 commit fcb7740
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
33 changes: 23 additions & 10 deletions ethcore/src/account_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,32 @@ use ethstore::{
use ethstore::accounts_dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator};
use ethjson::misc::AccountMeta;
use self::hw::*;

pub use ethstore::ethkey::Signature;
pub use ethstore::{Derivation, IndexDerivation, KeyFile};

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
use super::transaction::{Action, Transaction};
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};
mod hw {
pub use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};
pub use ::transaction::{Action, Transaction};
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
mod hw {
use super::fmt;

#[derive(Debug)]
pub enum HardwareError {}
pub struct HardwareWalletManager;

impl fmt::Display for HardwareError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "")
}
}
}


/// Type of unlock.
#[derive(Clone, PartialEq)]
Expand Down Expand Up @@ -67,7 +85,6 @@ pub enum SignError {
/// Account does not exist.
NotFound,
/// Low-level hardware device error.
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
Hardware(HardwareError),
/// Low-level error from store
SStore(SSError),
Expand All @@ -78,14 +95,12 @@ impl fmt::Display for SignError {
match *self {
SignError::NotUnlocked => write!(f, "Account is locked"),
SignError::NotFound => write!(f, "Account does not exist"),
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
SignError::Hardware(ref e) => write!(f, "{}", e),
SignError::SStore(ref e) => write!(f, "{}", e),
}
}
}

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
impl From<HardwareError> for SignError {
fn from(e: HardwareError) -> Self {
SignError::Hardware(e)
Expand Down Expand Up @@ -137,7 +152,6 @@ pub struct AccountProvider {
/// Accounts unlocked with rolling tokens
transient_sstore: EthMultiStore,
/// Accounts in hardware wallets.
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
hardware_store: Option<HardwareWalletManager>,
/// When unlocking account permanently we additionally keep a raw secret in memory
/// to increase the performance of transaction signing.
Expand Down Expand Up @@ -216,8 +230,7 @@ impl AccountProvider {
pub fn new(sstore: Box<SecretStore>, settings: AccountProviderSettings) -> Self {
if let Ok(accounts) = sstore.accounts() {
for account in accounts.into_iter().filter(|a| settings.blacklisted_accounts.contains(&a.address)) {
warn!("Local Account {} has a blacklisted (known to be weak) address and will be ignored",
account.address);
warn!("Local Account {} has a blacklisted (known to be weak) address and will be ignored", account.address);
}
}

Expand All @@ -234,6 +247,7 @@ impl AccountProvider {
dapps_settings: RwLock::new(DappsSettingsStore::new(&sstore.local_path())),
sstore: sstore,
transient_sstore: transient_sstore(),
hardware_store: None,
unlock_keep_secret: settings.unlock_keep_secret,
blacklisted_accounts: settings.blacklisted_accounts,
}
Expand All @@ -248,7 +262,6 @@ impl AccountProvider {
dapps_settings: RwLock::new(DappsSettingsStore::transient()),
sstore: Box::new(EthStore::open(Box::new(MemoryDirectory::default())).expect("MemoryDirectory load always succeeds; qed")),
transient_sstore: transient_sstore(),
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
hardware_store: None,
unlock_keep_secret: false,
blacklisted_accounts: vec![],
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ extern crate wasm;
extern crate memory_cache;
extern crate journaldb;


#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
extern crate hardware_wallet;

Expand Down Expand Up @@ -162,6 +161,7 @@ pub mod snapshot;
pub mod spec;
pub mod state;
pub mod state_db;

// Test helpers made public for usage outside ethcore
pub mod test_helpers;
pub mod trace;
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/helpers/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ fn hardware_signature(accounts: &AccountProvider, address: Address, t: Transacti

SignedTransaction::new(t.with_signature(signature, chain_id))
.map_err(|e| {
debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e);
errors::account("Invalid signature generated", e)
debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e);
errors::account("Invalid signature generated", e)
})
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/light/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ impl Parity for ParityClient {
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>> {
let stats = self.light_dispatch.sync.transactions_stats();
Ok(stats.into_iter()
.map(|(hash, stats)| (hash.into(), stats.into()))
.collect()
.map(|(hash, stats)| (hash.into(), stats.into()))
.collect()
)
}

Expand Down
44 changes: 22 additions & 22 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use Host;
use jsonrpc_core::Error;

/// Parity implementation.
pub struct ParityClient<C, M, U> {
pub struct ParityClient<C, M, U> {
client: Arc<C>,
miner: Arc<M>,
updater: Arc<U>,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
)
}

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
let store = self.account_provider()?;
let info = store.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
Expand All @@ -156,24 +156,24 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
.collect()
)
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
Err(Error::parse_error())
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
Err(Error::parse_error())
}

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
let store = self.account_provider()?;
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
Err(Error::parse_error())
Err(Error::parse_error())
}

fn default_account(&self, meta: Self::Metadata) -> Result<H160> {
fn default_account(&self, meta: Self::Metadata) -> Result<H160> {
let dapp_id = meta.dapp_id();

Ok(self.account_provider()?
Expand Down Expand Up @@ -332,20 +332,20 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
let ready_transactions = self.miner.ready_transactions(&*self.client);

Ok(ready_transactions
.into_iter()
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
.collect()
)
.into_iter()
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
.collect()
)
}

fn all_transactions(&self) -> Result<Vec<Transaction>> {
let block_number = self.client.chain_info().best_block_number;
let all_transactions = self.miner.queued_transactions();

Ok(all_transactions
.into_iter()
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
.collect()
.into_iter()
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
.collect()
)
}

Expand All @@ -356,8 +356,8 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>> {
let stats = self.sync.transactions_stats();
Ok(stats.into_iter()
.map(|(hash, stats)| (hash.into(), stats.into()))
.collect()
.map(|(hash, stats)| (hash.into(), stats.into()))
.collect()
)
}

Expand All @@ -370,9 +370,9 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
let transactions = self.miner.local_transactions();
let block_number = self.client.chain_info().best_block_number;
Ok(transactions
.into_iter()
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
.collect()
.into_iter()
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
.collect()
)
}

Expand Down

0 comments on commit fcb7740

Please sign in to comment.