2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-02-05 13:40:41 +01: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-02-05 13:40:41 +01: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-02-05 13:40:41 +01:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
//! Parity RPC.
|
|
|
|
|
2016-01-27 17:08:59 +01:00
|
|
|
#![warn(missing_docs)]
|
2016-01-26 13:14:22 +01:00
|
|
|
|
2017-10-17 14:50:53 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate futures;
|
|
|
|
|
2017-09-01 16:57:57 +02:00
|
|
|
extern crate ansi_term;
|
2017-05-24 12:24:07 +02:00
|
|
|
extern crate cid;
|
2017-08-17 16:05:26 +02:00
|
|
|
extern crate itertools;
|
2017-05-24 12:24:07 +02:00
|
|
|
extern crate multihash;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate order_stat;
|
2017-09-02 20:09:13 +02:00
|
|
|
extern crate parking_lot;
|
2017-05-24 12:24:07 +02:00
|
|
|
extern crate rand;
|
2017-07-06 11:26:14 +02:00
|
|
|
extern crate rustc_hex;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate semver;
|
2016-01-26 13:14:22 +01:00
|
|
|
extern crate serde;
|
2016-01-26 19:24:33 +01:00
|
|
|
extern crate serde_json;
|
2017-11-16 17:34:23 +01:00
|
|
|
extern crate tiny_keccak;
|
2017-05-06 13:24:18 +02:00
|
|
|
extern crate tokio_timer;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate transient_hashmap;
|
|
|
|
|
2016-01-21 01:19:29 +01:00
|
|
|
extern crate jsonrpc_core;
|
2017-04-03 10:27:37 +02:00
|
|
|
extern crate jsonrpc_http_server as http;
|
|
|
|
extern crate jsonrpc_ipc_server as ipc;
|
2017-05-06 13:24:18 +02:00
|
|
|
extern crate jsonrpc_pubsub;
|
2016-09-01 14:49:12 +02:00
|
|
|
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate common_types as types;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate ethash;
|
2016-01-26 13:14:22 +01:00
|
|
|
extern crate ethcore;
|
2018-08-25 23:06:01 +02:00
|
|
|
extern crate fastmap;
|
Delete crates from parity-ethereum and fetch them from parity-common instead (#9083)
Use crates from parity-common: hashdb, keccak-hash, kvdb, kvdb-memorydb, kvdb-rocksdb, memorydb, parity-bytes, parity-crypto, path, patricia_trie, plain_hasher, rlp, target, test-support, trie-standardmap, triehash
2018-07-10 14:59:19 +02:00
|
|
|
extern crate parity_bytes as bytes;
|
|
|
|
extern crate parity_crypto as crypto;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate ethcore_io as io;
|
|
|
|
extern crate ethcore_light as light;
|
2018-04-10 12:13:49 +02:00
|
|
|
extern crate ethcore_logger;
|
2018-01-11 17:49:10 +01:00
|
|
|
extern crate ethcore_miner as miner;
|
2018-04-10 12:13:49 +02:00
|
|
|
extern crate ethcore_private_tx;
|
|
|
|
extern crate ethcore_sync as sync;
|
2018-01-10 13:35:18 +01:00
|
|
|
extern crate ethereum_types;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate ethkey;
|
2016-08-10 17:57:40 +02:00
|
|
|
extern crate ethstore;
|
2016-09-27 16:27:06 +02:00
|
|
|
extern crate fetch;
|
2018-06-26 09:03:38 +02:00
|
|
|
extern crate keccak_hash as hash;
|
2018-10-22 09:40:50 +02:00
|
|
|
extern crate parity_runtime;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate parity_updater as updater;
|
2017-12-22 14:37:39 +01:00
|
|
|
extern crate parity_version as version;
|
2018-06-26 09:03:38 +02:00
|
|
|
extern crate patricia_trie as trie;
|
2018-12-28 10:36:55 +01:00
|
|
|
extern crate eip_712;
|
2017-03-22 07:02:14 +01:00
|
|
|
extern crate rlp;
|
2017-02-17 16:18:31 +01:00
|
|
|
extern crate stats;
|
2018-06-26 09:03:38 +02:00
|
|
|
extern crate vm;
|
|
|
|
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
|
2017-09-14 19:28:43 +02:00
|
|
|
extern crate hardware_wallet;
|
2018-06-26 09:03:38 +02:00
|
|
|
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
|
|
|
|
extern crate fake_hardware_wallet as hardware_wallet;
|
2016-09-01 14:49:12 +02:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2016-12-13 14:59:19 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate jsonrpc_macros;
|
2017-02-13 16:38:47 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
2016-05-24 16:56:09 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate ethjson;
|
2018-04-13 17:34:27 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate transaction_pool as txpool;
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2017-04-27 18:23:22 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate pretty_assertions;
|
|
|
|
|
2017-10-10 20:01:27 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate macros;
|
|
|
|
|
2017-10-12 15:36:27 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate kvdb_memorydb;
|
|
|
|
|
2018-04-11 11:59:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate fake_fetch;
|
|
|
|
|
2018-01-19 17:32:53 +01:00
|
|
|
extern crate tempdir;
|
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
pub extern crate jsonrpc_ws_server as ws;
|
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
mod authcodes;
|
|
|
|
mod http_common;
|
2016-03-02 12:42:08 +01:00
|
|
|
pub mod v1;
|
2017-03-22 07:02:14 +01:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
pub mod tests;
|
|
|
|
|
2019-01-02 16:49:01 +01:00
|
|
|
pub use jsonrpc_core::{FutureOutput, FutureResult, FutureResponse, FutureRpcResult};
|
2017-05-06 13:24:18 +02:00
|
|
|
pub use jsonrpc_pubsub::Session as PubSubSession;
|
2017-03-22 07:02:14 +01:00
|
|
|
pub use ipc::{Server as IpcServer, MetaExtractor as IpcMetaExtractor, RequestContext as IpcRequestContext};
|
2017-04-03 10:27:37 +02:00
|
|
|
pub use http::{
|
|
|
|
hyper,
|
|
|
|
RequestMiddleware, RequestMiddlewareAction,
|
2017-04-13 16:32:07 +02:00
|
|
|
AccessControlAllowOrigin, Host, DomainsValidation
|
2017-04-03 10:27:37 +02:00
|
|
|
};
|
2017-03-22 07:02:14 +01:00
|
|
|
|
2018-07-16 13:42:59 +02:00
|
|
|
pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer};
|
2018-07-23 15:42:08 +02:00
|
|
|
pub use v1::block_import::{is_major_importing, is_major_importing_or_waiting};
|
2017-05-24 12:24:07 +02:00
|
|
|
pub use v1::extractors::{RpcExtractor, WsExtractor, WsStats, WsDispatcher};
|
|
|
|
pub use authcodes::{AuthCodes, TimeProvider};
|
|
|
|
pub use http_common::HttpMetaExtractor;
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2017-03-22 07:02:14 +01:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
/// RPC HTTP Server instance
|
2017-10-05 12:35:01 +02:00
|
|
|
pub type HttpServer = http::Server;
|
2017-04-03 10:27:37 +02:00
|
|
|
|
2017-01-11 20:02:27 +01:00
|
|
|
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
2018-07-11 12:19:54 +02:00
|
|
|
pub fn start_http<M, S, H, T>(
|
2017-01-11 20:02:27 +01:00
|
|
|
addr: &SocketAddr,
|
2017-03-22 07:02:14 +01:00
|
|
|
cors_domains: http::DomainsValidation<http::AccessControlAllowOrigin>,
|
|
|
|
allowed_hosts: http::DomainsValidation<http::Host>,
|
|
|
|
handler: H,
|
2017-02-14 22:45:43 +01:00
|
|
|
extractor: T,
|
2017-10-05 12:35:01 +02:00
|
|
|
threads: usize,
|
2018-07-02 10:23:57 +02:00
|
|
|
max_payload: usize,
|
2018-11-05 15:39:51 +01:00
|
|
|
keep_alive: bool,
|
2017-11-14 11:38:17 +01:00
|
|
|
) -> ::std::io::Result<HttpServer> where
|
2017-02-14 22:45:43 +01:00
|
|
|
M: jsonrpc_core::Metadata,
|
|
|
|
S: jsonrpc_core::Middleware<M>,
|
2017-03-22 07:02:14 +01:00
|
|
|
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
2017-04-03 10:27:37 +02:00
|
|
|
T: HttpMetaExtractor<Metadata=M>,
|
2017-02-14 22:45:43 +01:00
|
|
|
{
|
2018-02-07 16:13:54 +01:00
|
|
|
let extractor = http_common::MetaExtractor::new(extractor);
|
2018-07-11 12:19:54 +02:00
|
|
|
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
|
2018-11-05 15:39:51 +01:00
|
|
|
.keep_alive(keep_alive)
|
2017-10-05 12:35:01 +02:00
|
|
|
.threads(threads)
|
|
|
|
.cors(cors_domains.into())
|
2018-07-02 10:23:57 +02:00
|
|
|
.allowed_hosts(allowed_hosts.into())
|
2018-11-07 09:30:34 +01:00
|
|
|
.health_api(("/api/health", "parity_nodeStatus"))
|
2018-07-11 12:19:54 +02:00
|
|
|
.max_request_body_size(max_payload * 1024 * 1024)
|
|
|
|
.start_http(addr)?)
|
|
|
|
}
|
2017-10-05 12:35:01 +02:00
|
|
|
|
2018-07-11 12:19:54 +02:00
|
|
|
/// Same as `start_http`, but takes an additional `middleware` parameter that is introduced as a
|
|
|
|
/// hyper middleware.
|
|
|
|
pub fn start_http_with_middleware<M, S, H, T, R>(
|
|
|
|
addr: &SocketAddr,
|
|
|
|
cors_domains: http::DomainsValidation<http::AccessControlAllowOrigin>,
|
|
|
|
allowed_hosts: http::DomainsValidation<http::Host>,
|
|
|
|
handler: H,
|
|
|
|
extractor: T,
|
|
|
|
middleware: R,
|
|
|
|
threads: usize,
|
|
|
|
max_payload: usize,
|
2018-11-05 15:39:51 +01:00
|
|
|
keep_alive: bool,
|
2018-07-11 12:19:54 +02:00
|
|
|
) -> ::std::io::Result<HttpServer> where
|
|
|
|
M: jsonrpc_core::Metadata,
|
|
|
|
S: jsonrpc_core::Middleware<M>,
|
|
|
|
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
|
|
|
T: HttpMetaExtractor<Metadata=M>,
|
|
|
|
R: RequestMiddleware,
|
|
|
|
{
|
|
|
|
let extractor = http_common::MetaExtractor::new(extractor);
|
|
|
|
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
|
2018-11-05 15:39:51 +01:00
|
|
|
.keep_alive(keep_alive)
|
2018-07-11 12:19:54 +02:00
|
|
|
.threads(threads)
|
|
|
|
.cors(cors_domains.into())
|
|
|
|
.allowed_hosts(allowed_hosts.into())
|
|
|
|
.max_request_body_size(max_payload * 1024 * 1024)
|
|
|
|
.request_middleware(middleware)
|
|
|
|
.start_http(addr)?)
|
2017-01-11 20:02:27 +01:00
|
|
|
}
|
2016-05-04 15:37:09 +02:00
|
|
|
|
2017-01-11 20:02:27 +01:00
|
|
|
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
|
2017-03-22 07:02:14 +01:00
|
|
|
pub fn start_ipc<M, S, H, T>(
|
2017-02-04 22:18:19 +01:00
|
|
|
addr: &str,
|
2017-03-22 07:02:14 +01:00
|
|
|
handler: H,
|
|
|
|
extractor: T,
|
|
|
|
) -> ::std::io::Result<ipc::Server> where
|
|
|
|
M: jsonrpc_core::Metadata,
|
|
|
|
S: jsonrpc_core::Middleware<M>,
|
|
|
|
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
|
|
|
T: IpcMetaExtractor<M>,
|
|
|
|
{
|
2018-02-07 16:13:54 +01:00
|
|
|
ipc::ServerBuilder::with_meta_extractor(handler, extractor)
|
2017-03-22 07:02:14 +01:00
|
|
|
.start(addr)
|
2016-03-02 12:42:08 +01:00
|
|
|
}
|
2017-04-13 16:32:07 +02:00
|
|
|
|
|
|
|
/// Start WS server and return `Server` handle.
|
2017-05-24 12:24:07 +02:00
|
|
|
pub fn start_ws<M, S, H, T, U, V>(
|
2017-04-13 16:32:07 +02:00
|
|
|
addr: &SocketAddr,
|
|
|
|
handler: H,
|
|
|
|
allowed_origins: ws::DomainsValidation<ws::Origin>,
|
|
|
|
allowed_hosts: ws::DomainsValidation<ws::Host>,
|
2018-04-02 12:33:09 +02:00
|
|
|
max_connections: usize,
|
2017-04-13 16:32:07 +02:00
|
|
|
extractor: T,
|
2017-05-24 12:24:07 +02:00
|
|
|
middleware: V,
|
2017-04-13 16:32:07 +02:00
|
|
|
stats: U,
|
|
|
|
) -> Result<ws::Server, ws::Error> where
|
|
|
|
M: jsonrpc_core::Metadata,
|
|
|
|
S: jsonrpc_core::Middleware<M>,
|
|
|
|
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
|
|
|
T: ws::MetaExtractor<M>,
|
|
|
|
U: ws::SessionStats,
|
2017-05-24 12:24:07 +02:00
|
|
|
V: ws::RequestMiddleware,
|
2017-04-13 16:32:07 +02:00
|
|
|
{
|
2018-02-07 16:13:54 +01:00
|
|
|
ws::ServerBuilder::with_meta_extractor(handler, extractor)
|
2017-05-24 12:24:07 +02:00
|
|
|
.request_middleware(middleware)
|
2017-04-13 16:32:07 +02:00
|
|
|
.allowed_origins(allowed_origins)
|
|
|
|
.allowed_hosts(allowed_hosts)
|
2018-04-02 12:33:09 +02:00
|
|
|
.max_connections(max_connections)
|
2017-04-13 16:32:07 +02:00
|
|
|
.session_stats(stats)
|
|
|
|
.start(addr)
|
|
|
|
}
|