2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-04-11 21:06:32 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-04-11 21:06:32 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-04-11 21:06:32 +02:00
|
|
|
// 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
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-04-11 21:06:32 +02:00
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
//! Parity-specific rpc implementation.
|
2017-05-28 14:40:36 +02:00
|
|
|
use std::sync::Arc;
|
2016-08-17 19:25:02 +02:00
|
|
|
use std::str::FromStr;
|
2016-12-23 18:52:02 +01:00
|
|
|
use std::collections::{BTreeMap, HashSet};
|
2016-10-04 19:05:46 +02:00
|
|
|
|
2018-01-10 13:35:18 +01:00
|
|
|
use ethereum_types::Address;
|
2017-12-22 14:37:39 +01:00
|
|
|
use version::version_data;
|
2016-08-11 17:19:20 +02:00
|
|
|
|
2018-05-05 11:02:33 +02:00
|
|
|
use crypto::DEFAULT_MAC;
|
2017-08-04 15:58:14 +02:00
|
|
|
use ethcore::account_provider::AccountProvider;
|
2018-04-13 17:34:27 +02:00
|
|
|
use ethcore::client::{BlockChainClient, StateClient, Call};
|
|
|
|
use ethcore::miner::{self, MinerService};
|
2018-11-07 09:30:34 +01:00
|
|
|
use ethcore::snapshot::{SnapshotService, RestorationStatus};
|
2018-03-03 18:42:13 +01:00
|
|
|
use ethcore::state::StateInfo;
|
2017-08-28 14:11:55 +02:00
|
|
|
use ethcore_logger::RotatingLogger;
|
2019-01-04 14:05:46 +01:00
|
|
|
use ethkey::{crypto::ecies, Brain, Generator};
|
|
|
|
use ethstore::random_phrase;
|
2018-07-18 16:27:29 +02:00
|
|
|
use jsonrpc_core::futures::future;
|
2019-01-04 14:05:46 +01:00
|
|
|
use jsonrpc_core::{BoxFuture, Result};
|
2016-12-13 14:27:27 +01:00
|
|
|
use jsonrpc_macros::Trailing;
|
2019-01-04 14:05:46 +01:00
|
|
|
use sync::{SyncProvider, ManageNetwork};
|
|
|
|
use types::ids::BlockId;
|
|
|
|
use updater::{Service as UpdateService};
|
2018-11-07 09:30:34 +01:00
|
|
|
|
|
|
|
use v1::helpers::block_import::is_major_importing;
|
2018-11-28 12:18:43 +01:00
|
|
|
use v1::helpers::{self, errors, fake_sign, ipfs, SigningQueue, SignerService, NetworkSettings, verify_signature};
|
2017-01-30 11:10:58 +01:00
|
|
|
use v1::metadata::Metadata;
|
2016-11-06 12:51:53 +01:00
|
|
|
use v1::traits::Parity;
|
2016-11-16 17:54:54 +01:00
|
|
|
use v1::types::{
|
2018-11-28 12:18:43 +01:00
|
|
|
Bytes, U256, H64, U64, H160, H256, H512, CallRequest,
|
2016-11-16 17:54:54 +01:00
|
|
|
Peers, Transaction, RpcSettings, Histogram,
|
|
|
|
TransactionStats, LocalTransactionStatus,
|
2016-12-12 02:57:19 +01:00
|
|
|
BlockNumber, ConsensusCapability, VersionInfo,
|
2018-12-17 20:40:25 +01:00
|
|
|
OperationsInfo, ChainStatus, Log, Filter,
|
2018-11-28 12:18:43 +01:00
|
|
|
AccountInfo, HwAccountInfo, RichHeader, Receipt, RecoveredAccount,
|
2018-03-03 18:42:13 +01:00
|
|
|
block_number_to_id
|
2016-11-16 17:54:54 +01:00
|
|
|
};
|
2017-09-21 14:52:44 +02:00
|
|
|
use Host;
|
2016-04-11 21:06:32 +02:00
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Parity implementation.
|
2018-06-26 09:03:38 +02:00
|
|
|
pub struct ParityClient<C, M, U> {
|
2017-05-28 14:40:36 +02:00
|
|
|
client: Arc<C>,
|
|
|
|
miner: Arc<M>,
|
|
|
|
updater: Arc<U>,
|
2017-08-28 14:11:55 +02:00
|
|
|
sync: Arc<SyncProvider>,
|
2017-05-28 14:40:36 +02:00
|
|
|
net: Arc<ManageNetwork>,
|
2018-06-01 16:49:55 +02:00
|
|
|
accounts: Arc<AccountProvider>,
|
2016-04-19 09:58:26 +02:00
|
|
|
logger: Arc<RotatingLogger>,
|
2016-04-21 19:19:42 +02:00
|
|
|
settings: Arc<NetworkSettings>,
|
2016-09-21 12:44:49 +02:00
|
|
|
signer: Option<Arc<SignerService>>,
|
2017-09-21 14:52:44 +02:00
|
|
|
ws_address: Option<Host>,
|
2018-11-07 09:30:34 +01:00
|
|
|
snapshot: Option<Arc<SnapshotService>>,
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 14:11:55 +02:00
|
|
|
impl<C, M, U> ParityClient<C, M, U> where
|
2018-04-13 17:34:27 +02:00
|
|
|
C: BlockChainClient,
|
2016-11-06 12:51:53 +01:00
|
|
|
{
|
|
|
|
/// Creates new `ParityClient`.
|
2016-08-11 17:19:20 +02:00
|
|
|
pub fn new(
|
2017-08-28 14:11:55 +02:00
|
|
|
client: Arc<C>,
|
|
|
|
miner: Arc<M>,
|
|
|
|
sync: Arc<SyncProvider>,
|
|
|
|
updater: Arc<U>,
|
|
|
|
net: Arc<ManageNetwork>,
|
2018-06-01 16:49:55 +02:00
|
|
|
accounts: Arc<AccountProvider>,
|
2016-08-11 17:19:20 +02:00
|
|
|
logger: Arc<RotatingLogger>,
|
|
|
|
settings: Arc<NetworkSettings>,
|
2016-10-24 12:21:15 +02:00
|
|
|
signer: Option<Arc<SignerService>>,
|
2017-09-21 14:52:44 +02:00
|
|
|
ws_address: Option<Host>,
|
2018-11-07 09:30:34 +01:00
|
|
|
snapshot: Option<Arc<SnapshotService>>,
|
2016-08-17 19:25:02 +02:00
|
|
|
) -> Self {
|
2016-11-06 12:51:53 +01:00
|
|
|
ParityClient {
|
2017-08-28 14:11:55 +02:00
|
|
|
client,
|
|
|
|
miner,
|
|
|
|
sync,
|
|
|
|
updater,
|
|
|
|
net,
|
|
|
|
accounts,
|
|
|
|
logger,
|
|
|
|
settings,
|
|
|
|
signer,
|
|
|
|
ws_address,
|
2018-11-07 09:30:34 +01:00
|
|
|
snapshot,
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 18:42:13 +01:00
|
|
|
impl<C, M, U, S> Parity for ParityClient<C, M, U> where
|
|
|
|
S: StateInfo + 'static,
|
2018-04-13 17:34:27 +02:00
|
|
|
C: miner::BlockChainClient + BlockChainClient + StateClient<State=S> + Call<State=S> + 'static,
|
2018-03-03 18:42:13 +01:00
|
|
|
M: MinerService<State=S> + 'static,
|
2016-12-23 18:52:02 +01:00
|
|
|
U: UpdateService + 'static,
|
|
|
|
{
|
2017-01-30 11:10:58 +01:00
|
|
|
type Metadata = Metadata;
|
|
|
|
|
2018-08-07 14:52:23 +02:00
|
|
|
fn accounts_info(&self) -> Result<BTreeMap<H160, AccountInfo>> {
|
|
|
|
let dapp_accounts = self.accounts.accounts()
|
2017-03-10 10:25:13 +01:00
|
|
|
.map_err(|e| errors::account("Could not fetch accounts.", e))?
|
2016-12-27 12:53:56 +01:00
|
|
|
.into_iter().collect::<HashSet<_>>();
|
2016-12-23 18:52:02 +01:00
|
|
|
|
2018-06-04 11:26:30 +02:00
|
|
|
let info = self.accounts.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
|
|
|
|
let other = self.accounts.addresses_info();
|
2016-12-23 18:52:02 +01:00
|
|
|
|
|
|
|
Ok(info
|
|
|
|
.into_iter()
|
|
|
|
.chain(other.into_iter())
|
|
|
|
.filter(|&(ref a, _)| dapp_accounts.contains(a))
|
2017-02-10 01:07:06 +01:00
|
|
|
.map(|(a, v)| (H160::from(a), AccountInfo { name: v.name }))
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>> {
|
2018-06-04 11:26:30 +02:00
|
|
|
let info = self.accounts.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
|
2017-02-10 01:07:06 +01:00
|
|
|
Ok(info
|
|
|
|
.into_iter()
|
|
|
|
.map(|(a, v)| (H160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta }))
|
2016-12-23 18:52:02 +01:00
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
2018-07-16 13:42:59 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
|
2018-06-04 11:26:30 +02:00
|
|
|
self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))
|
2017-09-14 19:28:43 +02:00
|
|
|
}
|
2018-07-16 13:42:59 +02:00
|
|
|
|
2018-08-07 14:52:23 +02:00
|
|
|
fn default_account(&self) -> Result<H160> {
|
|
|
|
Ok(self.accounts.default_account()
|
2017-10-05 12:35:01 +02:00
|
|
|
.map(Into::into)
|
|
|
|
.ok()
|
|
|
|
.unwrap_or_default())
|
2017-01-30 11:10:58 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn transactions_limit(&self) -> Result<usize> {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(self.miner.queue_status().limits.max_count)
|
2016-04-18 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn min_gas_price(&self) -> Result<U256> {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(self.miner.queue_status().options.minimal_gas_price.into())
|
2016-04-13 00:04:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn extra_data(&self) -> Result<Bytes> {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(Bytes::new(self.miner.authoring_params().extra_data))
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn gas_floor_target(&self) -> Result<U256> {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(U256::from(self.miner.authoring_params().gas_range_target.0))
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
2016-04-19 09:58:26 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn gas_ceil_target(&self) -> Result<U256> {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(U256::from(self.miner.authoring_params().gas_range_target.1))
|
2016-06-23 14:29:16 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn dev_logs(&self) -> Result<Vec<String>> {
|
2019-01-08 15:07:20 +01:00
|
|
|
warn!("This method is deprecated and will be removed in future. See PR #10102");
|
2016-04-19 09:58:26 +02:00
|
|
|
let logs = self.logger.logs();
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(logs.as_slice().to_owned())
|
2016-04-19 09:58:26 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn dev_logs_levels(&self) -> Result<String> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(self.logger.levels().to_owned())
|
2016-04-19 09:58:26 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn net_chain(&self) -> Result<String> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(self.settings.chain.clone())
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn chain(&self) -> Result<String> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.client.spec_name())
|
2017-03-13 12:10:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn net_peers(&self) -> Result<Peers> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let sync_status = self.sync.status();
|
2018-06-01 09:49:46 +02:00
|
|
|
let num_peers_range = self.net.num_peers_range();
|
2019-01-22 09:51:40 +01:00
|
|
|
debug_assert!(num_peers_range.end() >= num_peers_range.start());
|
2017-05-28 14:40:36 +02:00
|
|
|
let peers = self.sync.peers().into_iter().map(Into::into).collect();
|
2016-08-11 17:19:20 +02:00
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(Peers {
|
2016-08-11 17:19:20 +02:00
|
|
|
active: sync_status.num_active_peers,
|
|
|
|
connected: sync_status.num_peers,
|
2019-01-22 09:51:40 +01:00
|
|
|
max: sync_status.current_max_peers(*num_peers_range.start(), *num_peers_range.end()),
|
2016-10-12 20:18:59 +02:00
|
|
|
peers: peers
|
2016-10-04 19:05:46 +02:00
|
|
|
})
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn net_port(&self) -> Result<u16> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(self.settings.network_port)
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn node_name(&self) -> Result<String> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(self.settings.name.clone())
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn registry_address(&self) -> Result<Option<H160>> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(
|
2017-05-28 14:40:36 +02:00
|
|
|
self.client
|
2016-10-04 19:05:46 +02:00
|
|
|
.additional_params()
|
|
|
|
.get("registrar")
|
|
|
|
.and_then(|s| Address::from_str(s).ok())
|
|
|
|
.map(|s| H160::from(s))
|
|
|
|
)
|
2016-08-17 19:25:02 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn rpc_settings(&self) -> Result<RpcSettings> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(RpcSettings {
|
|
|
|
enabled: self.settings.rpc_enabled,
|
|
|
|
interface: self.settings.rpc_interface.clone(),
|
|
|
|
port: self.settings.rpc_port as u64,
|
|
|
|
})
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
2016-05-02 16:12:01 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn default_extra_data(&self) -> Result<Bytes> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(Bytes::new(version_data()))
|
2016-06-16 12:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn gas_price_histogram(&self) -> BoxFuture<Histogram> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(self.client
|
2017-02-17 21:38:43 +01:00
|
|
|
.gas_price_corpus(100)
|
|
|
|
.histogram(10)
|
|
|
|
.ok_or_else(errors::not_enough_data)
|
|
|
|
.map(Into::into)
|
2017-10-05 12:35:01 +02:00
|
|
|
))
|
2016-05-02 16:12:01 +02:00
|
|
|
}
|
2016-06-21 14:55:25 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn unsigned_transactions_count(&self) -> Result<usize> {
|
2016-09-21 12:44:49 +02:00
|
|
|
match self.signer {
|
2016-08-08 17:25:15 +02:00
|
|
|
None => Err(errors::signer_disabled()),
|
2016-10-04 19:05:46 +02:00
|
|
|
Some(ref signer) => Ok(signer.len()),
|
2016-06-21 14:55:25 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-10 17:57:40 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn generate_secret_phrase(&self) -> Result<String> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(random_phrase(12))
|
2016-08-10 17:57:40 +02:00
|
|
|
}
|
2016-08-10 21:23:17 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn phrase_to_address(&self, phrase: String) -> Result<H160> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(Brain::new(phrase).generate().unwrap().address().into())
|
2016-08-10 21:23:17 +02:00
|
|
|
}
|
2016-09-22 14:48:22 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn list_accounts(&self, count: u64, after: Option<H160>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H160>>> {
|
2018-03-03 18:42:13 +01:00
|
|
|
let number = match block_number.unwrap_or_default() {
|
|
|
|
BlockNumber::Pending => {
|
|
|
|
warn!("BlockNumber::Pending is unsupported");
|
|
|
|
return Ok(None);
|
|
|
|
},
|
|
|
|
|
|
|
|
num => block_number_to_id(num)
|
|
|
|
};
|
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.client
|
2018-03-03 18:42:13 +01:00
|
|
|
.list_accounts(number, after.map(Into::into).as_ref(), count)
|
2016-10-04 19:05:46 +02:00
|
|
|
.map(|a| a.into_iter().map(Into::into).collect()))
|
2016-10-03 11:13:10 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn list_storage_keys(&self, address: H160, count: u64, after: Option<H256>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H256>>> {
|
2018-03-03 18:42:13 +01:00
|
|
|
let number = match block_number.unwrap_or_default() {
|
|
|
|
BlockNumber::Pending => {
|
|
|
|
warn!("BlockNumber::Pending is unsupported");
|
|
|
|
return Ok(None);
|
|
|
|
},
|
|
|
|
|
|
|
|
num => block_number_to_id(num)
|
|
|
|
};
|
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.client
|
2018-03-03 18:42:13 +01:00
|
|
|
.list_storage(number, &address.into(), after.map(Into::into).as_ref(), count)
|
2016-11-27 11:11:56 +01:00
|
|
|
.map(|a| a.into_iter().map(Into::into).collect()))
|
2016-10-03 11:13:10 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result<Bytes> {
|
2016-10-15 14:44:08 +02:00
|
|
|
ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0)
|
2017-07-04 17:01:06 +02:00
|
|
|
.map_err(errors::encryption)
|
2016-10-04 19:05:46 +02:00
|
|
|
.map(Into::into)
|
2016-09-22 14:48:22 +02:00
|
|
|
}
|
2016-09-23 18:13:03 +02:00
|
|
|
|
2018-06-12 08:22:54 +02:00
|
|
|
fn pending_transactions(&self, limit: Trailing<usize>) -> Result<Vec<Transaction>> {
|
|
|
|
let ready_transactions = self.miner.ready_transactions(
|
|
|
|
&*self.client,
|
|
|
|
limit.unwrap_or_else(usize::max_value),
|
|
|
|
miner::PendingOrdering::Priority,
|
|
|
|
);
|
2018-04-13 17:34:27 +02:00
|
|
|
|
|
|
|
Ok(ready_transactions
|
2018-06-26 09:03:38 +02:00
|
|
|
.into_iter()
|
2018-08-01 13:17:04 +02:00
|
|
|
.map(|t| Transaction::from_pending(t.pending().clone()))
|
2018-06-26 09:03:38 +02:00
|
|
|
.collect()
|
2018-06-12 08:22:54 +02:00
|
|
|
)
|
2016-09-23 18:13:03 +02:00
|
|
|
}
|
2016-09-27 16:27:06 +02:00
|
|
|
|
2018-04-13 17:34:27 +02:00
|
|
|
fn all_transactions(&self) -> Result<Vec<Transaction>> {
|
|
|
|
let all_transactions = self.miner.queued_transactions();
|
|
|
|
|
|
|
|
Ok(all_transactions
|
2018-06-26 09:03:38 +02:00
|
|
|
.into_iter()
|
2018-08-01 13:17:04 +02:00
|
|
|
.map(|t| Transaction::from_pending(t.pending().clone()))
|
2018-06-26 09:03:38 +02:00
|
|
|
.collect()
|
2018-04-13 17:34:27 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-10-27 09:38:35 +02:00
|
|
|
fn all_transaction_hashes(&self) -> Result<Vec<H256>> {
|
|
|
|
let all_transaction_hashes = self.miner.queued_transaction_hashes();
|
|
|
|
|
|
|
|
Ok(all_transaction_hashes
|
|
|
|
.into_iter()
|
|
|
|
.map(|hash| hash.into())
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:34:27 +02:00
|
|
|
fn future_transactions(&self) -> Result<Vec<Transaction>> {
|
|
|
|
Err(errors::deprecated("Use `parity_allTransaction` instead."))
|
2016-12-15 18:19:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let stats = self.sync.transactions_stats();
|
2016-11-16 13:37:21 +01:00
|
|
|
Ok(stats.into_iter()
|
2018-06-26 09:03:38 +02:00
|
|
|
.map(|(hash, stats)| (hash.into(), stats.into()))
|
|
|
|
.collect()
|
2016-11-16 13:37:21 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn local_transactions(&self) -> Result<BTreeMap<H256, LocalTransactionStatus>> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let transactions = self.miner.local_transactions();
|
2016-11-16 17:54:54 +01:00
|
|
|
Ok(transactions
|
2018-06-26 09:03:38 +02:00
|
|
|
.into_iter()
|
2018-08-01 13:17:04 +02:00
|
|
|
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status)))
|
2018-06-26 09:03:38 +02:00
|
|
|
.collect()
|
2016-11-16 17:54:54 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn ws_url(&self) -> Result<String> {
|
2017-05-24 12:24:07 +02:00
|
|
|
helpers::to_url(&self.ws_address)
|
2018-09-25 19:06:14 +02:00
|
|
|
.ok_or_else(errors::ws_disabled)
|
2016-11-09 19:41:47 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn next_nonce(&self, address: H160) -> BoxFuture<U256> {
|
2016-10-27 19:29:55 +02:00
|
|
|
let address: Address = address.into();
|
|
|
|
|
2018-04-13 17:34:27 +02:00
|
|
|
Box::new(future::ok(self.miner.next_nonce(&*self.client, &address).into()))
|
2016-10-27 19:29:55 +02:00
|
|
|
}
|
2016-10-31 16:58:35 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn mode(&self) -> Result<String> {
|
2018-06-06 14:14:45 +02:00
|
|
|
Ok(self.client.mode().to_string())
|
2016-10-31 16:58:35 +01:00
|
|
|
}
|
2016-11-02 19:43:21 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn enode(&self) -> Result<String> {
|
2017-05-28 14:40:36 +02:00
|
|
|
self.sync.enode().ok_or_else(errors::network_disabled)
|
2016-11-02 19:43:21 +01:00
|
|
|
}
|
2016-11-06 12:51:53 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn consensus_capability(&self) -> Result<ConsensusCapability> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.updater.capability().into())
|
2016-12-11 23:36:38 +01:00
|
|
|
}
|
2016-12-12 02:57:19 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn version_info(&self) -> Result<VersionInfo> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.updater.version_info().into())
|
2016-12-12 02:57:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn releases_info(&self) -> Result<Option<OperationsInfo>> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.updater.info().map(Into::into))
|
2016-12-12 02:57:19 +01:00
|
|
|
}
|
2016-12-19 15:27:17 +01:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn chain_status(&self) -> Result<ChainStatus> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let chain_info = self.client.chain_info();
|
2016-12-19 15:27:17 +01:00
|
|
|
|
|
|
|
let gap = chain_info.ancient_block_number.map(|x| U256::from(x + 1))
|
|
|
|
.and_then(|first| chain_info.first_block_number.map(|last| (first, U256::from(last))));
|
|
|
|
|
|
|
|
Ok(ChainStatus {
|
|
|
|
block_gap: gap.map(|(x, y)| (x.into(), y.into())),
|
|
|
|
})
|
|
|
|
}
|
2017-03-27 17:30:19 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn node_kind(&self) -> Result<::v1::types::NodeKind> {
|
2017-03-27 17:30:19 +02:00
|
|
|
use ::v1::types::{NodeKind, Availability, Capability};
|
|
|
|
|
|
|
|
Ok(NodeKind {
|
2018-06-01 16:49:55 +02:00
|
|
|
availability: Availability::Personal,
|
2017-03-27 17:30:19 +02:00
|
|
|
capability: Capability::Full,
|
|
|
|
})
|
|
|
|
}
|
2017-04-03 11:37:07 +02:00
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn block_header(&self, number: Trailing<BlockNumber>) -> BoxFuture<RichHeader> {
|
2018-03-03 18:42:13 +01:00
|
|
|
const EXTRA_INFO_PROOF: &str = "Object exists in blockchain (fetched earlier), extra_info is always available if object exists; qed";
|
|
|
|
let number = number.unwrap_or_default();
|
|
|
|
|
|
|
|
let (header, extra) = if number == BlockNumber::Pending {
|
|
|
|
let info = self.client.chain_info();
|
2018-09-25 19:06:14 +02:00
|
|
|
let header =
|
|
|
|
try_bf!(self.miner.pending_block_header(info.best_block_number).ok_or_else(errors::unknown_block));
|
2018-03-03 18:42:13 +01:00
|
|
|
|
|
|
|
(header.encoded(), None)
|
|
|
|
} else {
|
|
|
|
let id = match number {
|
|
|
|
BlockNumber::Num(num) => BlockId::Number(num),
|
|
|
|
BlockNumber::Earliest => BlockId::Earliest,
|
|
|
|
BlockNumber::Latest => BlockId::Latest,
|
|
|
|
BlockNumber::Pending => unreachable!(), // Already covered
|
|
|
|
};
|
|
|
|
|
2018-09-25 19:06:14 +02:00
|
|
|
let header = try_bf!(self.client.block_header(id.clone()).ok_or_else(errors::unknown_block));
|
2018-03-03 18:42:13 +01:00
|
|
|
let info = self.client.block_extra_info(id).expect(EXTRA_INFO_PROOF);
|
|
|
|
|
|
|
|
(header, Some(info))
|
2017-04-03 11:37:07 +02:00
|
|
|
};
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(RichHeader {
|
2018-03-03 18:42:13 +01:00
|
|
|
inner: header.into(),
|
|
|
|
extra_info: extra.unwrap_or_default(),
|
2017-10-05 12:35:01 +02:00
|
|
|
}))
|
2017-04-03 11:37:07 +02:00
|
|
|
}
|
2017-04-10 19:53:53 +02:00
|
|
|
|
2018-09-25 19:06:14 +02:00
|
|
|
fn block_receipts(&self, number: Trailing<BlockNumber>) -> BoxFuture<Vec<Receipt>> {
|
|
|
|
let number = number.unwrap_or_default();
|
|
|
|
|
|
|
|
let id = match number {
|
|
|
|
BlockNumber::Pending => {
|
|
|
|
let info = self.client.chain_info();
|
|
|
|
let receipts = try_bf!(self.miner.pending_receipts(info.best_block_number).ok_or_else(errors::unknown_block));
|
|
|
|
return Box::new(future::ok(receipts
|
|
|
|
.into_iter()
|
|
|
|
.map(Into::into)
|
|
|
|
.collect()
|
|
|
|
))
|
|
|
|
},
|
|
|
|
BlockNumber::Num(num) => BlockId::Number(num),
|
|
|
|
BlockNumber::Earliest => BlockId::Earliest,
|
|
|
|
BlockNumber::Latest => BlockId::Latest,
|
|
|
|
};
|
2018-11-18 00:06:34 +01:00
|
|
|
let receipts = try_bf!(self.client.localized_block_receipts(id).ok_or_else(errors::unknown_block));
|
2018-09-25 19:06:14 +02:00
|
|
|
Box::new(future::ok(receipts.into_iter().map(Into::into).collect()))
|
|
|
|
}
|
|
|
|
|
2017-11-14 11:38:17 +01:00
|
|
|
fn ipfs_cid(&self, content: Bytes) -> Result<String> {
|
2017-04-08 13:35:23 +02:00
|
|
|
ipfs::cid(content)
|
|
|
|
}
|
2017-08-04 15:58:14 +02:00
|
|
|
|
2018-08-07 14:52:23 +02:00
|
|
|
fn call(&self, requests: Vec<CallRequest>, num: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
|
2017-10-05 12:35:01 +02:00
|
|
|
let requests = requests
|
2017-08-04 15:58:14 +02:00
|
|
|
.into_iter()
|
|
|
|
.map(|request| Ok((
|
2018-08-07 14:52:23 +02:00
|
|
|
fake_sign::sign_call(request.into())?,
|
2017-08-04 15:58:14 +02:00
|
|
|
Default::default()
|
|
|
|
)))
|
2017-11-14 11:38:17 +01:00
|
|
|
.collect::<Result<Vec<_>>>()?;
|
2017-08-04 15:58:14 +02:00
|
|
|
|
2018-03-03 18:42:13 +01:00
|
|
|
let num = num.unwrap_or_default();
|
|
|
|
|
|
|
|
let (mut state, header) = if num == BlockNumber::Pending {
|
|
|
|
let info = self.client.chain_info();
|
2018-09-25 19:06:14 +02:00
|
|
|
let state = self.miner.pending_state(info.best_block_number).ok_or_else(errors::state_pruned)?;
|
|
|
|
let header = self.miner.pending_block_header(info.best_block_number).ok_or_else(errors::state_pruned)?;
|
2018-03-03 18:42:13 +01:00
|
|
|
|
|
|
|
(state, header)
|
|
|
|
} else {
|
|
|
|
let id = match num {
|
|
|
|
BlockNumber::Num(num) => BlockId::Number(num),
|
|
|
|
BlockNumber::Earliest => BlockId::Earliest,
|
|
|
|
BlockNumber::Latest => BlockId::Latest,
|
|
|
|
BlockNumber::Pending => unreachable!(), // Already covered
|
|
|
|
};
|
|
|
|
|
2018-09-25 19:06:14 +02:00
|
|
|
let state = self.client.state_at(id).ok_or_else(errors::state_pruned)?;
|
|
|
|
let header = self.client.block_header(id).ok_or_else(errors::state_pruned)?.decode().map_err(errors::decode)?;
|
2018-03-03 18:42:13 +01:00
|
|
|
|
2018-05-09 12:05:56 +02:00
|
|
|
(state, header)
|
2018-03-03 18:42:13 +01:00
|
|
|
};
|
2017-08-04 15:58:14 +02:00
|
|
|
|
2018-03-03 18:42:13 +01:00
|
|
|
self.client.call_many(&requests, &mut state, &header)
|
2017-08-04 15:58:14 +02:00
|
|
|
.map(|res| res.into_iter().map(|res| res.output.into()).collect())
|
2017-10-05 12:35:01 +02:00
|
|
|
.map_err(errors::call)
|
2017-08-04 15:58:14 +02:00
|
|
|
}
|
2018-10-02 21:02:48 +02:00
|
|
|
|
|
|
|
fn submit_work_detail(&self, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result<H256> {
|
|
|
|
helpers::submit_work_detail(&self.client, &self.miner, nonce, pow_hash, mix_hash)
|
|
|
|
}
|
2018-11-07 09:30:34 +01:00
|
|
|
|
|
|
|
fn status(&self) -> Result<()> {
|
|
|
|
let has_peers = self.settings.is_dev_chain || self.sync.status().num_peers > 0;
|
|
|
|
let is_warping = match self.snapshot.as_ref().map(|s| s.status()) {
|
|
|
|
Some(RestorationStatus::Ongoing { .. }) => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
let is_not_syncing =
|
|
|
|
!is_warping &&
|
|
|
|
!is_major_importing(Some(self.sync.status().state), self.client.queue_info());
|
|
|
|
|
|
|
|
if has_peers && is_not_syncing {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(errors::status_error(has_peers))
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 12:18:43 +01:00
|
|
|
|
2018-12-17 20:40:25 +01:00
|
|
|
fn logs_no_tx_hash(&self, filter: Filter) -> BoxFuture<Vec<Log>> {
|
|
|
|
use v1::impls::eth::base_logs;
|
|
|
|
// only specific impl for lightclient
|
|
|
|
base_logs(&*self.client, &*self.miner, filter.into())
|
|
|
|
}
|
|
|
|
|
2018-11-28 12:18:43 +01:00
|
|
|
fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result<RecoveredAccount> {
|
|
|
|
verify_signature(is_prefixed, message, r, s, v, self.client.signing_chain_id())
|
|
|
|
}
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|