Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crate restructuring #590

Merged
merged 28 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cb3e37d
Nuke V2
maciejhirsz Dec 5, 2021
09ceb90
fmt
maciejhirsz Dec 5, 2021
714ce5d
Formatting and imports
maciejhirsz Dec 9, 2021
4d79729
Merge branch 'master' of github.com:paritytech/jsonrpsee into mh-cleanup
maciejhirsz Dec 9, 2021
22dd3a7
Updated benches
maciejhirsz Dec 9, 2021
6bb0224
Fix doc comment link
maciejhirsz Dec 9, 2021
bc22ac2
Brace imports in ws-server
maciejhirsz Dec 9, 2021
392daa7
Reworking imports
maciejhirsz Dec 10, 2021
a9c37fa
Merge branch 'master' of github.com:paritytech/jsonrpsee into mh-cleanup
maciejhirsz Dec 10, 2021
57bdf5a
std first
maciejhirsz Dec 10, 2021
e24f12d
fmt
maciejhirsz Dec 10, 2021
e59732f
std on top
maciejhirsz Dec 10, 2021
4f32c88
Update to match changed line numbers
maciejhirsz Dec 10, 2021
3ec6e62
Merge branch 'master' of github.com:paritytech/jsonrpsee into mh-cleanup
maciejhirsz Dec 13, 2021
f2f5315
Rename jsonrpsee_utils -> jsonrpsee_core
maciejhirsz Dec 14, 2021
e29bdec
Migrating things types -> core
maciejhirsz Dec 14, 2021
faa0da1
RpcError -> ErrorResponse
maciejhirsz Dec 14, 2021
a9567f0
Merge types::client into core::client
maciejhirsz Dec 14, 2021
f914dca
Continued move types -> core
maciejhirsz Dec 15, 2021
6c15874
Removing features to make checks pass
maciejhirsz Dec 15, 2021
7ed2316
Move rpc_module tests to tests crate
maciejhirsz Dec 16, 2021
1d09ee4
Merge branch 'master' of github.com:paritytech/jsonrpsee into mh-cleanup
maciejhirsz Dec 16, 2021
dc4ab02
Fixed doc comment links
maciejhirsz Dec 16, 2021
394a3c2
Add futures-util dependency for client
maciejhirsz Dec 16, 2021
c38ec76
Remove dead code
maciejhirsz Dec 16, 2021
e93c2d9
fmt
maciejhirsz Dec 16, 2021
51eec24
Feature gate the Client trait
maciejhirsz Dec 17, 2021
9a88c70
Move `Client` traits to `client` module
maciejhirsz Dec 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions http-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use crate::transport::HttpTransportClient;
use crate::types::{
traits::{Client, SubscriptionClient},
v2::{Id, NotificationSer, ParamsSer, RequestSer, Response, RpcError},
CertificateStore, Error, RequestIdManager, Subscription, TEN_MB_SIZE_BYTES,
CertificateStore, Error, Id, NotificationSer, ParamsSer, RequestIdManager, RequestSer, Response, RpcError,
Subscription, TEN_MB_SIZE_BYTES,
};
use async_trait::async_trait;
use fnv::FnvHashMap;
Expand Down
4 changes: 2 additions & 2 deletions http-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// DEALINGS IN THE SOFTWARE.

use crate::types::{
error::{Error, ErrorCode, ErrorObject, RpcError},
traits::Client,
v2::{ErrorCode, ErrorObject, ParamsSer, RpcError},
Error, JsonValue,
JsonValue, ParamsSer,
};
use crate::HttpClientBuilder;
use jsonrpsee_test_utils::helpers::*;
Expand Down
3 changes: 2 additions & 1 deletion http-server/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

//! Contains common builders for hyper responses.

use crate::types::v2::{ErrorCode, Id, RpcError, TwoPointZero};
use crate::types::error::{ErrorCode, RpcError};
use crate::types::{Id, TwoPointZero};

