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

Redo http transport #497

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pin-project = "1.0"
## HTTP
base64 = { version = "0.13", optional = true }
bytes = { version = "1.0", optional = true }
reqwest = { version = "0.11", optional = true, default-features = false }
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
headers = { version = "0.3", optional = true }
## WS
# async-native-tls = { git = "https://github.com/async-email/async-native-tls.git", rev = "b5b5562d6cea77f913d4cbe448058c031833bf17", optional = true, default-features = false }
Expand Down
16 changes: 12 additions & 4 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use futures::{
Future,
};
use pin_project::pin_project;
use serde::de::DeserializeOwned;
use std::{marker::PhantomData, pin::Pin};

/// Takes any type which is deserializable from rpc::Value and such a value and
Expand Down Expand Up @@ -70,12 +71,19 @@ pub fn build_request(id: usize, method: &str, params: Vec<rpc::Value>) -> rpc::C
/// Parse bytes slice into JSON-RPC response.
/// It looks for arbitrary_precision feature as a temporary workaround for https://github.com/tomusdrw/rust-web3/issues/460.
pub fn to_response_from_slice(response: &[u8]) -> error::Result<rpc::Response> {
arbitrary_precision_deserialize_workaround(response).map_err(|e| Error::InvalidResponse(format!("{:?}", e)))
}

/// Deserialize bytes into T.
/// It looks for arbitrary_precision feature as a temporary workaround for https://github.com/tomusdrw/rust-web3/issues/460.
pub fn arbitrary_precision_deserialize_workaround<T>(bytes: &[u8]) -> Result<T, serde_json::Error>
where
T: DeserializeOwned,
{
if cfg!(feature = "arbitrary_precision") {
let val: serde_json::Value =
serde_json::from_slice(response).map_err(|e| Error::InvalidResponse(format!("{:?}", e)))?;
serde_json::from_value(val).map_err(|e| Error::InvalidResponse(format!("{:?}", e)))
serde_json::from_value(serde_json::from_slice(bytes)?)
} else {
serde_json::from_slice(response).map_err(|e| Error::InvalidResponse(format!("{:?}", e)))
serde_json::from_slice(bytes)
}
}

Expand Down
Loading