Deprecate account management (#10213)

* Extract accounts from ethcore.

* Fix ethcore.

* Get rid of AccountProvider in test_helpers

* Fix rest of the code.

* Re-use EngineSigner, fix tests.

* Simplify EngineSigner to always have an Address.

* Fix RPC tests.

* Add deprecation notice to RPCs.

* Feature to disable accounts.

* extract accounts in RPC

* Run with accounts in tests.

* Fix RPC compilation and tests.

* Fix compilation of the binary.

* Fix compilation of the binary.

* Fix compilation with accounts enabled.

* Fix tests.

* Update submodule.

* Remove android.

* Use derive for Default

* Don't build secretstore by default.

* Add link to issue.

* Refresh Cargo.lock.

* Fix miner tests.

* Update rpc/Cargo.toml

Co-Authored-By: tomusdrw <tomusdrw@users.noreply.github.com>

* Fix private tests.
This commit is contained in:
Tomasz Drwięga
2019-02-07 14:34:24 +01:00
committed by Afri Schoedon
parent 8fa56add47
commit d5c19f8719
102 changed files with 3222 additions and 2393 deletions

View File

@@ -28,8 +28,7 @@ use light::client::LightChainClient;
use light::{cht, TransactionQueue};
use light::on_demand::{request, OnDemand};
use ethcore::account_provider::AccountProvider;
use ethereum_types::U256;
use ethereum_types::{U256, Address};
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
use parking_lot::{RwLock, Mutex};
use rlp::Rlp;
@@ -42,6 +41,7 @@ use types::ids::BlockId;
use v1::impls::eth_filter::Filterable;
use v1::helpers::{errors, limit_logs};
use v1::helpers::{SyncPollFilter, PollManager};
use v1::helpers::deprecated::{self, DeprecationNotice};
use v1::helpers::light_fetch::{self, LightFetch};
use v1::traits::Eth;
use v1::types::{
@@ -60,11 +60,12 @@ pub struct EthClient<T> {
client: Arc<T>,
on_demand: Arc<OnDemand>,
transaction_queue: Arc<RwLock<TransactionQueue>>,
accounts: Arc<AccountProvider>,
accounts: Arc<Fn() -> Vec<Address> + Send + Sync>,
cache: Arc<Mutex<LightDataCache>>,
polls: Mutex<PollManager<SyncPollFilter>>,
poll_lifetime: u32,
gas_price_percentile: usize,
deprecation_notice: DeprecationNotice,
}
impl<T> Clone for EthClient<T> {
@@ -80,6 +81,7 @@ impl<T> Clone for EthClient<T> {
polls: Mutex::new(PollManager::new(self.poll_lifetime)),
poll_lifetime: self.poll_lifetime,
gas_price_percentile: self.gas_price_percentile,
deprecation_notice: Default::default(),
}
}
}
@@ -92,7 +94,7 @@ impl<T: LightChainClient + 'static> EthClient<T> {
client: Arc<T>,
on_demand: Arc<OnDemand>,
transaction_queue: Arc<RwLock<TransactionQueue>>,
accounts: Arc<AccountProvider>,
accounts: Arc<Fn() -> Vec<Address> + Send + Sync>,
cache: Arc<Mutex<LightDataCache>>,
gas_price_percentile: usize,
poll_lifetime: u32
@@ -107,6 +109,7 @@ impl<T: LightChainClient + 'static> EthClient<T> {
polls: Mutex::new(PollManager::new(poll_lifetime)),
poll_lifetime,
gas_price_percentile,
deprecation_notice: Default::default(),
}
}
@@ -235,9 +238,9 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}
fn author(&self) -> Result<RpcH160> {
self.accounts.accounts()
.ok()
.and_then(|a| a.first().cloned())
(self.accounts)()
.first()
.cloned()
.map(From::from)
.ok_or_else(|| errors::account("No accounts were found", ""))
}
@@ -262,9 +265,12 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}
fn accounts(&self) -> Result<Vec<RpcH160>> {
self.accounts.accounts()
.map_err(|e| errors::account("Could not fetch accounts.", e))
.map(|accs| accs.into_iter().map(Into::<RpcH160>::into).collect())
self.deprecation_notice.print("eth_accounts", deprecated::msgs::ACCOUNTS);
Ok((self.accounts)()
.into_iter()
.map(Into::into)
.collect())
}
fn block_number(&self) -> Result<RpcU256> {

View File

@@ -16,7 +16,7 @@
//! Parity-specific rpc implementation.
use std::sync::Arc;
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use version::version_data;
@@ -24,12 +24,12 @@ use crypto::DEFAULT_MAC;
use ethkey::{crypto::ecies, Brain, Generator};
use ethstore::random_phrase;
use sync::LightSyncProvider;
use ethcore::account_provider::AccountProvider;
use ethcore_logger::RotatingLogger;
use jsonrpc_core::{Result, BoxFuture};
use jsonrpc_core::futures::{future, Future};
use v1::helpers::{self, errors, ipfs, SigningQueue, SignerService, NetworkSettings, verify_signature};
use v1::helpers::{self, errors, ipfs, NetworkSettings, verify_signature};
use v1::helpers::external_signer::{SignerService, SigningQueue};
use v1::helpers::dispatch::LightDispatcher;
use v1::helpers::light_fetch::{LightFetch, light_all_transactions};
use v1::metadata::Metadata;
@@ -40,7 +40,7 @@ use v1::types::{
TransactionStats, LocalTransactionStatus,
LightBlockNumber, ChainStatus, Receipt,
BlockNumber, ConsensusCapability, VersionInfo,
OperationsInfo, AccountInfo, HwAccountInfo, Header, RichHeader, RecoveredAccount,
OperationsInfo, Header, RichHeader, RecoveredAccount,
Log, Filter,
};
use Host;
@@ -48,7 +48,6 @@ use Host;
/// Parity implementation for light client.
pub struct ParityClient {
light_dispatch: Arc<LightDispatcher>,
accounts: Arc<AccountProvider>,
logger: Arc<RotatingLogger>,
settings: Arc<NetworkSettings>,
signer: Option<Arc<SignerService>>,
@@ -60,7 +59,6 @@ impl ParityClient {
/// Creates new `ParityClient`.
pub fn new(
light_dispatch: Arc<LightDispatcher>,
accounts: Arc<AccountProvider>,
logger: Arc<RotatingLogger>,
settings: Arc<NetworkSettings>,
signer: Option<Arc<SignerService>>,
@@ -69,7 +67,6 @@ impl ParityClient {
) -> Self {
ParityClient {
light_dispatch,
accounts,
logger,
settings,
signer,
@@ -93,49 +90,6 @@ impl ParityClient {
impl Parity for ParityClient {
type Metadata = Metadata;
fn accounts_info(&self) -> Result<BTreeMap<H160, AccountInfo>> {
let store = &self.accounts;
let dapp_accounts = store
.accounts()
.map_err(|e| errors::account("Could not fetch accounts.", e))?
.into_iter().collect::<HashSet<_>>();
let info = store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
let other = store.addresses_info();
Ok(info
.into_iter()
.chain(other.into_iter())
.filter(|&(ref a, _)| dapp_accounts.contains(a))
.map(|(a, v)| (H160::from(a), AccountInfo { name: v.name }))
.collect()
)
}
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
let store = &self.accounts;
let info = store.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
Ok(info
.into_iter()
.map(|(a, v)| (H160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta }))
.collect()
)
}
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
let store = &self.accounts;
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
}
fn default_account(&self) -> Result<H160> {
Ok(self.accounts
.accounts()
.ok()
.and_then(|accounts| accounts.get(0).cloned())
.map(|acc| acc.into())
.unwrap_or_default())
}
fn transactions_limit(&self) -> Result<usize> {
Ok(usize::max_value())
}

View File

@@ -67,7 +67,7 @@ impl<F: Fetch> ParitySet for ParitySetClient<F> {
Err(errors::light_unimplemented(None))
}
fn set_engine_signer(&self, _address: H160, _password: String) -> Result<bool> {
fn set_engine_signer_secret(&self, _secret: H256) -> Result<bool> {
Err(errors::light_unimplemented(None))
}