2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-04-11 21:06:32 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
//! Parity-specific rpc implementation.
|
|
|
|
use std::sync::{Arc, Weak};
|
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};
|
2017-02-20 16:33:12 +01:00
|
|
|
use futures::{future, Future, BoxFuture};
|
2016-10-04 19:05:46 +02:00
|
|
|
|
2017-03-22 06:23:40 +01:00
|
|
|
use ethcore_logger::RotatingLogger;
|
|
|
|
use util::Address;
|
2016-08-17 19:25:02 +02:00
|
|
|
use util::misc::version_data;
|
2016-08-11 17:19:20 +02:00
|
|
|
|
2016-09-22 14:48:22 +02:00
|
|
|
use crypto::ecies;
|
2016-08-24 18:35:21 +02:00
|
|
|
use ethkey::{Brain, Generator};
|
2016-08-10 17:57:40 +02:00
|
|
|
use ethstore::random_phrase;
|
2016-08-11 17:19:20 +02:00
|
|
|
use ethsync::{SyncProvider, ManageNetwork};
|
2017-04-03 11:37:07 +02:00
|
|
|
use ethcore::ids::BlockId;
|
2016-08-11 17:19:20 +02:00
|
|
|
use ethcore::miner::MinerService;
|
2016-06-16 12:44:08 +02:00
|
|
|
use ethcore::client::{MiningBlockChainClient};
|
2016-10-31 16:58:35 +01:00
|
|
|
use ethcore::mode::Mode;
|
2016-11-06 12:51:53 +01:00
|
|
|
use ethcore::account_provider::AccountProvider;
|
2016-12-11 23:15:52 +01:00
|
|
|
use updater::{Service as UpdateService};
|
2016-08-11 17:19:20 +02:00
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
use jsonrpc_core::Error;
|
2016-12-13 14:27:27 +01:00
|
|
|
use jsonrpc_macros::Trailing;
|
2017-04-08 13:35:23 +02:00
|
|
|
use v1::helpers::{errors, ipfs, SigningQueue, SignerService, NetworkSettings};
|
2017-03-29 17:07:58 +02:00
|
|
|
use v1::helpers::accounts::unwrap_provider;
|
2017-01-30 21:08:36 +01:00
|
|
|
use v1::helpers::dispatch::DEFAULT_MAC;
|
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::{
|
|
|
|
Bytes, U256, H160, H256, H512,
|
|
|
|
Peers, Transaction, RpcSettings, Histogram,
|
|
|
|
TransactionStats, LocalTransactionStatus,
|
2016-12-12 02:57:19 +01:00
|
|
|
BlockNumber, ConsensusCapability, VersionInfo,
|
2016-12-23 18:52:02 +01:00
|
|
|
OperationsInfo, DappId, ChainStatus,
|
2017-04-03 11:37:07 +02:00
|
|
|
AccountInfo, HwAccountInfo, Header, RichHeader
|
2016-11-16 17:54:54 +01:00
|
|
|
};
|
2016-04-11 21:06:32 +02:00
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Parity implementation.
|
2016-12-11 23:15:52 +01:00
|
|
|
pub struct ParityClient<C, M, S: ?Sized, U> where
|
2016-06-16 12:44:08 +02:00
|
|
|
C: MiningBlockChainClient,
|
2016-08-11 17:19:20 +02:00
|
|
|
M: MinerService,
|
2016-09-27 16:27:06 +02:00
|
|
|
S: SyncProvider,
|
2016-12-11 23:15:52 +01:00
|
|
|
U: UpdateService,
|
2016-11-06 12:51:53 +01:00
|
|
|
{
|
2016-06-16 12:44:08 +02:00
|
|
|
client: Weak<C>,
|
2016-04-11 21:06:32 +02:00
|
|
|
miner: Weak<M>,
|
2016-08-11 17:19:20 +02:00
|
|
|
sync: Weak<S>,
|
2016-12-11 23:15:52 +01:00
|
|
|
updater: Weak<U>,
|
2016-08-11 17:19:20 +02:00
|
|
|
net: Weak<ManageNetwork>,
|
2017-03-29 17:07:58 +02:00
|
|
|
accounts: Option<Weak<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>>,
|
2016-11-09 19:41:47 +01:00
|
|
|
dapps_interface: Option<String>,
|
2016-10-24 12:21:15 +02:00
|
|
|
dapps_port: Option<u16>,
|
2017-04-19 14:30:00 +02:00
|
|
|
eip86_transition: u64,
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:15:52 +01:00
|
|
|
impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
|
2016-09-27 16:27:06 +02:00
|
|
|
C: MiningBlockChainClient,
|
|
|
|
M: MinerService,
|
2016-11-06 12:51:53 +01:00
|
|
|
S: SyncProvider,
|
2016-12-11 23:15:52 +01:00
|
|
|
U: UpdateService,
|
2016-11-06 12:51:53 +01:00
|
|
|
{
|
|
|
|
/// Creates new `ParityClient`.
|
2016-08-11 17:19:20 +02:00
|
|
|
pub fn new(
|
|
|
|
client: &Arc<C>,
|
|
|
|
miner: &Arc<M>,
|
|
|
|
sync: &Arc<S>,
|
2016-12-11 23:15:52 +01:00
|
|
|
updater: &Arc<U>,
|
2016-08-11 17:19:20 +02:00
|
|
|
net: &Arc<ManageNetwork>,
|
2017-03-29 17:07:58 +02:00
|
|
|
store: &Option<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>>,
|
2016-11-09 19:41:47 +01:00
|
|
|
dapps_interface: Option<String>,
|
2016-10-24 12:21:15 +02:00
|
|
|
dapps_port: Option<u16>,
|
2016-08-17 19:25:02 +02:00
|
|
|
) -> Self {
|
2016-11-06 12:51:53 +01:00
|
|
|
ParityClient {
|
2016-06-16 12:44:08 +02:00
|
|
|
client: Arc::downgrade(client),
|
2016-04-19 09:58:26 +02:00
|
|
|
miner: Arc::downgrade(miner),
|
2016-08-11 17:19:20 +02:00
|
|
|
sync: Arc::downgrade(sync),
|
2016-12-11 23:15:52 +01:00
|
|
|
updater: Arc::downgrade(updater),
|
2016-08-11 17:19:20 +02:00
|
|
|
net: Arc::downgrade(net),
|
2017-03-29 17:07:58 +02:00
|
|
|
accounts: store.as_ref().map(Arc::downgrade),
|
2016-04-19 09:58:26 +02:00
|
|
|
logger: logger,
|
2016-04-21 19:19:42 +02:00
|
|
|
settings: settings,
|
2016-09-21 12:44:49 +02:00
|
|
|
signer: signer,
|
2016-11-09 19:41:47 +01:00
|
|
|
dapps_interface: dapps_interface,
|
2016-10-24 12:21:15 +02:00
|
|
|
dapps_port: dapps_port,
|
2017-04-19 14:30:00 +02:00
|
|
|
eip86_transition: client.eip86_transition(),
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 17:07:58 +02:00
|
|
|
|
|
|
|
/// Attempt to get the `Arc<AccountProvider>`, errors if provider was not
|
|
|
|
/// set, or if upgrading the weak reference failed.
|
|
|
|
fn account_provider(&self) -> Result<Arc<AccountProvider>, Error> {
|
|
|
|
unwrap_provider(&self.accounts)
|
|
|
|
}
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:15:52 +01:00
|
|
|
impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
|
2016-09-27 16:27:06 +02:00
|
|
|
M: MinerService + 'static,
|
|
|
|
C: MiningBlockChainClient + 'static,
|
2016-12-11 23:15:52 +01:00
|
|
|
S: SyncProvider + 'static,
|
2016-12-23 18:52:02 +01:00
|
|
|
U: UpdateService + 'static,
|
|
|
|
{
|
2017-01-30 11:10:58 +01:00
|
|
|
type Metadata = Metadata;
|
|
|
|
|
2017-02-10 01:07:06 +01:00
|
|
|
fn accounts_info(&self, dapp: Trailing<DappId>) -> Result<BTreeMap<H160, AccountInfo>, Error> {
|
2016-12-23 18:52:02 +01:00
|
|
|
let dapp = dapp.0;
|
|
|
|
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2016-12-27 12:53:56 +01:00
|
|
|
let dapp_accounts = store
|
2016-12-23 18:52:02 +01:00
|
|
|
.note_dapp_used(dapp.clone().into())
|
2017-02-20 16:33:12 +01:00
|
|
|
.and_then(|_| store.dapp_addresses(dapp.into()))
|
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
|
|
|
|
2016-12-27 12:53:56 +01:00
|
|
|
let info = store.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?;
|
2017-02-03 13:56:48 +01:00
|
|
|
let other = store.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()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>, Error> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-02-10 01:07:06 +01:00
|
|
|
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 }))
|
2016-12-23 18:52:02 +01:00
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
2016-04-13 00:04:40 +02:00
|
|
|
|
2017-01-30 11:10:58 +01:00
|
|
|
fn default_account(&self, meta: Self::Metadata) -> BoxFuture<H160, Error> {
|
2017-02-14 22:45:43 +01:00
|
|
|
let dapp_id = meta.dapp_id();
|
2017-02-20 16:33:12 +01:00
|
|
|
future::ok(
|
2017-03-29 17:07:58 +02:00
|
|
|
try_bf!(self.account_provider())
|
2017-02-20 16:33:12 +01:00
|
|
|
.dapp_default_address(dapp_id.into())
|
|
|
|
.map(Into::into)
|
2017-01-30 11:10:58 +01:00
|
|
|
.ok()
|
2017-02-20 16:33:12 +01:00
|
|
|
.unwrap_or_default()
|
|
|
|
).boxed()
|
2017-01-30 11:10:58 +01:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn transactions_limit(&self) -> Result<usize, Error> {
|
|
|
|
Ok(take_weak!(self.miner).transactions_limit())
|
2016-04-18 23:13:38 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn min_gas_price(&self) -> Result<U256, Error> {
|
|
|
|
Ok(U256::from(take_weak!(self.miner).minimal_gas_price()))
|
2016-04-13 00:04:40 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn extra_data(&self) -> Result<Bytes, Error> {
|
|
|
|
Ok(Bytes::new(take_weak!(self.miner).extra_data()))
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn gas_floor_target(&self) -> Result<U256, Error> {
|
|
|
|
Ok(U256::from(take_weak!(self.miner).gas_floor_target()))
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|
2016-04-19 09:58:26 +02:00
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn gas_ceil_target(&self) -> Result<U256, Error> {
|
|
|
|
Ok(U256::from(take_weak!(self.miner).gas_ceil_target()))
|
2016-06-23 14:29:16 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn dev_logs(&self) -> Result<Vec<String>, Error> {
|
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
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn dev_logs_levels(&self) -> Result<String, Error> {
|
|
|
|
Ok(self.logger.levels().to_owned())
|
2016-04-19 09:58:26 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn net_chain(&self) -> Result<String, Error> {
|
|
|
|
Ok(self.settings.chain.clone())
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-13 12:10:53 +01:00
|
|
|
fn chain(&self) -> Result<String, Error> {
|
|
|
|
Ok(take_weak!(self.client).spec_name())
|
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn net_peers(&self) -> Result<Peers, Error> {
|
2016-10-12 20:18:59 +02:00
|
|
|
let sync = take_weak!(self.sync);
|
|
|
|
let sync_status = sync.status();
|
2016-08-11 17:19:20 +02:00
|
|
|
let net_config = take_weak!(self.net).network_config();
|
2016-10-12 20:18:59 +02:00
|
|
|
let peers = 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,
|
|
|
|
max: sync_status.current_max_peers(net_config.min_peers, net_config.max_peers),
|
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
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn net_port(&self) -> Result<u16, Error> {
|
|
|
|
Ok(self.settings.network_port)
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn node_name(&self) -> Result<String, Error> {
|
|
|
|
Ok(self.settings.name.clone())
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn registry_address(&self) -> Result<Option<H160>, Error> {
|
|
|
|
Ok(
|
|
|
|
take_weak!(self.client)
|
|
|
|
.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
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn rpc_settings(&self) -> Result<RpcSettings, Error> {
|
|
|
|
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
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn default_extra_data(&self) -> Result<Bytes, Error> {
|
|
|
|
Ok(Bytes::new(version_data()))
|
2016-06-16 12:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 21:38:43 +01:00
|
|
|
fn gas_price_histogram(&self) -> BoxFuture<Histogram, Error> {
|
|
|
|
future::done(take_weakf!(self.client)
|
|
|
|
.gas_price_corpus(100)
|
|
|
|
.histogram(10)
|
|
|
|
.ok_or_else(errors::not_enough_data)
|
|
|
|
.map(Into::into)
|
|
|
|
).boxed()
|
2016-05-02 16:12:01 +02:00
|
|
|
}
|
2016-06-21 14:55:25 +02:00
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn unsigned_transactions_count(&self) -> Result<usize, Error> {
|
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
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn generate_secret_phrase(&self) -> Result<String, Error> {
|
|
|
|
Ok(random_phrase(12))
|
2016-08-10 17:57:40 +02:00
|
|
|
}
|
2016-08-10 21:23:17 +02:00
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn phrase_to_address(&self, phrase: String) -> Result<H160, Error> {
|
|
|
|
Ok(Brain::new(phrase).generate().unwrap().address().into())
|
2016-08-10 21:23:17 +02:00
|
|
|
}
|
2016-09-22 14:48:22 +02:00
|
|
|
|
2016-11-28 01:32:40 +01:00
|
|
|
fn list_accounts(&self, count: u64, after: Option<H160>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H160>>, Error> {
|
2016-10-04 19:05:46 +02:00
|
|
|
Ok(take_weak!(self.client)
|
2016-11-28 01:32:40 +01:00
|
|
|
.list_accounts(block_number.0.into(), 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
|
|
|
}
|
|
|
|
|
2016-11-28 01:32:40 +01:00
|
|
|
fn list_storage_keys(&self, address: H160, count: u64, after: Option<H256>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H256>>, Error> {
|
2016-11-27 11:11:56 +01:00
|
|
|
Ok(take_weak!(self.client)
|
2016-11-28 01:32:40 +01:00
|
|
|
.list_storage(block_number.0.into(), &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
|
|
|
}
|
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result<Bytes, Error> {
|
2016-10-15 14:44:08 +02:00
|
|
|
ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0)
|
|
|
|
.map_err(errors::encryption_error)
|
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
|
|
|
|
2016-10-04 19:05:46 +02:00
|
|
|
fn pending_transactions(&self) -> Result<Vec<Transaction>, Error> {
|
2017-04-19 14:30:00 +02:00
|
|
|
let block_number = take_weak!(self.client).chain_info().best_block_number;
|
|
|
|
Ok(take_weak!(self.miner).pending_transactions().into_iter().map(|t| Transaction::from_pending(t, block_number, self.eip86_transition)).collect::<Vec<_>>())
|
2016-09-23 18:13:03 +02:00
|
|
|
}
|
2016-09-27 16:27:06 +02:00
|
|
|
|
2016-12-15 18:19:19 +01:00
|
|
|
fn future_transactions(&self) -> Result<Vec<Transaction>, Error> {
|
2017-04-19 14:30:00 +02:00
|
|
|
let block_number = take_weak!(self.client).chain_info().best_block_number;
|
|
|
|
Ok(take_weak!(self.miner).future_transactions().into_iter().map(|t| Transaction::from_pending(t, block_number, self.eip86_transition)).collect::<Vec<_>>())
|
2016-12-15 18:19:19 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 13:37:21 +01:00
|
|
|
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>, Error> {
|
|
|
|
let stats = take_weak!(self.sync).transactions_stats();
|
|
|
|
Ok(stats.into_iter()
|
|
|
|
.map(|(hash, stats)| (hash.into(), stats.into()))
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:54:54 +01:00
|
|
|
fn local_transactions(&self) -> Result<BTreeMap<H256, LocalTransactionStatus>, Error> {
|
|
|
|
let transactions = take_weak!(self.miner).local_transactions();
|
2017-04-19 14:30:00 +02:00
|
|
|
let block_number = take_weak!(self.client).chain_info().best_block_number;
|
2016-11-16 17:54:54 +01:00
|
|
|
Ok(transactions
|
|
|
|
.into_iter()
|
2017-04-19 14:30:00 +02:00
|
|
|
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
|
2016-11-16 17:54:54 +01:00
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-10-24 12:21:15 +02:00
|
|
|
fn signer_port(&self) -> Result<u16, Error> {
|
|
|
|
self.signer
|
|
|
|
.clone()
|
2016-11-09 19:41:47 +01:00
|
|
|
.and_then(|signer| signer.address())
|
|
|
|
.map(|address| address.1)
|
2016-10-24 12:21:15 +02:00
|
|
|
.ok_or_else(|| errors::signer_disabled())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dapps_port(&self) -> Result<u16, Error> {
|
|
|
|
self.dapps_port
|
|
|
|
.ok_or_else(|| errors::dapps_disabled())
|
|
|
|
}
|
2016-10-27 19:29:55 +02:00
|
|
|
|
2016-11-09 19:41:47 +01:00
|
|
|
fn dapps_interface(&self) -> Result<String, Error> {
|
|
|
|
self.dapps_interface.clone()
|
|
|
|
.ok_or_else(|| errors::dapps_disabled())
|
|
|
|
}
|
|
|
|
|
2017-02-17 21:38:43 +01:00
|
|
|
fn next_nonce(&self, address: H160) -> BoxFuture<U256, Error> {
|
2016-10-27 19:29:55 +02:00
|
|
|
let address: Address = address.into();
|
2017-02-17 21:38:43 +01:00
|
|
|
let miner = take_weakf!(self.miner);
|
|
|
|
let client = take_weakf!(self.client);
|
2016-10-27 19:29:55 +02:00
|
|
|
|
2017-02-17 21:38:43 +01:00
|
|
|
future::ok(miner.last_nonce(&address)
|
2016-10-27 19:29:55 +02:00
|
|
|
.map(|n| n + 1.into())
|
|
|
|
.unwrap_or_else(|| client.latest_nonce(&address))
|
|
|
|
.into()
|
2017-02-17 21:38:43 +01:00
|
|
|
).boxed()
|
2016-10-27 19:29:55 +02:00
|
|
|
}
|
2016-10-31 16:58:35 +01:00
|
|
|
|
|
|
|
fn mode(&self) -> Result<String, Error> {
|
|
|
|
Ok(match take_weak!(self.client).mode() {
|
2016-11-05 10:38:00 +01:00
|
|
|
Mode::Off => "offline",
|
2016-10-31 16:58:35 +01:00
|
|
|
Mode::Dark(..) => "dark",
|
|
|
|
Mode::Passive(..) => "passive",
|
|
|
|
Mode::Active => "active",
|
|
|
|
}.into())
|
|
|
|
}
|
2016-11-02 19:43:21 +01:00
|
|
|
|
|
|
|
fn enode(&self) -> Result<String, Error> {
|
|
|
|
take_weak!(self.sync).enode().ok_or_else(errors::network_disabled)
|
|
|
|
}
|
2016-11-06 12:51:53 +01:00
|
|
|
|
2016-12-11 23:36:38 +01:00
|
|
|
fn consensus_capability(&self) -> Result<ConsensusCapability, Error> {
|
|
|
|
let updater = take_weak!(self.updater);
|
|
|
|
Ok(updater.capability().into())
|
|
|
|
}
|
2016-12-12 02:57:19 +01:00
|
|
|
|
|
|
|
fn version_info(&self) -> Result<VersionInfo, Error> {
|
|
|
|
let updater = take_weak!(self.updater);
|
|
|
|
Ok(updater.version_info().into())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn releases_info(&self) -> Result<Option<OperationsInfo>, Error> {
|
|
|
|
let updater = take_weak!(self.updater);
|
|
|
|
Ok(updater.info().map(Into::into))
|
|
|
|
}
|
2016-12-19 15:27:17 +01:00
|
|
|
|
|
|
|
fn chain_status(&self) -> Result<ChainStatus, Error> {
|
|
|
|
let chain_info = take_weak!(self.client).chain_info();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
fn node_kind(&self) -> Result<::v1::types::NodeKind, Error> {
|
|
|
|
use ::v1::types::{NodeKind, Availability, Capability};
|
|
|
|
|
2017-03-29 17:07:58 +02:00
|
|
|
let availability = match self.accounts {
|
|
|
|
Some(_) => Availability::Personal,
|
|
|
|
None => Availability::Public
|
|
|
|
};
|
|
|
|
|
2017-03-27 17:30:19 +02:00
|
|
|
Ok(NodeKind {
|
2017-03-29 17:07:58 +02:00
|
|
|
availability: availability,
|
2017-03-27 17:30:19 +02:00
|
|
|
capability: Capability::Full,
|
|
|
|
})
|
|
|
|
}
|
2017-04-03 11:37:07 +02:00
|
|
|
|
|
|
|
fn block_header(&self, number: Trailing<BlockNumber>) -> BoxFuture<Option<RichHeader>, Error> {
|
|
|
|
const EXTRA_INFO_PROOF: &'static str = "Object exists in in blockchain (fetched earlier), extra_info is always available if object exists; qed";
|
|
|
|
|
|
|
|
let client = take_weakf!(self.client);
|
|
|
|
let id: BlockId = number.0.into();
|
|
|
|
let encoded = match client.block_header(id.clone()) {
|
|
|
|
Some(encoded) => encoded,
|
|
|
|
None => return future::ok(None).boxed(),
|
|
|
|
};
|
|
|
|
|
|
|
|
future::ok(Some(RichHeader {
|
|
|
|
inner: Header {
|
|
|
|
hash: Some(encoded.hash().into()),
|
|
|
|
size: Some(encoded.rlp().as_raw().len().into()),
|
|
|
|
parent_hash: encoded.parent_hash().into(),
|
|
|
|
uncles_hash: encoded.uncles_hash().into(),
|
|
|
|
author: encoded.author().into(),
|
|
|
|
miner: encoded.author().into(),
|
|
|
|
state_root: encoded.state_root().into(),
|
|
|
|
transactions_root: encoded.transactions_root().into(),
|
|
|
|
receipts_root: encoded.receipts_root().into(),
|
|
|
|
number: Some(encoded.number().into()),
|
|
|
|
gas_used: encoded.gas_used().into(),
|
|
|
|
gas_limit: encoded.gas_limit().into(),
|
|
|
|
logs_bloom: encoded.log_bloom().into(),
|
|
|
|
timestamp: encoded.timestamp().into(),
|
|
|
|
difficulty: encoded.difficulty().into(),
|
|
|
|
seal_fields: encoded.seal().into_iter().map(Into::into).collect(),
|
|
|
|
extra_data: Bytes::new(encoded.extra_data()),
|
|
|
|
},
|
|
|
|
extra_info: client.block_extra_info(id).expect(EXTRA_INFO_PROOF),
|
|
|
|
})).boxed()
|
2017-04-10 18:06:36 +02:00
|
|
|
}
|
2017-04-10 18:06:28 +02:00
|
|
|
|
2017-04-08 13:35:23 +02:00
|
|
|
fn ipfs_cid(&self, content: Bytes) -> Result<String, Error> {
|
|
|
|
ipfs::cid(content)
|
2017-04-03 11:37:07 +02:00
|
|
|
}
|
2016-04-11 21:06:32 +02:00
|
|
|
}
|