2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-06-01 19:37:34 +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-06-01 19:37:34 +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-06-01 19:37:34 +02:00
|
|
|
|
2017-02-04 22:18:19 +01:00
|
|
|
use std::cmp::PartialEq;
|
2017-11-12 12:36:41 +01:00
|
|
|
use std::collections::{BTreeMap, HashSet};
|
2016-06-01 19:37:34 +02:00
|
|
|
use std::str::FromStr;
|
2017-05-23 12:26:39 +02:00
|
|
|
use std::sync::{Arc, Weak};
|
2017-02-04 22:18:19 +01:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
pub use parity_rpc::signer::SignerService;
|
2017-02-04 22:18:19 +01:00
|
|
|
|
2019-02-07 14:34:24 +01:00
|
|
|
use account_utils::{self, AccountProvider};
|
2017-02-04 22:18:19 +01:00
|
|
|
use ethcore::client::Client;
|
2018-01-11 17:49:10 +01:00
|
|
|
use ethcore::miner::Miner;
|
2016-10-31 17:32:53 +01:00
|
|
|
use ethcore::snapshot::SnapshotService;
|
2019-08-15 17:59:22 +02:00
|
|
|
use client_traits::BlockChainClient;
|
2019-04-02 17:13:55 +02:00
|
|
|
use sync::SyncState;
|
2017-08-28 14:11:55 +02:00
|
|
|
use ethcore_logger::RotatingLogger;
|
2018-11-26 19:58:27 +01:00
|
|
|
use ethcore_private_tx::Provider as PrivateTransactionManager;
|
|
|
|
use ethcore_service::PrivateTxService;
|
2016-12-22 18:26:39 +01:00
|
|
|
use hash_fetch::fetch::Client as FetchClient;
|
2017-05-06 13:24:18 +02:00
|
|
|
use jsonrpc_core::{self as core, MetaIoHandler};
|
2017-09-05 17:54:05 +02:00
|
|
|
use light::client::LightChainClient;
|
2018-11-26 19:58:27 +01:00
|
|
|
use light::{Cache as LightDataCache, TransactionQueue as LightTransactionQueue};
|
2018-01-11 17:49:10 +01:00
|
|
|
use miner::external::ExternalMiner;
|
2017-08-28 14:11:55 +02:00
|
|
|
use parity_rpc::dispatch::{FullDispatcher, LightDispatcher};
|
|
|
|
use parity_rpc::informant::{ActivityNotifier, ClientNotifier};
|
2018-11-26 19:58:27 +01:00
|
|
|
use parity_rpc::{Host, Metadata, NetworkSettings};
|
2019-04-12 13:36:49 +02:00
|
|
|
use parity_rpc::v1::traits::TransactionsPool;
|
2018-11-26 19:58:27 +01:00
|
|
|
use parity_runtime::Executor;
|
2017-09-02 20:09:13 +02:00
|
|
|
use parking_lot::{Mutex, RwLock};
|
2018-11-26 19:58:27 +01:00
|
|
|
use sync::{LightSync, ManageNetwork, SyncProvider};
|
2018-01-11 17:49:10 +01:00
|
|
|
use updater::Updater;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
2016-06-01 19:37:34 +02:00
|
|
|
pub enum Api {
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Web3 (Safe)
|
2016-06-01 19:37:34 +02:00
|
|
|
Web3,
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Net (Safe)
|
2016-06-01 19:37:34 +02:00
|
|
|
Net,
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Eth (Safe)
|
2016-06-01 19:37:34 +02:00
|
|
|
Eth,
|
2017-05-23 12:26:39 +02:00
|
|
|
/// Eth Pub-Sub (Safe)
|
|
|
|
EthPubSub,
|
2016-11-09 19:41:47 +01:00
|
|
|
/// Geth-compatible "personal" API (DEPRECATED; only used in `--geth` mode.)
|
2016-11-06 12:51:53 +01:00
|
|
|
Personal,
|
|
|
|
/// Signer - Confirm transactions in Signer (UNSAFE: Passwords, List of transactions)
|
2016-06-07 22:52:48 +02:00
|
|
|
Signer,
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Parity - Custom extensions (Safe)
|
|
|
|
Parity,
|
|
|
|
/// Traces (Safe)
|
2016-06-01 19:37:34 +02:00
|
|
|
Traces,
|
2016-11-06 12:51:53 +01:00
|
|
|
/// Rpc (Safe)
|
2016-06-01 19:37:34 +02:00
|
|
|
Rpc,
|
2018-04-09 16:14:33 +02:00
|
|
|
/// Private transaction manager (Safe)
|
|
|
|
Private,
|
2018-09-08 04:04:28 +02:00
|
|
|
/// Parity PubSub - Generic Publish-Subscriber (Safety depends on other APIs exposed).
|
|
|
|
ParityPubSub,
|
|
|
|
/// Parity Accounts extensions (UNSAFE: Passwords, Side Effects (new account))
|
|
|
|
ParityAccounts,
|
|
|
|
/// Parity - Set methods (UNSAFE: Side Effects affecting node operation)
|
|
|
|
ParitySet,
|
|
|
|
/// SecretStore (UNSAFE: arbitrary hash signing)
|
|
|
|
SecretStore,
|
|
|
|
/// Geth-compatible (best-effort) debug API (Potentially UNSAFE)
|
|
|
|
/// NOTE We don't aim to support all methods, only the ones that are useful.
|
|
|
|
Debug,
|
2019-04-12 13:36:49 +02:00
|
|
|
/// Parity Transactions pool PubSub
|
|
|
|
ParityTransactionsPool,
|
2019-07-12 14:15:30 +02:00
|
|
|
/// Deprecated api
|
|
|
|
Deprecated,
|
2016-06-01 19:37:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for Api {
|
2016-07-25 16:09:47 +02:00
|
|
|
type Err = String;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
use self::Api::*;
|
|
|
|
|
|
|
|
match s {
|
2018-09-08 04:04:28 +02:00
|
|
|
"debug" => Ok(Debug),
|
2016-06-01 19:37:34 +02:00
|
|
|
"eth" => Ok(Eth),
|
2018-09-08 04:04:28 +02:00
|
|
|
"net" => Ok(Net),
|
2016-11-06 12:51:53 +01:00
|
|
|
"parity" => Ok(Parity),
|
|
|
|
"parity_accounts" => Ok(ParityAccounts),
|
2018-09-08 04:04:28 +02:00
|
|
|
"parity_pubsub" => Ok(ParityPubSub),
|
2016-11-06 12:51:53 +01:00
|
|
|
"parity_set" => Ok(ParitySet),
|
2018-09-08 04:04:28 +02:00
|
|
|
"personal" => Ok(Personal),
|
|
|
|
"private" => Ok(Private),
|
|
|
|
"pubsub" => Ok(EthPubSub),
|
2016-06-01 19:37:34 +02:00
|
|
|
"rpc" => Ok(Rpc),
|
2017-05-05 15:57:29 +02:00
|
|
|
"secretstore" => Ok(SecretStore),
|
2018-09-08 04:04:28 +02:00
|
|
|
"signer" => Ok(Signer),
|
|
|
|
"traces" => Ok(Traces),
|
|
|
|
"web3" => Ok(Web3),
|
2019-04-12 13:36:49 +02:00
|
|
|
"parity_transactions_pool" => Ok(ParityTransactionsPool),
|
2019-07-12 14:15:30 +02:00
|
|
|
"shh" | "shh_pubsub" => Ok(Deprecated),
|
2018-11-26 19:58:27 +01:00
|
|
|
api => Err(format!("Unknown api: {}", api)),
|
2016-06-01 19:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2016-07-25 16:09:47 +02:00
|
|
|
pub enum ApiSet {
|
2017-04-06 19:38:33 +02:00
|
|
|
// Unsafe context (like jsonrpc over http)
|
2016-07-25 16:09:47 +02:00
|
|
|
UnsafeContext,
|
2019-02-08 14:11:55 +01:00
|
|
|
// All possible APIs (safe context like token-protected WS interface)
|
2017-04-06 19:38:33 +02:00
|
|
|
All,
|
|
|
|
// Local "unsafe" context and accounts access
|
2016-11-04 09:58:39 +01:00
|
|
|
IpcContext,
|
2017-07-10 17:42:29 +02:00
|
|
|
// APIs for Parity Generic Pub-Sub
|
|
|
|
PubSub,
|
2017-04-06 19:38:33 +02:00
|
|
|
// Fixed list of APis
|
2016-07-25 16:09:47 +02:00
|
|
|
List(HashSet<Api>),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ApiSet {
|
|
|
|
fn default() -> Self {
|
|
|
|
ApiSet::UnsafeContext
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for ApiSet {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.list_apis() == other.list_apis()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for ApiSet {
|
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2017-04-06 19:38:33 +02:00
|
|
|
let mut apis = HashSet::new();
|
|
|
|
|
|
|
|
for api in s.split(',') {
|
|
|
|
match api {
|
|
|
|
"all" => {
|
|
|
|
apis.extend(ApiSet::All.list_apis());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-04-06 19:38:33 +02:00
|
|
|
"safe" => {
|
|
|
|
// Safe APIs are those that are safe even in UnsafeContext.
|
|
|
|
apis.extend(ApiSet::UnsafeContext.list_apis());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-04-06 19:38:33 +02:00
|
|
|
// Remove the API
|
|
|
|
api if api.starts_with("-") => {
|
|
|
|
let api = api[1..].parse()?;
|
|
|
|
apis.remove(&api);
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-04-06 19:38:33 +02:00
|
|
|
api => {
|
|
|
|
let api = api.parse()?;
|
|
|
|
apis.insert(api);
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-04-06 19:38:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(ApiSet::List(apis))
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 17:42:29 +02:00
|
|
|
fn to_modules(apis: &HashSet<Api>) -> BTreeMap<String, String> {
|
2017-03-22 20:14:40 +01:00
|
|
|
let mut modules = BTreeMap::new();
|
|
|
|
for api in apis {
|
|
|
|
let (name, version) = match *api {
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Debug => ("debug", "1.0"),
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Eth => ("eth", "1.0"),
|
2017-05-23 12:26:39 +02:00
|
|
|
Api::EthPubSub => ("pubsub", "1.0"),
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Net => ("net", "1.0"),
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Parity => ("parity", "1.0"),
|
|
|
|
Api::ParityAccounts => ("parity_accounts", "1.0"),
|
2017-05-23 18:05:17 +02:00
|
|
|
Api::ParityPubSub => ("parity_pubsub", "1.0"),
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::ParitySet => ("parity_set", "1.0"),
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Personal => ("personal", "1.0"),
|
|
|
|
Api::Private => ("private", "1.0"),
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Rpc => ("rpc", "1.0"),
|
2017-05-05 15:57:29 +02:00
|
|
|
Api::SecretStore => ("secretstore", "1.0"),
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Signer => ("signer", "1.0"),
|
|
|
|
Api::Traces => ("traces", "1.0"),
|
|
|
|
Api::Web3 => ("web3", "1.0"),
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool => ("parity_transactions_pool", "1.0"),
|
2019-07-12 14:15:30 +02:00
|
|
|
Api::Deprecated => {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
};
|
|
|
|
modules.insert(name.into(), version.into());
|
|
|
|
}
|
|
|
|
modules
|
|
|
|
}
|
|
|
|
|
2019-02-07 14:34:24 +01:00
|
|
|
macro_rules! add_signing_methods {
|
|
|
|
($namespace:ident, $handler:expr, $deps:expr, $dispatch:expr) => {{
|
|
|
|
let deps = &$deps;
|
|
|
|
let (dispatcher, accounts) = $dispatch;
|
|
|
|
if deps.signer_service.is_enabled() {
|
|
|
|
$handler.extend_with($namespace::to_delegate(SigningQueueClient::new(
|
|
|
|
&deps.signer_service,
|
|
|
|
dispatcher.clone(),
|
|
|
|
deps.executor.clone(),
|
|
|
|
accounts,
|
|
|
|
)))
|
|
|
|
} else {
|
|
|
|
$handler.extend_with($namespace::to_delegate(SigningUnsafeClient::new(
|
|
|
|
accounts,
|
|
|
|
dispatcher.clone(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-03-22 20:14:40 +01:00
|
|
|
/// RPC dependencies can be used to initialize RPC endpoints from APIs.
|
|
|
|
pub trait Dependencies {
|
|
|
|
type Notifier: ActivityNotifier;
|
|
|
|
|
|
|
|
/// Create the activity notifier.
|
|
|
|
fn activity_notifier(&self) -> Self::Notifier;
|
|
|
|
|
|
|
|
/// Extend the given I/O handler with endpoints for each API.
|
2018-11-26 19:58:27 +01:00
|
|
|
fn extend_with_set<S>(&self, handler: &mut MetaIoHandler<Metadata, S>, apis: &HashSet<Api>)
|
|
|
|
where
|
|
|
|
S: core::Middleware<Metadata>;
|
2017-03-22 20:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// RPC dependencies for a full node.
|
|
|
|
pub struct FullDependencies {
|
2016-09-21 12:44:49 +02:00
|
|
|
pub signer_service: Arc<SignerService>,
|
2016-06-01 19:37:34 +02:00
|
|
|
pub client: Arc<Client>,
|
2016-10-31 17:32:53 +01:00
|
|
|
pub snapshot: Arc<SnapshotService>,
|
2016-07-16 15:51:06 +02:00
|
|
|
pub sync: Arc<SyncProvider>,
|
|
|
|
pub net: Arc<ManageNetwork>,
|
2019-02-07 14:34:24 +01:00
|
|
|
pub accounts: Arc<AccountProvider>,
|
2018-04-09 16:14:33 +02:00
|
|
|
pub private_tx_service: Option<Arc<PrivateTxService>>,
|
2016-06-01 19:37:34 +02:00
|
|
|
pub miner: Arc<Miner>,
|
|
|
|
pub external_miner: Arc<ExternalMiner>,
|
|
|
|
pub logger: Arc<RotatingLogger>,
|
|
|
|
pub settings: Arc<NetworkSettings>,
|
2016-07-11 17:02:42 +02:00
|
|
|
pub net_service: Arc<ManageNetwork>,
|
2016-12-11 19:14:42 +01:00
|
|
|
pub updater: Arc<Updater>,
|
2016-08-03 15:31:00 +02:00
|
|
|
pub geth_compatibility: bool,
|
2018-11-16 14:00:34 +01:00
|
|
|
pub experimental_rpcs: bool,
|
2017-09-21 14:52:44 +02:00
|
|
|
pub ws_address: Option<Host>,
|
2016-12-22 18:26:39 +01:00
|
|
|
pub fetch: FetchClient,
|
2018-10-22 09:40:50 +02:00
|
|
|
pub executor: Executor,
|
2018-01-09 12:43:36 +01:00
|
|
|
pub gas_price_percentile: usize,
|
2018-06-18 13:42:54 +02:00
|
|
|
pub poll_lifetime: u32,
|
2018-11-26 19:58:27 +01:00
|
|
|
pub allow_missing_blocks: bool,
|
2019-04-23 14:54:45 +02:00
|
|
|
pub no_ancient_blocks: bool,
|
2016-06-01 19:37:34 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 13:24:18 +02:00
|
|
|
impl FullDependencies {
|
2017-05-24 12:24:07 +02:00
|
|
|
fn extend_api<S>(
|
2017-05-06 13:24:18 +02:00
|
|
|
&self,
|
2017-05-24 12:24:07 +02:00
|
|
|
handler: &mut MetaIoHandler<Metadata, S>,
|
2017-07-10 17:42:29 +02:00
|
|
|
apis: &HashSet<Api>,
|
2017-05-06 13:24:18 +02:00
|
|
|
for_generic_pubsub: bool,
|
2018-11-26 19:58:27 +01:00
|
|
|
) where
|
|
|
|
S: core::Middleware<Metadata>,
|
|
|
|
{
|
2017-04-13 16:32:07 +02:00
|
|
|
use parity_rpc::v1::*;
|
2017-03-22 20:14:40 +01:00
|
|
|
|
2018-11-26 19:58:27 +01:00
|
|
|
let nonces = Arc::new(Mutex::new(dispatch::Reservations::new(
|
|
|
|
self.executor.clone(),
|
|
|
|
)));
|
2017-11-01 11:23:18 +01:00
|
|
|
let dispatcher = FullDispatcher::new(
|
|
|
|
self.client.clone(),
|
|
|
|
self.miner.clone(),
|
2017-11-10 17:11:04 +01:00
|
|
|
nonces.clone(),
|
2018-01-09 12:43:36 +01:00
|
|
|
self.gas_price_percentile,
|
2017-11-01 11:23:18 +01:00
|
|
|
);
|
2019-02-07 14:34:24 +01:00
|
|
|
let account_signer = Arc::new(dispatch::Signer::new(self.accounts.clone())) as _;
|
|
|
|
let accounts = account_utils::accounts_list(self.accounts.clone());
|
|
|
|
|
2017-03-22 20:14:40 +01:00
|
|
|
for api in apis {
|
|
|
|
match *api {
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Debug => {
|
|
|
|
handler.extend_with(DebugClient::new(self.client.clone()).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Web3 => {
|
2019-03-22 12:01:11 +01:00
|
|
|
handler.extend_with(Web3Client::default().to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Net => {
|
|
|
|
handler.extend_with(NetClient::new(&self.sync).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Eth => {
|
|
|
|
let client = EthClient::new(
|
|
|
|
&self.client,
|
|
|
|
&self.snapshot,
|
|
|
|
&self.sync,
|
2019-02-07 14:34:24 +01:00
|
|
|
&accounts,
|
2017-03-22 20:14:40 +01:00
|
|
|
&self.miner,
|
|
|
|
&self.external_miner,
|
|
|
|
EthClientOptions {
|
|
|
|
pending_nonce_from_queue: self.geth_compatibility,
|
|
|
|
allow_pending_receipt_query: !self.geth_compatibility,
|
|
|
|
send_block_number_in_get_work: !self.geth_compatibility,
|
2018-01-09 12:43:36 +01:00
|
|
|
gas_price_percentile: self.gas_price_percentile,
|
2018-11-26 19:58:27 +01:00
|
|
|
allow_missing_blocks: self.allow_missing_blocks,
|
2018-11-21 20:09:33 +01:00
|
|
|
allow_experimental_rpcs: self.experimental_rpcs,
|
2019-04-23 14:54:45 +02:00
|
|
|
no_ancient_blocks: self.no_ancient_blocks
|
2017-03-22 20:14:40 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
handler.extend_with(client.to_delegate());
|
|
|
|
|
2017-05-06 13:24:18 +02:00
|
|
|
if !for_generic_pubsub {
|
2018-11-26 19:58:27 +01:00
|
|
|
let filter_client = EthFilterClient::new(
|
|
|
|
self.client.clone(),
|
|
|
|
self.miner.clone(),
|
|
|
|
self.poll_lifetime,
|
|
|
|
);
|
2017-05-06 13:24:18 +02:00
|
|
|
handler.extend_with(filter_client.to_delegate());
|
2017-03-22 20:14:40 +01:00
|
|
|
|
2019-02-07 14:34:24 +01:00
|
|
|
add_signing_methods!(EthSigning, handler, self, (&dispatcher, &account_signer));
|
2017-05-06 13:24:18 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-23 12:26:39 +02:00
|
|
|
Api::EthPubSub => {
|
2017-07-27 12:52:36 +02:00
|
|
|
if !for_generic_pubsub {
|
2019-06-04 13:35:33 +02:00
|
|
|
let pool_receiver = self.miner.pending_transactions_receiver();
|
2019-04-02 17:13:55 +02:00
|
|
|
let mut client =
|
2019-06-04 13:35:33 +02:00
|
|
|
EthPubSubClient::new(self.client.clone(), self.executor.clone(), pool_receiver);
|
2019-04-02 17:13:55 +02:00
|
|
|
let weak_client = Arc::downgrade(&self.client);
|
|
|
|
|
|
|
|
client.add_sync_notifier(self.sync.sync_notification(), move |state| {
|
|
|
|
let client = weak_client.upgrade()?;
|
|
|
|
let queue_info = client.queue_info();
|
|
|
|
|
|
|
|
let is_syncing_state = match state { SyncState::Idle | SyncState::NewBlocks => false, _ => true };
|
|
|
|
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
|
|
|
|
|
|
|
Some(PubSubSyncStatus {
|
|
|
|
syncing: is_verifying || is_syncing_state,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-02-16 16:51:34 +01:00
|
|
|
if let Some(h) = client.handler().upgrade() {
|
|
|
|
self.client.add_notify(h);
|
|
|
|
}
|
2017-07-27 12:52:36 +02:00
|
|
|
handler.extend_with(client.to_delegate());
|
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool => {
|
|
|
|
if !for_generic_pubsub {
|
2019-06-04 13:35:33 +02:00
|
|
|
let receiver = self.miner.full_transactions_receiver();
|
2019-04-12 13:36:49 +02:00
|
|
|
let client = TransactionsPoolClient::new(self.executor.clone(), receiver);
|
|
|
|
handler.extend_with(TransactionsPoolClient::to_delegate(client));
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Personal => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
PersonalClient::new(
|
2019-02-07 14:34:24 +01:00
|
|
|
&self.accounts,
|
2018-11-26 19:58:27 +01:00
|
|
|
dispatcher.clone(),
|
|
|
|
self.geth_compatibility,
|
|
|
|
self.experimental_rpcs,
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Signer => {
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
SignerClient::new(
|
2019-02-07 14:34:24 +01:00
|
|
|
account_signer.clone(),
|
2018-11-26 19:58:27 +01:00
|
|
|
dispatcher.clone(),
|
|
|
|
&self.signer_service,
|
|
|
|
self.executor.clone(),
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Parity => {
|
|
|
|
let signer = match self.signer_service.is_enabled() {
|
|
|
|
true => Some(self.signer_service.clone()),
|
|
|
|
false => None,
|
|
|
|
};
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
ParityClient::new(
|
|
|
|
self.client.clone(),
|
|
|
|
self.miner.clone(),
|
|
|
|
self.sync.clone(),
|
|
|
|
self.updater.clone(),
|
|
|
|
self.net_service.clone(),
|
|
|
|
self.logger.clone(),
|
|
|
|
self.settings.clone(),
|
|
|
|
signer,
|
|
|
|
self.ws_address.clone(),
|
|
|
|
self.snapshot.clone().into(),
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(ParityAccountsInfo::to_delegate(ParityAccountsClient::new(&self.accounts)));
|
2017-03-22 20:14:40 +01:00
|
|
|
|
2017-05-23 18:05:17 +02:00
|
|
|
if !for_generic_pubsub {
|
2019-02-07 14:34:24 +01:00
|
|
|
add_signing_methods!(ParitySigning, handler, self, (&dispatcher, &account_signer));
|
2017-05-23 18:05:17 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-23 18:05:17 +02:00
|
|
|
Api::ParityPubSub => {
|
2017-05-06 13:24:18 +02:00
|
|
|
if !for_generic_pubsub {
|
|
|
|
let mut rpc = MetaIoHandler::default();
|
2018-11-26 19:58:27 +01:00
|
|
|
let apis = ApiSet::List(apis.clone())
|
|
|
|
.retain(ApiSet::PubSub)
|
|
|
|
.list_apis();
|
2017-07-10 17:42:29 +02:00
|
|
|
self.extend_api(&mut rpc, &apis, true);
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
PubSubClient::new(rpc, self.executor.clone()).to_delegate(),
|
|
|
|
);
|
2017-05-06 13:24:18 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::ParityAccounts => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(ParityAccounts::to_delegate(ParityAccountsClient::new(&self.accounts)));
|
|
|
|
}
|
|
|
|
Api::ParitySet => {
|
|
|
|
handler.extend_with(
|
|
|
|
ParitySetClient::new(
|
|
|
|
&self.client,
|
|
|
|
&self.miner,
|
|
|
|
&self.updater,
|
|
|
|
&self.net_service,
|
|
|
|
self.fetch.clone(),
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(
|
|
|
|
ParitySetAccountsClient::new(
|
|
|
|
&self.accounts,
|
|
|
|
&self.miner,
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
|
|
|
Api::Traces => handler.extend_with(TracesClient::new(&self.client).to_delegate()),
|
2017-03-22 20:14:40 +01:00
|
|
|
Api::Rpc => {
|
|
|
|
let modules = to_modules(&apis);
|
|
|
|
handler.extend_with(RpcClient::new(modules).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-05 15:57:29 +02:00
|
|
|
Api::SecretStore => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(SecretStoreClient::new(&self.accounts).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2018-04-09 16:14:33 +02:00
|
|
|
Api::Private => {
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
PrivateClient::new(self.private_tx_service.as_ref().map(|p| p.provider()))
|
|
|
|
.to_delegate(),
|
|
|
|
);
|
|
|
|
}
|
2019-07-12 14:15:30 +02:00
|
|
|
Api::Deprecated => {},
|
2017-03-22 20:14:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-01 19:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 13:24:18 +02:00
|
|
|
impl Dependencies for FullDependencies {
|
|
|
|
type Notifier = ClientNotifier;
|
|
|
|
|
|
|
|
fn activity_notifier(&self) -> ClientNotifier {
|
|
|
|
ClientNotifier {
|
|
|
|
client: self.client.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-26 19:58:27 +01:00
|
|
|
fn extend_with_set<S>(&self, handler: &mut MetaIoHandler<Metadata, S>, apis: &HashSet<Api>)
|
|
|
|
where
|
|
|
|
S: core::Middleware<Metadata>,
|
|
|
|
{
|
2017-05-06 13:24:18 +02:00
|
|
|
self.extend_api(handler, apis, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 21:09:43 +01:00
|
|
|
/// Light client notifier. Doesn't do anything yet, but might in the future.
|
|
|
|
pub struct LightClientNotifier;
|
|
|
|
|
|
|
|
impl ActivityNotifier for LightClientNotifier {
|
|
|
|
fn active(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RPC dependencies for a light client.
|
2017-09-05 17:54:05 +02:00
|
|
|
pub struct LightDependencies<T> {
|
2017-03-22 21:09:43 +01:00
|
|
|
pub signer_service: Arc<SignerService>,
|
2017-09-05 17:54:05 +02:00
|
|
|
pub client: Arc<T>,
|
2017-03-22 21:09:43 +01:00
|
|
|
pub sync: Arc<LightSync>,
|
|
|
|
pub net: Arc<ManageNetwork>,
|
2019-02-07 14:34:24 +01:00
|
|
|
pub accounts: Arc<AccountProvider>,
|
2017-03-22 21:09:43 +01:00
|
|
|
pub logger: Arc<RotatingLogger>,
|
|
|
|
pub settings: Arc<NetworkSettings>,
|
|
|
|
pub on_demand: Arc<::light::on_demand::OnDemand>,
|
|
|
|
pub cache: Arc<Mutex<LightDataCache>>,
|
|
|
|
pub transaction_queue: Arc<RwLock<LightTransactionQueue>>,
|
2017-09-21 14:52:44 +02:00
|
|
|
pub ws_address: Option<Host>,
|
2017-03-22 21:09:43 +01:00
|
|
|
pub fetch: FetchClient,
|
|
|
|
pub geth_compatibility: bool,
|
2018-11-16 14:00:34 +01:00
|
|
|
pub experimental_rpcs: bool,
|
2018-10-22 09:40:50 +02:00
|
|
|
pub executor: Executor,
|
2018-04-09 16:14:33 +02:00
|
|
|
pub private_tx_service: Option<Arc<PrivateTransactionManager>>,
|
2018-01-09 12:43:36 +01:00
|
|
|
pub gas_price_percentile: usize,
|
2018-06-18 13:42:54 +02:00
|
|
|
pub poll_lifetime: u32,
|
2017-03-22 21:09:43 +01:00
|
|
|
}
|
|
|
|
|
2017-09-05 17:54:05 +02:00
|
|
|
impl<C: LightChainClient + 'static> LightDependencies<C> {
|
2017-05-23 18:05:17 +02:00
|
|
|
fn extend_api<T: core::Middleware<Metadata>>(
|
|
|
|
&self,
|
|
|
|
handler: &mut MetaIoHandler<Metadata, T>,
|
2017-07-10 17:42:29 +02:00
|
|
|
apis: &HashSet<Api>,
|
2017-05-23 18:05:17 +02:00
|
|
|
for_generic_pubsub: bool,
|
|
|
|
) {
|
2017-04-13 16:32:07 +02:00
|
|
|
use parity_rpc::v1::*;
|
2017-03-22 21:09:43 +01:00
|
|
|
|
|
|
|
let dispatcher = LightDispatcher::new(
|
|
|
|
self.sync.clone(),
|
|
|
|
self.client.clone(),
|
|
|
|
self.on_demand.clone(),
|
|
|
|
self.cache.clone(),
|
|
|
|
self.transaction_queue.clone(),
|
2018-11-26 19:58:27 +01:00
|
|
|
Arc::new(Mutex::new(dispatch::Reservations::new(
|
|
|
|
self.executor.clone(),
|
|
|
|
))),
|
2018-01-09 12:43:36 +01:00
|
|
|
self.gas_price_percentile,
|
2017-03-22 21:09:43 +01:00
|
|
|
);
|
2019-02-07 14:34:24 +01:00
|
|
|
let account_signer = Arc::new(dispatch::Signer::new(self.accounts.clone())) as _;
|
|
|
|
let accounts = account_utils::accounts_list(self.accounts.clone());
|
2017-03-23 19:42:11 +01:00
|
|
|
|
2017-03-22 21:09:43 +01:00
|
|
|
for api in apis {
|
|
|
|
match *api {
|
2018-09-08 04:04:28 +02:00
|
|
|
Api::Debug => {
|
|
|
|
warn!(target: "rpc", "Debug API is not available in light client mode.")
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Web3 => {
|
2019-03-22 12:01:11 +01:00
|
|
|
handler.extend_with(Web3Client::default().to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Net => {
|
|
|
|
handler.extend_with(light::NetClient::new(self.sync.clone()).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Eth => {
|
|
|
|
let client = light::EthClient::new(
|
|
|
|
self.sync.clone(),
|
|
|
|
self.client.clone(),
|
|
|
|
self.on_demand.clone(),
|
|
|
|
self.transaction_queue.clone(),
|
2019-02-07 14:34:24 +01:00
|
|
|
accounts.clone(),
|
2017-03-22 21:09:43 +01:00
|
|
|
self.cache.clone(),
|
2018-01-09 12:43:36 +01:00
|
|
|
self.gas_price_percentile,
|
2018-06-18 13:42:54 +02:00
|
|
|
self.poll_lifetime,
|
2017-03-22 21:09:43 +01:00
|
|
|
);
|
2017-04-12 12:07:54 +02:00
|
|
|
handler.extend_with(Eth::to_delegate(client.clone()));
|
2017-05-23 18:05:17 +02:00
|
|
|
|
|
|
|
if !for_generic_pubsub {
|
|
|
|
handler.extend_with(EthFilter::to_delegate(client));
|
2019-02-07 14:34:24 +01:00
|
|
|
add_signing_methods!(EthSigning, handler, self, (&dispatcher, &account_signer));
|
2017-05-23 18:05:17 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-23 12:26:39 +02:00
|
|
|
Api::EthPubSub => {
|
2019-06-04 13:35:33 +02:00
|
|
|
let receiver = self.transaction_queue.write().pending_transactions_receiver();
|
|
|
|
|
2019-04-02 17:13:55 +02:00
|
|
|
let mut client = EthPubSubClient::light(
|
2017-06-28 12:21:13 +02:00
|
|
|
self.client.clone(),
|
|
|
|
self.on_demand.clone(),
|
|
|
|
self.sync.clone(),
|
|
|
|
self.cache.clone(),
|
2018-10-22 09:40:50 +02:00
|
|
|
self.executor.clone(),
|
2018-01-09 12:43:36 +01:00
|
|
|
self.gas_price_percentile,
|
2019-06-04 13:35:33 +02:00
|
|
|
receiver
|
2017-06-28 12:21:13 +02:00
|
|
|
);
|
2019-04-02 17:13:55 +02:00
|
|
|
|
|
|
|
let weak_client = Arc::downgrade(&self.client);
|
|
|
|
|
|
|
|
client.add_sync_notifier(self.sync.sync_notification(), move |state| {
|
|
|
|
let client = weak_client.upgrade()?;
|
|
|
|
let queue_info = client.queue_info();
|
|
|
|
|
|
|
|
let is_syncing_state = match state { SyncState::Idle | SyncState::NewBlocks => false, _ => true };
|
|
|
|
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
|
|
|
|
|
|
|
Some(PubSubSyncStatus {
|
|
|
|
syncing: is_verifying || is_syncing_state,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-02-16 16:51:34 +01:00
|
|
|
self.client.add_listener(client.handler() as Weak<_>);
|
2017-05-23 12:26:39 +02:00
|
|
|
handler.extend_with(EthPubSub::to_delegate(client));
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool => {
|
|
|
|
if !for_generic_pubsub {
|
2019-06-04 13:35:33 +02:00
|
|
|
let receiver = self.transaction_queue.write().full_transactions_receiver();
|
2019-04-12 13:36:49 +02:00
|
|
|
let client = TransactionsPoolClient::new(self.executor.clone(), receiver);
|
|
|
|
handler.extend_with(TransactionsPoolClient::to_delegate(client));
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Personal => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
PersonalClient::new(
|
2019-02-07 14:34:24 +01:00
|
|
|
&self.accounts,
|
2018-11-26 19:58:27 +01:00
|
|
|
dispatcher.clone(),
|
|
|
|
self.geth_compatibility,
|
|
|
|
self.experimental_rpcs,
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Signer => {
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
SignerClient::new(
|
2019-02-07 14:34:24 +01:00
|
|
|
account_signer.clone(),
|
2018-11-26 19:58:27 +01:00
|
|
|
dispatcher.clone(),
|
|
|
|
&self.signer_service,
|
|
|
|
self.executor.clone(),
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Parity => {
|
|
|
|
let signer = match self.signer_service.is_enabled() {
|
|
|
|
true => Some(self.signer_service.clone()),
|
|
|
|
false => None,
|
|
|
|
};
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
light::ParityClient::new(
|
|
|
|
Arc::new(dispatcher.clone()),
|
|
|
|
self.logger.clone(),
|
|
|
|
self.settings.clone(),
|
|
|
|
signer,
|
|
|
|
self.ws_address.clone(),
|
|
|
|
self.gas_price_percentile,
|
|
|
|
).to_delegate(),
|
|
|
|
);
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(
|
|
|
|
ParityAccountsInfo::to_delegate(ParityAccountsClient::new(&self.accounts))
|
|
|
|
);
|
2017-03-22 21:09:43 +01:00
|
|
|
|
2017-05-23 18:05:17 +02:00
|
|
|
if !for_generic_pubsub {
|
2019-02-07 14:34:24 +01:00
|
|
|
add_signing_methods!(ParitySigning, handler, self, (&dispatcher, &account_signer));
|
2017-05-23 18:05:17 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-23 18:05:17 +02:00
|
|
|
Api::ParityPubSub => {
|
|
|
|
if !for_generic_pubsub {
|
|
|
|
let mut rpc = MetaIoHandler::default();
|
2018-11-26 19:58:27 +01:00
|
|
|
let apis = ApiSet::List(apis.clone())
|
|
|
|
.retain(ApiSet::PubSub)
|
|
|
|
.list_apis();
|
2017-07-10 17:42:29 +02:00
|
|
|
self.extend_api(&mut rpc, &apis, true);
|
2018-11-26 19:58:27 +01:00
|
|
|
handler.extend_with(
|
|
|
|
PubSubClient::new(rpc, self.executor.clone()).to_delegate(),
|
|
|
|
);
|
2017-05-23 18:05:17 +02:00
|
|
|
}
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::ParityAccounts => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(ParityAccounts::to_delegate(ParityAccountsClient::new(&self.accounts)));
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
|
|
|
Api::ParitySet => handler.extend_with(
|
2019-03-04 20:24:53 +01:00
|
|
|
light::ParitySetClient::new(self.client.clone(), self.sync.clone(), self.fetch.clone())
|
2018-11-26 19:58:27 +01:00
|
|
|
.to_delegate(),
|
|
|
|
),
|
|
|
|
Api::Traces => handler.extend_with(light::TracesClient.to_delegate()),
|
2017-03-22 21:09:43 +01:00
|
|
|
Api::Rpc => {
|
|
|
|
let modules = to_modules(&apis);
|
|
|
|
handler.extend_with(RpcClient::new(modules).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-05-05 15:57:29 +02:00
|
|
|
Api::SecretStore => {
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
handler.extend_with(SecretStoreClient::new(&self.accounts).to_delegate());
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2018-04-09 16:14:33 +02:00
|
|
|
Api::Private => {
|
|
|
|
if let Some(ref tx_manager) = self.private_tx_service {
|
|
|
|
let private_tx_service = Some(tx_manager.clone());
|
|
|
|
handler.extend_with(PrivateClient::new(private_tx_service).to_delegate());
|
|
|
|
}
|
2017-07-14 20:40:28 +02:00
|
|
|
}
|
2019-07-12 14:15:30 +02:00
|
|
|
Api::Deprecated => {},
|
2017-03-22 21:09:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 17:54:05 +02:00
|
|
|
impl<T: LightChainClient + 'static> Dependencies for LightDependencies<T> {
|
2017-05-23 18:05:17 +02:00
|
|
|
type Notifier = LightClientNotifier;
|
|
|
|
|
2018-11-26 19:58:27 +01:00
|
|
|
fn activity_notifier(&self) -> Self::Notifier {
|
|
|
|
LightClientNotifier
|
|
|
|
}
|
2017-05-24 12:24:07 +02:00
|
|
|
|
2018-11-26 19:58:27 +01:00
|
|
|
fn extend_with_set<S>(&self, handler: &mut MetaIoHandler<Metadata, S>, apis: &HashSet<Api>)
|
|
|
|
where
|
|
|
|
S: core::Middleware<Metadata>,
|
|
|
|
{
|
2017-05-23 18:05:17 +02:00
|
|
|
self.extend_api(handler, apis, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
impl ApiSet {
|
2017-04-06 19:38:33 +02:00
|
|
|
/// Retains only APIs in given set.
|
|
|
|
pub fn retain(self, set: Self) -> Self {
|
|
|
|
ApiSet::List(&self.list_apis() & &set.list_apis())
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
pub fn list_apis(&self) -> HashSet<Api> {
|
2018-06-01 16:49:55 +02:00
|
|
|
let mut public_list: HashSet<Api> = [
|
2017-07-14 20:40:28 +02:00
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::Rpc,
|
2018-04-09 16:14:33 +02:00
|
|
|
Api::Private,
|
2018-11-26 19:58:27 +01:00
|
|
|
]
|
|
|
|
.into_iter()
|
|
|
|
.cloned()
|
|
|
|
.collect();
|
2017-07-14 20:40:28 +02:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
match *self {
|
2019-07-12 14:15:30 +02:00
|
|
|
ApiSet::List(ref apis) => apis.into_iter()
|
|
|
|
.filter(|api| *api != &Api::Deprecated)
|
|
|
|
.cloned()
|
|
|
|
.collect(),
|
2017-04-06 19:38:33 +02:00
|
|
|
ApiSet::UnsafeContext => {
|
|
|
|
public_list.insert(Api::Traces);
|
2017-05-23 18:05:17 +02:00
|
|
|
public_list.insert(Api::ParityPubSub);
|
2019-04-12 13:36:49 +02:00
|
|
|
public_list.insert(Api::ParityTransactionsPool);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2016-11-04 09:58:39 +01:00
|
|
|
ApiSet::IpcContext => {
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list.insert(Api::Traces);
|
2017-05-23 18:05:17 +02:00
|
|
|
public_list.insert(Api::ParityPubSub);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list.insert(Api::ParityAccounts);
|
2019-04-12 13:36:49 +02:00
|
|
|
public_list.insert(Api::ParityTransactionsPool);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-04-06 19:38:33 +02:00
|
|
|
ApiSet::All => {
|
2018-09-08 04:04:28 +02:00
|
|
|
public_list.insert(Api::Debug);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list.insert(Api::Traces);
|
2017-05-23 18:05:17 +02:00
|
|
|
public_list.insert(Api::ParityPubSub);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list.insert(Api::ParityAccounts);
|
|
|
|
public_list.insert(Api::ParitySet);
|
|
|
|
public_list.insert(Api::Signer);
|
|
|
|
public_list.insert(Api::Personal);
|
2017-12-19 14:59:37 +01:00
|
|
|
public_list.insert(Api::SecretStore);
|
2019-04-12 13:36:49 +02:00
|
|
|
public_list.insert(Api::ParityTransactionsPool);
|
2017-04-06 19:38:33 +02:00
|
|
|
public_list
|
2018-11-26 19:58:27 +01:00
|
|
|
}
|
2017-07-10 17:42:29 +02:00
|
|
|
ApiSet::PubSub => [
|
|
|
|
Api::Eth,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityAccounts,
|
|
|
|
Api::ParitySet,
|
|
|
|
Api::Traces,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2018-11-26 19:58:27 +01:00
|
|
|
]
|
|
|
|
.into_iter()
|
|
|
|
.cloned()
|
|
|
|
.collect(),
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
2016-06-01 19:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::{Api, ApiSet};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_api_parsing() {
|
2018-09-08 04:04:28 +02:00
|
|
|
assert_eq!(Api::Debug, "debug".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
assert_eq!(Api::Web3, "web3".parse().unwrap());
|
|
|
|
assert_eq!(Api::Net, "net".parse().unwrap());
|
|
|
|
assert_eq!(Api::Eth, "eth".parse().unwrap());
|
2017-05-23 12:26:39 +02:00
|
|
|
assert_eq!(Api::EthPubSub, "pubsub".parse().unwrap());
|
2016-11-06 12:51:53 +01:00
|
|
|
assert_eq!(Api::Personal, "personal".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
assert_eq!(Api::Signer, "signer".parse().unwrap());
|
2016-11-06 12:51:53 +01:00
|
|
|
assert_eq!(Api::Parity, "parity".parse().unwrap());
|
|
|
|
assert_eq!(Api::ParityAccounts, "parity_accounts".parse().unwrap());
|
|
|
|
assert_eq!(Api::ParitySet, "parity_set".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
assert_eq!(Api::Traces, "traces".parse().unwrap());
|
|
|
|
assert_eq!(Api::Rpc, "rpc".parse().unwrap());
|
2017-05-05 15:57:29 +02:00
|
|
|
assert_eq!(Api::SecretStore, "secretstore".parse().unwrap());
|
2018-04-09 16:14:33 +02:00
|
|
|
assert_eq!(Api::Private, "private".parse().unwrap());
|
2019-04-12 13:36:49 +02:00
|
|
|
assert_eq!(Api::ParityTransactionsPool, "parity_transactions_pool".parse().unwrap());
|
2016-07-25 16:09:47 +02:00
|
|
|
assert!("rp".parse::<Api>().is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_api_set_default() {
|
|
|
|
assert_eq!(ApiSet::UnsafeContext, ApiSet::default());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_api_set_parsing() {
|
2018-11-26 19:58:27 +01:00
|
|
|
assert_eq!(
|
|
|
|
ApiSet::List(vec![Api::Web3, Api::Eth].into_iter().collect()),
|
|
|
|
"web3,eth".parse().unwrap()
|
|
|
|
);
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_api_set_unsafe_context() {
|
2016-11-06 12:51:53 +01:00
|
|
|
let expected = vec![
|
|
|
|
// make sure this list contains only SAFE methods
|
2018-11-26 19:58:27 +01:00
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityPubSub,
|
|
|
|
Api::Traces,
|
|
|
|
Api::Rpc,
|
|
|
|
Api::Private,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2018-11-26 19:58:27 +01:00
|
|
|
].into_iter()
|
|
|
|
.collect();
|
2016-07-25 16:09:47 +02:00
|
|
|
assert_eq!(ApiSet::UnsafeContext.list_apis(), expected);
|
|
|
|
}
|
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
#[test]
|
|
|
|
fn test_api_set_ipc_context() {
|
|
|
|
let expected = vec![
|
|
|
|
// safe
|
2018-11-26 19:58:27 +01:00
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityPubSub,
|
|
|
|
Api::Traces,
|
|
|
|
Api::Rpc,
|
|
|
|
Api::Private,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2016-11-06 12:51:53 +01:00
|
|
|
// semi-safe
|
2018-11-26 19:58:27 +01:00
|
|
|
Api::ParityAccounts,
|
|
|
|
].into_iter()
|
|
|
|
.collect();
|
2016-11-06 12:51:53 +01:00
|
|
|
assert_eq!(ApiSet::IpcContext.list_apis(), expected);
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:38:33 +02:00
|
|
|
#[test]
|
|
|
|
fn test_all_apis() {
|
2018-11-26 19:58:27 +01:00
|
|
|
assert_eq!(
|
|
|
|
"all".parse::<ApiSet>().unwrap(),
|
|
|
|
ApiSet::List(
|
|
|
|
vec![
|
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityPubSub,
|
|
|
|
Api::Traces,
|
|
|
|
Api::Rpc,
|
|
|
|
Api::SecretStore,
|
|
|
|
Api::ParityAccounts,
|
|
|
|
Api::ParitySet,
|
|
|
|
Api::Signer,
|
|
|
|
Api::Personal,
|
|
|
|
Api::Private,
|
|
|
|
Api::Debug,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2018-11-26 19:58:27 +01:00
|
|
|
].into_iter()
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
);
|
2017-04-06 19:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_all_without_personal_apis() {
|
2018-11-26 19:58:27 +01:00
|
|
|
assert_eq!(
|
|
|
|
"personal,all,-personal".parse::<ApiSet>().unwrap(),
|
|
|
|
ApiSet::List(
|
|
|
|
vec![
|
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityPubSub,
|
|
|
|
Api::Traces,
|
|
|
|
Api::Rpc,
|
|
|
|
Api::SecretStore,
|
|
|
|
Api::ParityAccounts,
|
|
|
|
Api::ParitySet,
|
|
|
|
Api::Signer,
|
|
|
|
Api::Private,
|
|
|
|
Api::Debug,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2018-11-26 19:58:27 +01:00
|
|
|
].into_iter()
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
);
|
2017-04-06 19:38:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_safe_parsing() {
|
2018-11-26 19:58:27 +01:00
|
|
|
assert_eq!(
|
|
|
|
"safe".parse::<ApiSet>().unwrap(),
|
|
|
|
ApiSet::List(
|
|
|
|
vec![
|
|
|
|
Api::Web3,
|
|
|
|
Api::Net,
|
|
|
|
Api::Eth,
|
|
|
|
Api::EthPubSub,
|
|
|
|
Api::Parity,
|
|
|
|
Api::ParityPubSub,
|
|
|
|
Api::Traces,
|
|
|
|
Api::Rpc,
|
|
|
|
Api::Private,
|
2019-04-12 13:36:49 +02:00
|
|
|
Api::ParityTransactionsPool,
|
2018-11-26 19:58:27 +01:00
|
|
|
].into_iter()
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
);
|
2017-04-06 19:38:33 +02:00
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|