const JSON: &str = "application/json; charset=utf-8";
const TEXT: &str = "text/plain";
Expand Down
5 changes: 2 additions & 3 deletions http-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ use hyper::{
Error as HyperError,
};
use jsonrpsee_types::{
error::{Error, GenericTransportError},
error::{Error, ErrorCode, GenericTransportError},
middleware::Middleware,
v2::{ErrorCode, Id, Notification, Request},
TEN_MB_SIZE_BYTES,
Id, Notification, Request, TEN_MB_SIZE_BYTES,
};
use jsonrpsee_utils::http_helpers::read_body;
use jsonrpsee_utils::server::{
Expand Down
8 changes: 4 additions & 4 deletions proc-macros/src/render_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ impl RpcDescription {
quote! { (#param, #value) }
});
quote! {
Some(types::v2::ParamsSer::Map(
std::collections::BTreeMap::<&str, #serde_json::Value>::from(
[#(#params),*]
)
Some(types::ParamsSer::Map(
std::collections::BTreeMap::<&str, #serde_json::Value>::from(
[#(#params),*]
)
)
)
}
}
ParamKind::Array => {
Expand Down
2 changes: 1 addition & 1 deletion types/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::{error::SubscriptionClosedError, v2::SubscriptionId, Error};
use crate::{error::SubscriptionClosedError, Error, SubscriptionId};
use core::marker::PhantomData;
use futures_channel::{mpsc, oneshot};
use futures_util::{future::FutureExt, sink::SinkExt, stream::StreamExt};
Expand Down
File renamed without changes.
18 changes: 7 additions & 11 deletions types/src/v2/mod.rs → types/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@
// DEALINGS IN THE SOFTWARE.

//! Types to handle in- and outgoing JSON-RPC requests and subscriptions according to the [spec](https://www.jsonrpc.org/specification).
/// Error type.

/// Main `Error` type.
mod error;

/// JSON-RPC error related types.
pub mod error;
/// JSON_RPC params related types.
pub mod params;
/// JSON-RPC request object related types
pub mod request;
/// JSON-RPC response object related types.
pub mod response;
pub mod rpc;

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};
pub use error::{CallError, Error, GenericTransportError, SubscriptionClosedError};
pub use rpc::{ErrorCode, ErrorObject, RpcError};
2 changes: 1 addition & 1 deletion types/src/v2/error.rs → types/src/error/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::v2::params::{Id, TwoPointZero};
use crate::params::{Id, TwoPointZero};
use beef::Cow;
use serde::de::Deserializer;
use serde::ser::Serializer;
Expand Down
18 changes: 14 additions & 4 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ extern crate alloc;
/// Ten megabytes.
pub const TEN_MB_SIZE_BYTES: u32 = 10 * 1024 * 1024;

/// JSON-RPC v2.0 specification related types.
pub mod v2;

/// Error type.
pub mod error;

Expand All @@ -49,10 +46,20 @@ pub mod traits;
/// Middleware trait and implementation.
pub mod middleware;

/// JSON_RPC params related types.
maciejhirsz marked this conversation as resolved.
Show resolved Hide resolved
pub mod params;

/// JSON-RPC request object related types
pub mod request;

/// JSON-RPC response object related types.
pub mod response;

pub use async_trait::async_trait;
pub use beef::Cow;
pub use client::*;
pub use error::{CallError, Error};
pub use error::{CallError, Error, RpcError};
pub use params::{Id, Params, ParamsSequence, ParamsSer, SubscriptionId, TwoPointZero};
pub use serde::{de::DeserializeOwned, Serialize};
pub use serde_json::{
to_value as to_json_value, value::to_raw_value as to_json_raw_value, value::RawValue as JsonRawValue,
Expand All @@ -70,3 +77,6 @@ pub mod __reexports {

/// JSON-RPC result.
pub type RpcResult<T> = std::result::Result<T, Error>;

pub use request::{InvalidRequest, Notification, NotificationSer, Request, RequestSer};
pub use response::{Response, SubscriptionPayload, SubscriptionResponse};
6 changes: 3 additions & 3 deletions types/src/v2/params.rs → types/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a> ParamsSequence<'a> {
/// Parse the next parameter to type `T`
///
/// ```
/// # use jsonrpsee_types::v2::params::Params;
/// # use jsonrpsee_types::params::Params;
/// let params = Params::new(Some(r#"[true, 10, "foo"]"#));
/// let mut seq = params.sequence();
///
Expand All @@ -226,7 +226,7 @@ impl<'a> ParamsSequence<'a> {
/// The result will be `None` for `null`, and for missing values in the supplied JSON array.
///
/// ```
/// # use jsonrpsee_types::v2::params::Params;
/// # use jsonrpsee_types::params::Params;
/// let params = Params::new(Some(r#"[1, 2, null]"#));
/// let mut seq = params.sequence();
///
Expand Down Expand Up @@ -358,7 +358,7 @@ impl<'a> Id<'a> {
#[cfg(test)]
mod test {
use super::{Cow, Id, JsonValue, Params, ParamsSer, SubscriptionId, TwoPointZero};
use crate::v2::response::SubscriptionPayload;
use crate::response::SubscriptionPayload;

#[test]
fn id_deserialization() {
Expand Down
2 changes: 1 addition & 1 deletion types/src/v2/request.rs → types/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! Types to handle JSON-RPC requests according to the [spec](https://www.jsonrpc.org/specification#request-object).
//! Some types come with a "*Ser" variant that implements [`serde::Serialize`]; these are used in the client.

use crate::v2::params::{Id, ParamsSer, TwoPointZero};
use crate::params::{Id, ParamsSer, TwoPointZero};
use beef::Cow;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
Expand Down
6 changes: 2 additions & 4 deletions types/src/v2/response.rs → types/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

//! Types pertaining to JSON-RPC responses.

use crate::v2::{
params::{Id, SubscriptionId, TwoPointZero},
request::Notification,
};
use crate::params::{Id, SubscriptionId, TwoPointZero};
use crate::request::Notification;
use serde::{Deserialize, Serialize};

/// JSON-RPC successful response object as defined in the [spec](https://www.jsonrpc.org/specification#response_object).
Expand Down
2 changes: 1 addition & 1 deletion types/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::v2::ParamsSer;
use crate::ParamsSer;
use crate::{Error, Subscription};
use async_trait::async_trait;
use serde::de::DeserializeOwned;
Expand Down
2 changes: 1 addition & 1 deletion utils/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#[doc(hidden)]
pub mod __reexports {
pub use jsonrpsee_types::{to_json_value, v2::ParamsSer};
pub use jsonrpsee_types::{to_json_value, ParamsSer};
}

#[macro_export]
Expand Down
12 changes: 5 additions & 7 deletions utils/src/server/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

use futures_channel::mpsc;
use futures_util::stream::StreamExt;
use jsonrpsee_types::error::{CallError, Error};
use jsonrpsee_types::to_json_raw_value;
use jsonrpsee_types::v2::error::{OVERSIZED_RESPONSE_CODE, OVERSIZED_RESPONSE_MSG};
use jsonrpsee_types::v2::{
error::{CALL_EXECUTION_FAILED_CODE, UNKNOWN_ERROR_CODE},
ErrorCode, ErrorObject, Id, InvalidRequest, Response, RpcError, TwoPointZero,
};
use jsonrpsee_types::error::rpc::{CALL_EXECUTION_FAILED_CODE, UNKNOWN_ERROR_CODE};
use jsonrpsee_types::error::rpc::{OVERSIZED_RESPONSE_CODE, OVERSIZED_RESPONSE_MSG};
use jsonrpsee_types::error::{CallError, Error, ErrorCode, ErrorObject, RpcError};
use jsonrpsee_types::{to_json_raw_value, Id, TwoPointZero};
use jsonrpsee_types::{InvalidRequest, Response};
maciejhirsz marked this conversation as resolved.
Show resolved Hide resolved
use serde::Serialize;

use std::io;
Expand Down
18 changes: 7 additions & 11 deletions utils/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ use crate::server::resource_limiting::{ResourceGuard, ResourceTable, ResourceVec
use beef::Cow;
use futures_channel::{mpsc, oneshot};
use futures_util::{future::BoxFuture, FutureExt, StreamExt};
use jsonrpsee_types::error::rpc::{invalid_subscription_err, CALL_EXECUTION_FAILED_CODE};
use jsonrpsee_types::to_json_raw_value;
use jsonrpsee_types::v2::error::{invalid_subscription_err, CALL_EXECUTION_FAILED_CODE};
use jsonrpsee_types::{
error::{Error, SubscriptionClosedError},
error::{Error, ErrorCode, SubscriptionClosedError},
traits::ToRpcParams,
v2::{
ErrorCode, Id, Params, Request, Response, SubscriptionId as RpcSubscriptionId, SubscriptionPayload,
SubscriptionResponse, TwoPointZero,
},
DeserializeOwned,
DeserializeOwned, Id, Params, Request, Response, SubscriptionId as RpcSubscriptionId, SubscriptionPayload,
SubscriptionResponse, TwoPointZero,
};

use parking_lot::Mutex;
Expand Down Expand Up @@ -782,7 +779,7 @@ impl TestSubscription {
/// # Panics
///
/// If the decoding the value as `T` fails.
pub async fn next<T: DeserializeOwned>(&mut self) -> Option<(T, jsonrpsee_types::v2::SubscriptionId)> {
pub async fn next<T: DeserializeOwned>(&mut self) -> Option<(T, RpcSubscriptionId)> {
let raw = self.rx.next().await?;
let val: SubscriptionResponse<T> =
serde_json::from_str(&raw).expect("valid response in TestSubscription::next()");
Expand All @@ -799,7 +796,6 @@ impl Drop for TestSubscription {
#[cfg(test)]
mod tests {
use super::*;
use jsonrpsee_types::v2;
use serde::Deserialize;
use std::collections::HashMap;

Expand Down Expand Up @@ -980,7 +976,7 @@ mod tests {
for i in (0..=2).rev() {
let (val, id) = my_sub.next::<char>().await.unwrap();
assert_eq!(val, std::char::from_digit(i, 10).unwrap());
assert_eq!(id, v2::params::SubscriptionId::Num(my_sub.subscription_id()));
assert_eq!(id, RpcSubscriptionId::Num(my_sub.subscription_id()));
}

// The subscription is now closed by the server.
Expand All @@ -1007,7 +1003,7 @@ mod tests {
let mut my_sub: TestSubscription = module.test_subscription("my_sub", Vec::<()>::new()).await;
let (val, id) = my_sub.next::<String>().await.unwrap();
assert_eq!(&val, "lo");
assert_eq!(id, v2::params::SubscriptionId::Num(my_sub.subscription_id()));
assert_eq!(id, RpcSubscriptionId::Num(my_sub.subscription_id()));

// close the subscription to ensure it doesn't return any items.
my_sub.close();
Expand Down
6 changes: 3 additions & 3 deletions ws-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
use crate::transport::{Receiver as WsReceiver, Sender as WsSender, WsHandshakeError, WsTransportClientBuilder};
use crate::types::{
traits::{Client, SubscriptionClient},
v2::{Id, Notification, NotificationSer, ParamsSer, RequestSer, Response, RpcError, SubscriptionResponse},
BatchMessage, CertificateStore, Error, FrontToBack, RegisterNotificationMessage, RequestIdManager, RequestMessage,
Subscription, SubscriptionKind, SubscriptionMessage, TEN_MB_SIZE_BYTES,
BatchMessage, CertificateStore, Error, FrontToBack, Id, Notification, NotificationSer, ParamsSer,
RegisterNotificationMessage, RequestIdManager, RequestMessage, RequestSer, Response, RpcError, Subscription,
SubscriptionKind, SubscriptionMessage, SubscriptionResponse, TEN_MB_SIZE_BYTES,
};
use crate::{
helpers::{
Expand Down
7 changes: 3 additions & 4 deletions ws-client/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

use crate::manager::{RequestManager, RequestStatus};
use crate::transport::Sender as WsSender;
use crate::types::v2::{
Id, Notification, ParamsSer, RequestSer, Response, RpcError, SubscriptionId, SubscriptionResponse,
};
use crate::types::{Error, RequestMessage};
use crate::types::{Error, RequestMessage, RpcError};
use crate::types::{Id, ParamsSer, SubscriptionId};
use crate::types::{Notification, RequestSer, Response, SubscriptionResponse};
use futures::channel::{mpsc, oneshot};
use serde_json::Value as JsonValue;
use std::time::Duration;
Expand Down
4 changes: 2 additions & 2 deletions ws-client/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::SubscriptionId, Error, JsonValue};
use crate::types::{Error, JsonValue, SubscriptionId};
use fnv::FnvHashMap;
use futures::channel::{mpsc, oneshot};
use std::collections::hash_map::{Entry, HashMap};
Expand Down Expand Up @@ -308,7 +308,7 @@ impl RequestManager {
mod tests {
use super::{Error, RequestManager};
use futures::channel::{mpsc, oneshot};
use jsonrpsee_types::v2::SubscriptionId;
use jsonrpsee_types::SubscriptionId;
use serde_json::Value as JsonValue;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions ws-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

#![cfg(test)]
use crate::types::{
error::{Error, ErrorCode, ErrorObject, RpcError},
traits::{Client, SubscriptionClient},
v2::{ErrorCode, ErrorObject, ParamsSer, RpcError},
Error, Subscription,
ParamsSer, Subscription,
};
use crate::WsClientBuilder;
use jsonrpsee_test_utils::helpers::*;
Expand Down
8 changes: 2 additions & 6 deletions ws-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use crate::future::{FutureDriver, ServerHandle, StopMonitor};
use crate::types::{
error::Error,
middleware::Middleware,
v2::{ErrorCode, Id, Request},
TEN_MB_SIZE_BYTES,
};
use crate::types::error::{Error, ErrorCode};
use crate::types::{middleware::Middleware, Id, Request, TEN_MB_SIZE_BYTES};
use futures_channel::mpsc;
use futures_util::future::join_all;
use futures_util::future::FutureExt;
Expand Down
8 changes: 4 additions & 4 deletions ws-server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
#![cfg(test)]

use crate::types::error::{CallError, Error};
use crate::types::v2::{self, Response, RpcError};
use crate::types::DeserializeOwned;
use crate::types::{self, Response, RpcError};
use crate::{future::ServerHandle, RpcModule, WsServerBuilder};
use anyhow::anyhow;
use futures_util::future::join;
use jsonrpsee_test_utils::helpers::*;
use jsonrpsee_test_utils::mocks::{Id, TestContext, WebSocketTestClient, WebSocketTestError};
use jsonrpsee_test_utils::TimeoutFutureExt;
use jsonrpsee_types::error::rpc::invalid_subscription_err;
use jsonrpsee_types::to_json_raw_value;
use jsonrpsee_types::v2::error::invalid_subscription_err;
use serde_json::Value as JsonValue;
use std::{fmt, net::SocketAddr, time::Duration};
use tracing_subscriber::{EnvFilter, FmtSubscriber};
Expand Down Expand Up @@ -611,7 +611,7 @@ async fn unsubscribe_twice_should_indicate_error() {
let sub_id = to_json_raw_value(&sub_id).unwrap();

let err = Some(to_json_raw_value(&format!("Invalid subscription ID={}", sub_id)).unwrap());
assert_eq!(unsub_2_err, RpcError::new(invalid_subscription_err(err.as_deref()), v2::Id::Number(2)));
assert_eq!(unsub_2_err, RpcError::new(invalid_subscription_err(err.as_deref()), types::Id::Number(2)));
}

#[tokio::test]
Expand All @@ -624,5 +624,5 @@ async fn unsubscribe_wrong_sub_id_type() {
client.send_request_text(call("unsubscribe_hello", vec!["string_is_not_supported"], Id::Num(0))).await.unwrap();
let unsub_2_err: RpcError = serde_json::from_str(&unsub).unwrap();
let err = Some(to_json_raw_value(&"Invalid subscription ID type, must be integer").unwrap());
assert_eq!(unsub_2_err, RpcError::new(invalid_subscription_err(err.as_deref()), v2::Id::Number(0)));
assert_eq!(unsub_2_err, RpcError::new(invalid_subscription_err(err.as_deref()), types::Id::Number(0)));
}