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

Commit

Permalink
return error if no hardware wallets are found
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Jun 22, 2018
1 parent 6548566 commit 2011226
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
25 changes: 15 additions & 10 deletions ethcore/src/account_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@

mod stores;

use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy};

use std::collections::{HashMap, HashSet};
use std::fmt;
use std::time::{Instant, Duration};

use ethstore::accounts_dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Password, Random, Generator};
use ethjson::misc::AccountMeta;
use ethstore::{
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret,
};
use ethjson::misc::AccountMeta;
use ethstore::accounts_dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Password, Random, Generator};
use ethjson::misc::AccountMeta;
use parking_lot::RwLock;
use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::time::{Instant, Duration};

pub use ethstore::ethkey::Signature;
pub use ethstore::{Derivation, IndexDerivation, KeyFile};
Expand Down Expand Up @@ -291,8 +292,12 @@ impl AccountProvider {

/// Returns addresses of hardware accounts.
pub fn hardware_accounts(&self) -> Result<Vec<Address>, Error> {
let accounts = self.hardware_store.as_ref().map_or_else(|| Vec::new(), |h| h.list_wallets());
Ok(accounts.into_iter().map(|a| a.address).collect())
if let Some(accounts) = self.hardware_store.as_ref().map(|h| h.list_wallets()) {
if !accounts.is_empty() {
return Ok(accounts.into_iter().map(|a| a.address).collect());
}
}
Err(SSError::Custom("No hardware wallet accounts were found".into()))
}

/// Get a list of paths to locked hardware wallets
Expand Down
6 changes: 1 addition & 5 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ extern crate vm;
extern crate wasm;
extern crate memory_cache;
extern crate journaldb;
extern crate tempdir;

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

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

#[cfg(test)]
extern crate tempdir;

#[macro_use]
extern crate ethabi_derive;
#[macro_use]
Expand Down Expand Up @@ -161,8 +159,6 @@ pub mod snapshot;
pub mod spec;
pub mod state;
pub mod state_db;

// Test helpers made public for usage outside ethcore
pub mod trace;
pub mod verification;

Expand Down
8 changes: 4 additions & 4 deletions util/fake-hardware-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct WalletInfo {
/// `ErrorType` for devices with no `hardware wallet`
pub enum Error {
NoWallet,
KeyNotFound,
KeyNotFound,
}

pub struct TransactionInfo {
Expand Down Expand Up @@ -65,8 +65,8 @@ pub struct HardwareWalletManager;

impl HardwareWalletManager {
pub fn new() -> Result<Self, Error> {
Err(Error::NoWallet)
}
Err(Error::NoWallet)
}

pub fn set_key_path(&self, _key_path: KeyPath) {}

Expand Down Expand Up @@ -96,6 +96,6 @@ impl HardwareWalletManager {

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

0 comments on commit 2011226

Please sign in to comment.