From 54eb9d7d4eaa35dfca87fbd396a3e06216c7c8fa Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 15 Sep 2021 16:22:59 +0200 Subject: [PATCH 1/2] Re-export v2::params, error, request and response types --- types/src/v2/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/src/v2/mod.rs b/types/src/v2/mod.rs index 98e0b02a03..60776f01f5 100644 --- a/types/src/v2/mod.rs +++ b/types/src/v2/mod.rs @@ -34,3 +34,8 @@ pub mod params; pub mod request; /// JSON-RPC response object related types. pub mod response; + +pub use error::{RpcError, ErrorObject, ErrorCode}; +pub use params::{TwoPointZero, Params, ParamsSequence, ParamsSer, SubscriptionId, Id}; +pub use request::{Request, RequestSer, InvalidRequest, Notification, NotificationSer}; +pub use response::{Response, SubscriptionResponse, SubscriptionPayload}; From dce488c42b0d9608e5fd5502d8cbb604db954491 Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 15 Sep 2021 16:41:29 +0200 Subject: [PATCH 2/2] Use shallow type paths --- benches/bench.rs | 3 +-- examples/weather.rs | 2 +- examples/ws.rs | 2 +- examples/ws_sub_with_params.rs | 2 +- examples/ws_subscription.rs | 2 +- http-client/src/client.rs | 7 +------ http-client/src/tests.rs | 5 +---- http-server/src/response.rs | 5 +---- http-server/src/server.rs | 6 +----- tests/tests/integration_tests.rs | 2 +- types/src/client.rs | 2 +- types/src/traits.rs | 2 +- types/src/v2/mod.rs | 8 ++++---- utils/src/server/helpers.rs | 7 +------ utils/src/server/rpc_module.rs | 7 +++---- ws-client/src/client.rs | 13 +++---------- ws-client/src/helpers.rs | 5 +---- ws-client/src/manager.rs | 4 ++-- ws-client/src/tests.rs | 5 +---- ws-server/src/server.rs | 6 +++++- 20 files changed, 32 insertions(+), 63 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 0e8d0ba479..229420267c 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -6,8 +6,7 @@ use jsonrpsee::{ types::traits::SubscriptionClient, types::{ traits::Client, - v2::params::{Id, ParamsSer}, - v2::request::RequestSer, + v2::{Id, ParamsSer, RequestSer}, }, ws_client::WsClientBuilder, }; diff --git a/examples/weather.rs b/examples/weather.rs index 59ddaab369..f86e51f398 100644 --- a/examples/weather.rs +++ b/examples/weather.rs @@ -31,7 +31,7 @@ //! mutation. use jsonrpsee::{ - types::{traits::SubscriptionClient, v2::params::ParamsSer}, + types::{traits::SubscriptionClient, v2::ParamsSer}, ws_client::WsClientBuilder, ws_server::RpcModule, ws_server::WsServerBuilder, diff --git a/examples/ws.rs b/examples/ws.rs index d09a0dbc81..12e2a7ed00 100644 --- a/examples/ws.rs +++ b/examples/ws.rs @@ -25,7 +25,7 @@ // DEALINGS IN THE SOFTWARE. use jsonrpsee::{ - types::{traits::Client, v2::params::ParamsSer}, + types::{traits::Client, v2::ParamsSer}, ws_client::WsClientBuilder, ws_server::{RpcModule, WsServerBuilder}, }; diff --git a/examples/ws_sub_with_params.rs b/examples/ws_sub_with_params.rs index c35dc4da54..67deeb84a4 100644 --- a/examples/ws_sub_with_params.rs +++ b/examples/ws_sub_with_params.rs @@ -25,7 +25,7 @@ // DEALINGS IN THE SOFTWARE. use jsonrpsee::{ - types::{traits::SubscriptionClient, v2::params::ParamsSer}, + types::{traits::SubscriptionClient, v2::ParamsSer}, ws_client::WsClientBuilder, ws_server::{RpcModule, WsServerBuilder}, }; diff --git a/examples/ws_subscription.rs b/examples/ws_subscription.rs index 61d3597d10..1e4d9545f7 100644 --- a/examples/ws_subscription.rs +++ b/examples/ws_subscription.rs @@ -25,7 +25,7 @@ // DEALINGS IN THE SOFTWARE. use jsonrpsee::{ - types::{traits::SubscriptionClient, v2::params::ParamsSer, Error, Subscription}, + types::{traits::SubscriptionClient, v2::ParamsSer, Error, Subscription}, ws_client::WsClientBuilder, ws_server::{RpcModule, WsServerBuilder}, }; diff --git a/http-client/src/client.rs b/http-client/src/client.rs index 074dc58e6e..53e520ea25 100644 --- a/http-client/src/client.rs +++ b/http-client/src/client.rs @@ -27,12 +27,7 @@ use crate::transport::HttpTransportClient; use crate::types::{ traits::Client, - v2::{ - error::RpcError, - params::{Id, ParamsSer}, - request::{NotificationSer, RequestSer}, - response::Response, - }, + v2::{Id, NotificationSer, ParamsSer, RequestSer, Response, RpcError}, Error, TEN_MB_SIZE_BYTES, }; use async_trait::async_trait; diff --git a/http-client/src/tests.rs b/http-client/src/tests.rs index f7d08c68d9..8ce53edb98 100644 --- a/http-client/src/tests.rs +++ b/http-client/src/tests.rs @@ -26,10 +26,7 @@ use crate::types::{ traits::Client, - v2::{ - error::{ErrorCode, ErrorObject, RpcError}, - params::ParamsSer, - }, + v2::{ErrorCode, ErrorObject, ParamsSer, RpcError}, Error, JsonValue, }; use crate::HttpClientBuilder; diff --git a/http-server/src/response.rs b/http-server/src/response.rs index a615cfc5cb..18f2313fdf 100644 --- a/http-server/src/response.rs +++ b/http-server/src/response.rs @@ -26,10 +26,7 @@ //! Contains common builders for hyper responses. -use crate::types::v2::{ - error::{ErrorCode, RpcError}, - params::{Id, TwoPointZero}, -}; +use crate::types::v2::{ErrorCode, Id, RpcError, TwoPointZero}; const JSON: &str = "application/json; charset=utf-8"; const TEXT: &str = "text/plain"; diff --git a/http-server/src/server.rs b/http-server/src/server.rs index 9fe090d2c3..8c9bf02214 100644 --- a/http-server/src/server.rs +++ b/http-server/src/server.rs @@ -35,11 +35,7 @@ use hyper::{ }; use jsonrpsee_types::{ error::{Error, GenericTransportError}, - v2::{ - error::ErrorCode, - params::Id, - request::{Notification, Request}, - }, + v2::{ErrorCode, Id, Notification, Request}, TEN_MB_SIZE_BYTES, }; use jsonrpsee_utils::http_helpers::read_body; diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index 44cf0e5e32..3b4329b6df 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -34,7 +34,7 @@ use jsonrpsee::{ http_client::HttpClientBuilder, types::{ traits::{Client, SubscriptionClient}, - v2::params::ParamsSer, + v2::ParamsSer, Error, JsonValue, Subscription, }, ws_client::WsClientBuilder, diff --git a/types/src/client.rs b/types/src/client.rs index 02584c4f62..32a11a05fe 100644 --- a/types/src/client.rs +++ b/types/src/client.rs @@ -24,7 +24,7 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::{error::SubscriptionClosedError, v2::params::SubscriptionId, Error}; +use crate::{error::SubscriptionClosedError, v2::SubscriptionId, Error}; use core::marker::PhantomData; use futures_channel::{mpsc, oneshot}; use futures_util::{future::FutureExt, sink::SinkExt, stream::StreamExt}; diff --git a/types/src/traits.rs b/types/src/traits.rs index 2163bd9bf9..8906b9028e 100644 --- a/types/src/traits.rs +++ b/types/src/traits.rs @@ -24,7 +24,7 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::v2::params::ParamsSer; +use crate::v2::ParamsSer; use crate::{Error, Subscription}; use async_trait::async_trait; use serde::de::DeserializeOwned; diff --git a/types/src/v2/mod.rs b/types/src/v2/mod.rs index 60776f01f5..d3dcfdb245 100644 --- a/types/src/v2/mod.rs +++ b/types/src/v2/mod.rs @@ -35,7 +35,7 @@ pub mod request; /// JSON-RPC response object related types. pub mod response; -pub use error::{RpcError, ErrorObject, ErrorCode}; -pub use params::{TwoPointZero, Params, ParamsSequence, ParamsSer, SubscriptionId, Id}; -pub use request::{Request, RequestSer, InvalidRequest, Notification, NotificationSer}; -pub use response::{Response, SubscriptionResponse, SubscriptionPayload}; +pub use error::{ErrorCode, ErrorObject, RpcError}; +pub use params::{Id, Params, ParamsSequence, ParamsSer, SubscriptionId, TwoPointZero}; +pub use request::{InvalidRequest, Notification, NotificationSer, Request, RequestSer}; +pub use response::{Response, SubscriptionPayload, SubscriptionResponse}; diff --git a/utils/src/server/helpers.rs b/utils/src/server/helpers.rs index 532dc8f2f5..70445822fd 100644 --- a/utils/src/server/helpers.rs +++ b/utils/src/server/helpers.rs @@ -27,12 +27,7 @@ use crate::server::rpc_module::MethodSink; use futures_channel::mpsc; use futures_util::stream::StreamExt; -use jsonrpsee_types::v2::{ - error::{ErrorCode, ErrorObject, RpcError}, - params::{Id, TwoPointZero}, - request::InvalidRequest, - response::Response, -}; +use jsonrpsee_types::v2::{ErrorCode, ErrorObject, Id, InvalidRequest, Response, RpcError, TwoPointZero}; use serde::Serialize; /// Helper for sending JSON-RPC responses to the client diff --git a/utils/src/server/rpc_module.rs b/utils/src/server/rpc_module.rs index 0bf4511030..9ebf788a9a 100644 --- a/utils/src/server/rpc_module.rs +++ b/utils/src/server/rpc_module.rs @@ -32,10 +32,9 @@ use jsonrpsee_types::{ error::{CallError, Error, SubscriptionClosedError}, traits::ToRpcParams, v2::{ - error::{ErrorCode, ErrorObject, CALL_EXECUTION_FAILED_CODE, UNKNOWN_ERROR_CODE}, - params::{Id, Params, SubscriptionId as RpcSubscriptionId, TwoPointZero}, - request::Request, - response::{Response, SubscriptionPayload, SubscriptionResponse}, + error::{CALL_EXECUTION_FAILED_CODE, UNKNOWN_ERROR_CODE}, + ErrorCode, ErrorObject, Id, Params, Request, Response, SubscriptionId as RpcSubscriptionId, + SubscriptionPayload, SubscriptionResponse, TwoPointZero, }, }; diff --git a/ws-client/src/client.rs b/ws-client/src/client.rs index f169f76d7b..7200c0e034 100644 --- a/ws-client/src/client.rs +++ b/ws-client/src/client.rs @@ -27,14 +27,9 @@ use crate::transport::{Receiver as WsReceiver, Sender as WsSender, Target, WsTransportClientBuilder}; use crate::types::{ traits::{Client, SubscriptionClient}, - v2::{ - error::RpcError, - params::{Id, ParamsSer}, - request::{Notification, NotificationSer, RequestSer}, - response::Response, - }, - BatchMessage, Error, FrontToBack, RegisterNotificationMessage, RequestMessage, Subscription, SubscriptionMessage, - TEN_MB_SIZE_BYTES, + v2::{Id, Notification, NotificationSer, ParamsSer, RequestSer, Response, RpcError, SubscriptionResponse}, + BatchMessage, Error, FrontToBack, RegisterNotificationMessage, RequestMessage, Subscription, SubscriptionKind, + SubscriptionMessage, TEN_MB_SIZE_BYTES, }; use crate::{ helpers::{ @@ -51,10 +46,8 @@ use futures::{ prelude::*, sink::SinkExt, }; -use jsonrpsee_types::v2::response::SubscriptionResponse; use tokio::sync::Mutex; -use jsonrpsee_types::SubscriptionKind; use serde::de::DeserializeOwned; use std::{ borrow::Cow, diff --git a/ws-client/src/helpers.rs b/ws-client/src/helpers.rs index ce07b9ee33..d485c9dacd 100644 --- a/ws-client/src/helpers.rs +++ b/ws-client/src/helpers.rs @@ -27,10 +27,7 @@ use crate::manager::{RequestManager, RequestStatus}; use crate::transport::Sender as WsSender; use crate::types::v2::{ - error::RpcError, - params::{Id, ParamsSer, SubscriptionId}, - request::{Notification, RequestSer}, - response::{Response, SubscriptionResponse}, + Id, Notification, ParamsSer, RequestSer, Response, RpcError, SubscriptionId, SubscriptionResponse, }; use crate::types::{Error, RequestMessage}; use futures::channel::{mpsc, oneshot}; diff --git a/ws-client/src/manager.rs b/ws-client/src/manager.rs index 452784c760..126a2d51f0 100644 --- a/ws-client/src/manager.rs +++ b/ws-client/src/manager.rs @@ -32,7 +32,7 @@ //! > **Note**: The spec allow number, string or null but this crate only supports numbers. //! - SubscriptionId: unique ID generated by server -use crate::types::{v2::params::SubscriptionId, Error, JsonValue}; +use crate::types::{v2::SubscriptionId, Error, JsonValue}; use fnv::FnvHashMap; use futures::channel::{mpsc, oneshot}; use std::collections::hash_map::{Entry, HashMap}; @@ -308,7 +308,7 @@ impl RequestManager { mod tests { use super::{Error, RequestManager}; use futures::channel::{mpsc, oneshot}; - use jsonrpsee_types::v2::params::SubscriptionId; + use jsonrpsee_types::v2::SubscriptionId; use serde_json::Value as JsonValue; #[test] diff --git a/ws-client/src/tests.rs b/ws-client/src/tests.rs index 422db78061..2b9f74cbee 100644 --- a/ws-client/src/tests.rs +++ b/ws-client/src/tests.rs @@ -27,10 +27,7 @@ #![cfg(test)] use crate::types::{ traits::{Client, SubscriptionClient}, - v2::{ - error::{ErrorCode, ErrorObject, RpcError}, - params::ParamsSer, - }, + v2::{ErrorCode, ErrorObject, ParamsSer, RpcError}, Error, Subscription, }; use crate::WsClientBuilder; diff --git a/ws-server/src/server.rs b/ws-server/src/server.rs index 87b58f795d..89eea96133 100644 --- a/ws-server/src/server.rs +++ b/ws-server/src/server.rs @@ -30,7 +30,11 @@ use std::pin::Pin; use std::task::{Context, Poll}; use crate::future::{FutureDriver, StopHandle, StopMonitor}; -use crate::types::{error::Error, v2::error::ErrorCode, v2::params::Id, v2::request::Request, TEN_MB_SIZE_BYTES}; +use crate::types::{ + error::Error, + v2::{ErrorCode, Id, Request}, + TEN_MB_SIZE_BYTES, +}; use futures_channel::mpsc; use futures_util::io::{BufReader, BufWriter}; use futures_util::stream::StreamExt;