Skip to content

Commit 81f7eb3

Browse files
authored
rpc: guard client with feature flag (#343)
Guard client code paths To avoid the transient dependency on net related crates for users who are primarily interested in the core types. Follow-up #339 Ref #337
1 parent e2335c4 commit 81f7eb3

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

light-node/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async-trait = "0.1"
1010
gumdrop = "0.7"
1111
serde = { version = "1", features = ["serde_derive"] }
1212
tendermint = { version = "0.13.0-dev", path = "../tendermint" }
13-
tendermint-rpc = { version = "0.1.0", path = "../rpc" }
13+
tendermint-rpc = { version = "0.1.0", path = "../rpc", features = [ "client" ] }
1414
tokio = { version = "0.2", features = ["full"] }
1515

1616
[dependencies.abscissa_core]

rpc/Cargo.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ version = "0.1.0"
44
authors = ["Alexander Simmerl <[email protected]>"]
55
edition = "2018"
66

7+
[features]
8+
default = []
9+
client = [ "async-tungstenite", "futures", "http", "hyper", "tokio" ]
10+
711
[dependencies]
8-
async-tungstenite = {version="0.5", features = ["tokio-runtime"]}
912
bytes = "0.5"
10-
futures = "0.3"
1113
getrandom = "0.1"
12-
http = "0.2"
13-
hyper = "0.13"
1414
serde = { version = "1", features = [ "derive" ] }
1515
serde_bytes = "0.11"
1616
serde_json = "1"
1717
tendermint = { version = "0.13.0", path = "../tendermint" }
1818
thiserror = "1"
19-
tokio = { version = "0.2", features = ["macros"] }
2019
uuid = { version = "0.8", default-features = false }
20+
21+
async-tungstenite = { version="0.5", features = ["tokio-runtime"], optional = true }
22+
futures = { version = "0.3", optional = true }
23+
http = { version = "0.2", optional = true }
24+
hyper = { version = "0.13", optional = true }
25+
tokio = { version = "0.2", features = ["macros"], optional = true }

rpc/src/client.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use tendermint::Genesis;
1010

1111
use crate::{endpoint::*, Error, Request, Response};
1212

13+
pub mod event_listener;
14+
1315
/// Tendermint RPC client.
1416
///
1517
/// Presently supports JSONRPC via HTTP.

rpc/src/event_listener.rs rpc/src/client/event_listener.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Tendermint Websocket event listener client
22
3+
// TODO(ismail): document fields or re-use the abci types
4+
#![allow(missing_docs)]
5+
36
use async_tungstenite::{tokio::connect_async, tokio::TokioAdapter, tungstenite::Message};
47
use futures::prelude::*;
58
use serde::{Deserialize, Serialize};

rpc/src/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! JSONRPC error types
22
3+
#[cfg(feature = "client")]
34
use async_tungstenite::tungstenite::Error as WSError;
5+
46
use serde::{Deserialize, Deserializer, Serialize, Serializer};
57
use std::fmt::{self, Display};
68
use thiserror::Error;
@@ -102,18 +104,21 @@ impl Display for Error {
102104
}
103105
}
104106

107+
#[cfg(feature = "client")]
105108
impl From<http::Error> for Error {
106109
fn from(http_error: http::Error) -> Error {
107110
Error::http_error(http_error.to_string())
108111
}
109112
}
110113

114+
#[cfg(feature = "client")]
111115
impl From<hyper::Error> for Error {
112116
fn from(hyper_error: hyper::Error) -> Error {
113117
Error::http_error(hyper_error.to_string())
114118
}
115119
}
116120

121+
#[cfg(feature = "client")]
117122
impl From<WSError> for Error {
118123
fn from(websocket_error: WSError) -> Error {
119124
Error::websocket_error(websocket_error.to_string())

rpc/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! Tendermint RPC definitons and types.
22
3+
#[cfg(feature = "client")]
34
mod client;
5+
#[cfg(feature = "client")]
6+
pub use client::{event_listener, Client};
7+
48
pub mod endpoint;
59
pub mod error;
6-
// TODO(ismail): document fields or re-use the abci types
7-
#[allow(missing_docs)]
8-
pub mod event_listener;
910
mod id;
1011
mod method;
1112
pub mod request;
1213
pub mod response;
1314
mod version;
1415

1516
pub use self::{
16-
client::Client, error::Error, id::Id, method::Method, request::Request, response::Response,
17-
version::Version,
17+
error::Error, id::Id, method::Method, request::Request, response::Response, version::Version,
1818
};

tendermint/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ zeroize = { version = "1.1", features = ["zeroize_derive"] }
5656
ripemd160 = "0.9"
5757

5858
[dev-dependencies]
59-
tendermint-rpc = { version = "0.1.0", path = "../rpc" }
59+
tendermint-rpc = { version = "0.1.0", path = "../rpc", features = [ "client" ] }
6060
tokio = { version = "0.2", features = [ "macros" ] }

0 commit comments

Comments
 (0)