Skip to content

Commit 12b6210

Browse files
authored
Bump to 12.0 and change core-client transports a bit. (#440)
* Rename http client method, tls enables http. * Bump version. * Add tagging to publish script. * Make sure we generate nice docs for transports as well. * Add transports to publish script.
1 parent 1bbd403 commit 12b6210

File tree

29 files changed

+338
-291
lines changed

29 files changed

+338
-291
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ before_script:
3232
script:
3333
- cargo build --all
3434
- cargo test --all
35-
- cargo test --manifest-path=core-client/Cargo.toml --features "http"
36-
- cargo test --manifest-path=core-client/Cargo.toml --features "http, tls"
37-
- cargo test --manifest-path=core-client/Cargo.toml --features "ws"
3835
- |
3936
([ $TRAVIS_RUST_VERSION = stable ] && cargo fmt --all -- --check) || true
4037

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"core",
44
"core-client",
5+
"core-client/transports",
56
"http",
67
"ipc",
78
"derive",

_automate/publish.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
set -exu
44

5-
ORDER=(core core-client server-utils tcp ws ws/client http ipc stdio pubsub derive test)
5+
VERSION=$(grep "^version" ./core/Cargo.toml | sed -e 's/.*"\(.*\)"/\1/')
6+
ORDER=(core core-client/transports core-client server-utils tcp ws ws/client http ipc stdio pubsub derive test)
7+
8+
echo "Publishing version $VERSION"
9+
cargo clean
610

711
for crate in ${ORDER[@]}; do
812
cd $crate
13+
echo "Publishing $crate@$VERSION"
14+
sleep 5
915
cargo publish $@
1016
cd -
1117
done
1218

19+
echo "Tagging version $VERSION"
20+
git tag -a v$VERSION -m "Version $VERSION"
21+
git push --tags

core-client/Cargo.toml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
88
license = "MIT"
99
name = "jsonrpc-core-client"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "11.0.0"
11+
version = "12.0.0"
1212

1313
categories = [
1414
"asynchronous",
@@ -19,31 +19,12 @@ categories = [
1919
]
2020

2121
[features]
22-
tls = ["hyper-tls"]
23-
http = ["hyper"]
24-
ws = [
25-
"websocket",
26-
"tokio",
27-
]
22+
tls = ["jsonrpc-client-transports/tls"]
23+
http = ["jsonrpc-client-transports/http"]
24+
ws = ["jsonrpc-client-transports/ws"]
2825

2926
[dependencies]
30-
failure = "0.1"
31-
futures = "0.1.26"
32-
hyper = { version = "0.12", optional = true }
33-
hyper-tls = { version = "0.3.2", optional = true }
34-
jsonrpc-core = { version = "11.0", path = "../core" }
35-
log = "0.4"
36-
serde = "1.0"
37-
serde_json = "1.0"
38-
tokio = { version = "0.1", optional = true }
39-
websocket = { version = "0.22", optional = true }
40-
41-
[dev-dependencies]
42-
assert_matches = "1.1"
43-
jsonrpc-http-server = { version = "11.0", path = "../http" }
44-
lazy_static = "1.0"
45-
env_logger = "0.6"
46-
tokio = "0.1"
27+
jsonrpc-client-transports = { version = "12.0", path = "./transports", default-features = false }
4728

4829
[badges]
4930
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}

core-client/src/lib.rs

Lines changed: 8 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,8 @@
1-
//! JSON-RPC client implementation.
2-
#![deny(missing_docs)]
3-
4-
use failure::{format_err, Fail};
5-
use futures::sync::{mpsc, oneshot};
6-
use futures::{future, prelude::*};
7-
use jsonrpc_core::{Error, Params};
8-
use serde::de::DeserializeOwned;
9-
use serde::Serialize;
10-
use serde_json::Value;
11-
12-
pub mod transports;
13-
14-
#[cfg(test)]
15-
mod logger;
16-
17-
/// The errors returned by the client.
18-
#[derive(Debug, Fail)]
19-
pub enum RpcError {
20-
/// An error returned by the server.
21-
#[fail(display = "Server returned rpc error {}", _0)]
22-
JsonRpcError(Error),
23-
/// Failure to parse server response.
24-
#[fail(display = "Failed to parse server response as {}: {}", _0, _1)]
25-
ParseError(String, failure::Error),
26-
/// Request timed out.
27-
#[fail(display = "Request timed out")]
28-
Timeout,
29-
/// The server returned a response with an unknown id.
30-
#[fail(display = "Server returned a response with an unknown id")]
31-
UnknownId,
32-
/// Not rpc specific errors.
33-
#[fail(display = "{}", _0)]
34-
Other(failure::Error),
35-
}
36-
37-
impl From<Error> for RpcError {
38-
fn from(error: Error) -> Self {
39-
RpcError::JsonRpcError(error)
40-
}
41-
}
42-
43-
/// A message sent to the `RpcClient`. This is public so that
44-
/// the derive crate can generate a client.
45-
struct RpcMessage {
46-
/// The rpc method name.
47-
method: String,
48-
/// The rpc method parameters.
49-
params: Params,
50-
/// The oneshot channel to send the result of the rpc
51-
/// call to.
52-
sender: oneshot::Sender<Result<Value, RpcError>>,
53-
}
54-
55-
/// A channel to a `RpcClient`.
56-
#[derive(Clone)]
57-
pub struct RpcChannel(mpsc::Sender<RpcMessage>);
58-
59-
impl RpcChannel {
60-
fn send(
61-
&self,
62-
msg: RpcMessage,
63-
) -> impl Future<Item = mpsc::Sender<RpcMessage>, Error = mpsc::SendError<RpcMessage>> {
64-
self.0.to_owned().send(msg)
65-
}
66-
}
67-
68-
impl From<mpsc::Sender<RpcMessage>> for RpcChannel {
69-
fn from(sender: mpsc::Sender<RpcMessage>) -> Self {
70-
RpcChannel(sender)
71-
}
72-
}
73-
74-
/// The future returned by the rpc call.
75-
pub struct RpcFuture {
76-
recv: oneshot::Receiver<Result<Value, RpcError>>,
77-
}
78-
79-
impl RpcFuture {
80-
/// Creates a new `RpcFuture`.
81-
pub fn new(recv: oneshot::Receiver<Result<Value, RpcError>>) -> Self {
82-
RpcFuture { recv }
83-
}
84-
}
85-
86-
impl Future for RpcFuture {
87-
type Item = Value;
88-
type Error = RpcError;
89-
90-
fn poll(&mut self) -> Result<Async<Self::Item>, Self::Error> {
91-
// TODO should timeout (#410)
92-
match self.recv.poll() {
93-
Ok(Async::Ready(Ok(value))) => Ok(Async::Ready(value)),
94-
Ok(Async::Ready(Err(error))) => Err(error),
95-
Ok(Async::NotReady) => Ok(Async::NotReady),
96-
Err(error) => Err(RpcError::Other(error.into())),
97-
}
98-
}
99-
}
100-
101-
/// Client for raw JSON RPC requests
102-
#[derive(Clone)]
103-
pub struct RawClient(RpcChannel);
104-
105-
impl From<RpcChannel> for RawClient {
106-
fn from(channel: RpcChannel) -> Self {
107-
RawClient(channel)
108-
}
109-
}
110-
111-
impl RawClient {
112-
/// Call RPC with raw JSON
113-
pub fn call_method(&self, method: &str, params: Params) -> impl Future<Item = Value, Error = RpcError> {
114-
let (sender, receiver) = oneshot::channel();
115-
let msg = RpcMessage {
116-
method: method.into(),
117-
params,
118-
sender,
119-
};
120-
self.0
121-
.send(msg)
122-
.map_err(|error| RpcError::Other(error.into()))
123-
.and_then(|_| RpcFuture::new(receiver))
124-
}
125-
}
126-
127-
/// Client for typed JSON RPC requests
128-
#[derive(Clone)]
129-
pub struct TypedClient(RawClient);
130-
131-
impl From<RpcChannel> for TypedClient {
132-
fn from(channel: RpcChannel) -> Self {
133-
TypedClient(channel.into())
134-
}
135-
}
136-
137-
impl TypedClient {
138-
/// Create new TypedClient
139-
pub fn new(raw_cli: RawClient) -> Self {
140-
TypedClient(raw_cli)
141-
}
142-
143-
/// Call RPC with serialization of request and deserialization of response
144-
pub fn call_method<T: Serialize, R: DeserializeOwned + 'static>(
145-
&self,
146-
method: &str,
147-
returns: &'static str,
148-
args: T,
149-
) -> impl Future<Item = R, Error = RpcError> {
150-
let args =
151-
serde_json::to_value(args).expect("Only types with infallible serialisation can be used for JSON-RPC");
152-
let params = match args {
153-
Value::Array(vec) => Params::Array(vec),
154-
Value::Null => Params::None,
155-
_ => {
156-
return future::Either::A(future::err(RpcError::Other(format_err!(
157-
"RPC params should serialize to a JSON array, or null"
158-
))))
159-
}
160-
};
161-
162-
future::Either::B(self.0.call_method(method, params).and_then(move |value: Value| {
163-
log::debug!("response: {:?}", value);
164-
let result =
165-
serde_json::from_value::<R>(value).map_err(|error| RpcError::ParseError(returns.into(), error.into()));
166-
future::done(result)
167-
}))
168-
}
169-
}
170-
171-
#[cfg(test)]
172-
mod tests {
173-
use super::*;
174-
use crate::transports::local;
175-
use crate::{RpcChannel, RpcError, TypedClient};
176-
use jsonrpc_core::{self, IoHandler};
177-
178-
#[derive(Clone)]
179-
struct AddClient(TypedClient);
180-
181-
impl From<RpcChannel> for AddClient {
182-
fn from(channel: RpcChannel) -> Self {
183-
AddClient(channel.into())
184-
}
185-
}
186-
187-
impl AddClient {
188-
fn add(&self, a: u64, b: u64) -> impl Future<Item = u64, Error = RpcError> {
189-
self.0.call_method("add", "u64", (a, b))
190-
}
191-
}
192-
193-
#[test]
194-
fn test_client_terminates() {
195-
let mut handler = IoHandler::new();
196-
handler.add_method("add", |params: Params| {
197-
let (a, b) = params.parse::<(u64, u64)>()?;
198-
let res = a + b;
199-
Ok(jsonrpc_core::to_value(res).unwrap())
200-
});
201-
202-
let (client, rpc_client) = local::connect::<AddClient, _, _>(handler);
203-
let fut = client
204-
.clone()
205-
.add(3, 4)
206-
.and_then(move |res| client.add(res, 5))
207-
.join(rpc_client)
208-
.map(|(res, ())| {
209-
assert_eq!(res, 12);
210-
})
211-
.map_err(|err| {
212-
eprintln!("{:?}", err);
213-
assert!(false);
214-
});
215-
tokio::run(fut);
216-
}
217-
}
1+
//! JSON-RPC client implementation primitives.
2+
//!
3+
//! By default this crate does not implement any transports,
4+
//! use corresponding features (`tls`, `http` or `ws`) to opt-in for them.
5+
//!
6+
//! See documentation of [`jsonrpc-client-transports`](../jsonrpc_client_transports/) for more details.
7+
8+
pub use jsonrpc_client_transports::*;

