New version of jsonrpc.
This commit is contained in:
102
rpc/src/lib.rs
102
rpc/src/lib.rs
@@ -19,31 +19,32 @@
|
||||
#![cfg_attr(feature="nightly", feature(plugin))]
|
||||
#![cfg_attr(feature="nightly", plugin(clippy))]
|
||||
|
||||
extern crate semver;
|
||||
extern crate rustc_serialize;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate jsonrpc_http_server;
|
||||
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore;
|
||||
extern crate ethkey;
|
||||
extern crate ethcrypto as crypto;
|
||||
extern crate ethstore;
|
||||
extern crate ethsync;
|
||||
extern crate ethash;
|
||||
extern crate ethcore_light as light;
|
||||
extern crate transient_hashmap;
|
||||
extern crate jsonrpc_ipc_server as ipc;
|
||||
extern crate ethcore_ipc;
|
||||
extern crate time;
|
||||
extern crate rlp;
|
||||
extern crate fetch;
|
||||
extern crate futures;
|
||||
extern crate order_stat;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate rustc_serialize;
|
||||
extern crate semver;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate time;
|
||||
extern crate transient_hashmap;
|
||||
|
||||
extern crate jsonrpc_core;
|
||||
pub extern crate jsonrpc_http_server as http;
|
||||
pub extern crate jsonrpc_ipc_server as ipc;
|
||||
|
||||
extern crate ethash;
|
||||
extern crate ethcore;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore_ipc;
|
||||
extern crate ethcore_light as light;
|
||||
extern crate ethcrypto as crypto;
|
||||
extern crate ethkey;
|
||||
extern crate ethstore;
|
||||
extern crate ethsync;
|
||||
extern crate fetch;
|
||||
extern crate parity_reactor;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate rlp;
|
||||
extern crate stats;
|
||||
|
||||
#[macro_use]
|
||||
@@ -60,57 +61,50 @@ extern crate ethjson;
|
||||
#[cfg(test)]
|
||||
extern crate ethcore_devtools as devtools;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use io::PanicHandler;
|
||||
use jsonrpc_core::reactor::RpcHandler;
|
||||
pub mod v1;
|
||||
|
||||
pub use ipc::{Server as IpcServer, Error as IpcServerError};
|
||||
pub use jsonrpc_http_server::{ServerBuilder, Server, RpcServerError, HttpMetaExtractor};
|
||||
pub mod v1;
|
||||
pub use http::{HttpMetaExtractor, Server as HttpServer, Error as HttpServerError, AccessControlAllowOrigin, Host};
|
||||
|
||||
pub use v1::{SigningQueue, SignerService, ConfirmationsQueue, NetworkSettings, Metadata, Origin, informant, dispatch};
|
||||
pub use v1::block_import::is_major_importing;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use http::tokio_core;
|
||||
|
||||
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_http<M, T, S>(
|
||||
pub fn start_http<M, S, H, T>(
|
||||
addr: &SocketAddr,
|
||||
cors_domains: Option<Vec<String>>,
|
||||
allowed_hosts: Option<Vec<String>>,
|
||||
panic_handler: Arc<PanicHandler>,
|
||||
handler: RpcHandler<M, S>,
|
||||
cors_domains: http::DomainsValidation<http::AccessControlAllowOrigin>,
|
||||
allowed_hosts: http::DomainsValidation<http::Host>,
|
||||
handler: H,
|
||||
remote: tokio_core::reactor::Remote,
|
||||
extractor: T,
|
||||
) -> Result<Server, RpcServerError> where
|
||||
) -> Result<HttpServer, HttpServerError> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
||||
T: HttpMetaExtractor<M>,
|
||||
{
|
||||
|
||||
let cors_domains = cors_domains.map(|domains| {
|
||||
domains.into_iter()
|
||||
.map(|v| match v.as_str() {
|
||||
"*" => jsonrpc_http_server::AccessControlAllowOrigin::Any,
|
||||
"null" => jsonrpc_http_server::AccessControlAllowOrigin::Null,
|
||||
v => jsonrpc_http_server::AccessControlAllowOrigin::Value(v.into()),
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
ServerBuilder::with_rpc_handler(handler)
|
||||
.meta_extractor(Arc::new(extractor))
|
||||
http::ServerBuilder::new(handler)
|
||||
.event_loop_remote(remote)
|
||||
.meta_extractor(extractor)
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
.panic_handler(move || {
|
||||
panic_handler.notify_all("Panic in RPC thread.".to_owned());
|
||||
})
|
||||
.start_http(addr)
|
||||
}
|
||||
|
||||
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_ipc<M: jsonrpc_core::Metadata, S: jsonrpc_core::Middleware<M>>(
|
||||
pub fn start_ipc<M, S, H>(
|
||||
addr: &str,
|
||||
handler: RpcHandler<M, S>,
|
||||
) -> Result<ipc::Server<M, S>, ipc::Error> {
|
||||
let server = ipc::Server::with_rpc_handler(addr, handler)?;
|
||||
handler: H,
|
||||
remote: tokio_core::reactor::Remote,
|
||||
) -> Result<ipc::Server<M, S>, ipc::Error> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
H: Into<jsonrpc_core::MetaIoHandler<M, S>>,
|
||||
{
|
||||
let server = ipc::Server::with_remote(addr, handler, ipc::UninitializedRemote::Shared(remote))?;
|
||||
server.run_async()?;
|
||||
Ok(server)
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ fn rpc_eth_send_transaction_with_bad_to() {
|
||||
"id": 1
|
||||
}"#;
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid length.","data":null},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid length."},"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
}
|
||||
@@ -1058,7 +1058,7 @@ fn rpc_get_work_returns_no_work_if_cant_mine() {
|
||||
eth_tester.client.set_queue_size(10);
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Still syncing.","data":null},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Still syncing."},"id":1}"#;
|
||||
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
@@ -1117,6 +1117,6 @@ fn rpc_get_work_should_timeout() {
|
||||
|
||||
// Request with timeout of 10 seconds. This should fail.
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["10"], "id": 1}"#;
|
||||
let err_response = r#"{"jsonrpc":"2.0","error":{"code":-32003,"message":"Work has not changed.","data":null},"id":1}"#;
|
||||
let err_response = r#"{"jsonrpc":"2.0","error":{"code":-32003,"message":"Work has not changed."},"id":1}"#;
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(err_response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ fn rpc_parity_unsigned_transactions_count_when_signer_disabled() {
|
||||
let io = deps.default_client();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available.","data":null},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available."},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
@@ -382,7 +382,7 @@ fn rpc_parity_signer_port() {
|
||||
// when
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_signerPort", "params": [], "id": 1}"#;
|
||||
let response1 = r#"{"jsonrpc":"2.0","result":18180,"id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available.","data":null},"id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available."},"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(io1.handle_request_sync(request), Some(response1.to_owned()));
|
||||
@@ -400,7 +400,7 @@ fn rpc_parity_dapps_port() {
|
||||
// when
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_dappsPort", "params": [], "id": 1}"#;
|
||||
let response1 = r#"{"jsonrpc":"2.0","result":18080,"id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32031,"message":"Dapps Server is disabled. This API is not available.","data":null},"id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32031,"message":"Dapps Server is disabled. This API is not available."},"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(io1.handle_request_sync(request), Some(response1.to_owned()));
|
||||
@@ -418,7 +418,7 @@ fn rpc_parity_dapps_interface() {
|
||||
// when
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_dappsInterface", "params": [], "id": 1}"#;
|
||||
let response1 = r#"{"jsonrpc":"2.0","result":"127.0.0.1","id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32031,"message":"Dapps Server is disabled. This API is not available.","data":null},"id":1}"#;
|
||||
let response2 = r#"{"jsonrpc":"2.0","error":{"code":-32031,"message":"Dapps Server is disabled. This API is not available."},"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(io1.handle_request_sync(request), Some(response1.to_owned()));
|
||||
|
||||
@@ -230,7 +230,7 @@ fn should_be_able_to_kill_account() {
|
||||
let address = accounts[0];
|
||||
|
||||
let request = format!(r#"{{"jsonrpc": "2.0", "method": "parity_killAccount", "params": ["0xf00baba2f00baba2f00baba2f00baba2f00baba2"], "id": 1}}"#);
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid length 1, expected a tuple of size 2","data":null},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid length 1, expected a tuple of size 2"},"id":1}"#;
|
||||
let res = tester.io.handle_request_sync(&request);
|
||||
assert_eq!(res, Some(response.into()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user