Disable hardware-wallets on platforms that don't support libusb (#8464)

* disable hardware-wallets that don't support libusb

* address grumbles

* nits

* Refactor to get rid off as much annotations asap

* Might consume slight more memory than pure conditional compilation
flags

* formatting nits

* Enable libusb for android

* Tested by it compiling succesfully with `cargo build --target=armv7--linux-androideabi`
* The binary is ~66 MB

```bash
$ size
size target/armv7-linux-androideabi/release/parity
text    	data     	bss     	dec     	hex 		filename
50676230        416200   	31456 		51123886        30c16ae 	target/armv7-linux-androideabi/release/parity
```

* Move all `fake-hardware-wallet` to its own crate

* Removes some conditional compilation flags
* Introduces `fake-hardware-wallet` crate

* return error if no hardware wallets are found
This commit is contained in:
Niklas Adolfsson
2018-06-26 09:03:38 +02:00
committed by Afri Schoedon
parent 4145be863b
commit 1a16f335fa
12 changed files with 184 additions and 39 deletions

View File

@@ -58,17 +58,21 @@ extern crate ethcore_transaction as transaction;
extern crate ethereum_types;
extern crate ethkey;
extern crate ethstore;
extern crate vm;
extern crate fetch;
extern crate keccak_hash as hash;
extern crate node_health;
extern crate parity_reactor;
extern crate parity_updater as updater;
extern crate parity_version as version;
extern crate patricia_trie as trie;
extern crate rlp;
extern crate stats;
extern crate keccak_hash as hash;
extern crate vm;
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
extern crate hardware_wallet;
extern crate patricia_trie as trie;
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
extern crate fake_hardware_wallet as hardware_wallet;
#[macro_use]
extern crate log;

View File

@@ -24,7 +24,6 @@ use light::cache::Cache as LightDataCache;
use light::client::LightChainClient;
use light::on_demand::{request, OnDemand};
use light::TransactionQueue as LightTransactionQueue;
use rlp;
use hash::keccak;
use ethereum_types::{H256, H520, Address, U256};
use bytes::Bytes;
@@ -52,6 +51,7 @@ use v1::types::{
SignRequest as RpcSignRequest,
DecryptRequest as RpcDecryptRequest,
};
use rlp;
pub use self::nonce::Reservations;
@@ -323,7 +323,7 @@ impl LightDispatcher {
x.map(move |acc| acc.map_or(account_start_nonce, |acc| acc.nonce))
.map_err(|_| errors::no_light_peers())
),
None => Box::new(future::err(errors::network_disabled()))
None => Box::new(future::err(errors::network_disabled()))
}
}
}
@@ -699,7 +699,6 @@ pub fn execute<D: Dispatcher + 'static>(
if accounts.is_hardware_address(&address) {
return Box::new(future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None)));
}
let res = decrypt(&accounts, address, data, pass)
.map(|result| result
.map(RpcBytes)
@@ -737,8 +736,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)
})
}

View File

@@ -305,8 +305,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()
)
}

View File

@@ -34,7 +34,6 @@ use ethcore::state::StateInfo;
use ethcore_logger::RotatingLogger;
use node_health::{NodeHealth, Health};
use updater::{Service as UpdateService};
use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_core::futures::{future, Future};
use jsonrpc_macros::Trailing;
@@ -53,7 +52,7 @@ use v1::types::{
use Host;
/// Parity implementation.
pub struct ParityClient<C, M, U> {
pub struct ParityClient<C, M, U> {
client: Arc<C>,
miner: Arc<M>,
updater: Arc<U>,
@@ -143,11 +142,11 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
.collect()
)
}
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))
}
fn default_account(&self, meta: Self::Metadata) -> Result<H160> {
let dapp_id = meta.dapp_id();
@@ -312,9 +311,9 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
);
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()
)
}
@@ -323,9 +322,9 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
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()
)
}
@@ -336,8 +335,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()
)
}
@@ -345,9 +344,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()
)
}

View File

@@ -22,7 +22,6 @@ use ethereum_types::Address;
use ethkey::{Brain, Generator, Secret};
use ethstore::KeyFile;
use ethcore::account_provider::AccountProvider;
use jsonrpc_core::Result;
use v1::helpers::errors;
use v1::traits::ParityAccounts;