core-client/transports/Cargo.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[package]
2+
authors = ["Parity Technologies <admin@parity.io>"]
3+
description = "Transport agnostic JSON-RPC 2.0 client implementation."
4+
documentation = "https://docs.rs/jsonrpc-client-transports/"
5+
edition = "2018"
6+
homepage = "https://github.com/paritytech/jsonrpc"
7+
keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
8+
license = "MIT"
9+
name = "jsonrpc-client-transports"
10+
repository = "https://github.com/paritytech/jsonrpc"
11+
version = "12.0.0"
12+
13+
categories = [
14+
"asynchronous",
15+
"network-programming",
16+
"web-programming::http-client",
17+
"web-programming::http-server",
18+
"web-programming::websocket",
19+
]
20+
21+
[features]
22+
default = ["http", "tls", "ws"]
23+
tls = ["hyper-tls", "http"]
24+
http = ["hyper"]
25+
ws = [
26+
"websocket",
27+
"tokio",
28+
]
29+
30+
[dependencies]
31+
failure = "0.1"
32+
futures = "0.1.26"
33+
hyper = { version = "0.12", optional = true }
34+
hyper-tls = { version = "0.3.2", optional = true }
35+
jsonrpc-core = { version = "12.0", path = "../../core" }
36+
log = "0.4"
37+
serde = "1.0"
38+
serde_json = "1.0"
39+
tokio = { version = "0.1", optional = true }
40+
websocket = { version = "0.22", optional = true }
41+
42+
[dev-dependencies]
43+
assert_matches = "1.1"
44+
jsonrpc-http-server = { version = "12.0", path = "../../http" }
45+
lazy_static = "1.0"
46+
env_logger = "0.6"
47+
tokio = "0.1"
48+
49+
[badges]
50+
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}

0 commit comments

Comments
 (0)