From b36dccbbafbdf3357d1bc67b18671adea30611b0 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:45:36 +0100 Subject: [PATCH] chore(deps): bump hyper to 1.0 --- Cargo.toml | 28 ++++++++++++++++++----- crates/rpc-client/Cargo.toml | 6 ++++- crates/rpc-client/src/builder.rs | 17 ++++++++++---- crates/transport-http/Cargo.toml | 6 +++-- crates/transport-http/src/hyper.rs | 33 +++++++++++++++------------- crates/transport-http/src/reqwest.rs | 6 ++--- 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa6b1bf6772..597c89e4729 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,22 +26,38 @@ alloy-networks = { version = "0.1.0", path = "crates/networks" } alloy-rpc-types = { version = "0.1.0", path = "crates/rpc-types" } alloy-rpc-client = { version = "0.1.0", path = "crates/rpc-client" } -alloy-primitives = { version = "0.5.1", features = ["serde"] } +alloy-primitives = { version = "0.5.1", default-features = false, features = ["std"] } +alloy-sol-types = { version = "0.5.1", default-features = false, features = ["std"] } alloy-rlp = "0.3" +# async async-trait = "0.1.74" +futures = "0.3.29" +futures-util = "0.3.29" +futures-executor = "0.3.29" + +http-body-util = "0.1.0" +hyper = { version = "1.0", default-features = false } +hyper-util = "0.1.1" +tokio = "1.33" +tower = { version = "0.4.13", default-features = false, features = ["util"] } + +tracing = "0.1.40" +tracing-subscriber = "0.3.18" + +tempfile = "3.8" + +assert_matches = "1.5" base64 = "0.21" bimap = "0.6" -futures = "0.3.29" -hyper = "0.14.27" itertools = "0.12" pin-project = "1.1" +rand = "0.8.5" reqwest = "0.11.18" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_with = "3.4" +home = "0.5" +semver = "1.0" thiserror = "1.0" -tokio = { version = "1.33", features = ["sync", "macros"] } -tower = { version = "0.4.13", features = ["util"] } -tracing = "0.1.40" url = "2.4" diff --git a/crates/rpc-client/Cargo.toml b/crates/rpc-client/Cargo.toml index cbac62f8111..6f6765087a6 100644 --- a/crates/rpc-client/Cargo.toml +++ b/crates/rpc-client/Cargo.toml @@ -25,8 +25,12 @@ tracing.workspace = true alloy-primitives = { workspace = true, optional = true } alloy-pubsub = { workspace = true, optional = true } alloy-transport-ws = { workspace = true, optional = true } -hyper = { workspace = true, optional = true } + reqwest = { workspace = true, optional = true } + +hyper = { workspace = true, optional = true } +hyper-util = { workspace = true, optional = true } + tokio = { workspace = true, optional = true } url = { workspace = true, optional = true } diff --git a/crates/rpc-client/src/builder.rs b/crates/rpc-client/src/builder.rs index f6870ee6fe4..7573675bb42 100644 --- a/crates/rpc-client/src/builder.rs +++ b/crates/rpc-client/src/builder.rs @@ -65,13 +65,22 @@ impl ClientBuilder { #[cfg(all(not(target_arch = "wasm32"), feature = "hyper"))] pub fn hyper_http(self, url: url::Url) -> RpcClient where - L: Layer>>, + L: Layer< + alloy_transport_http::Http< + hyper_util::client::legacy::Client< + hyper_util::client::legacy::connect::HttpConnector, + hyper::body::Bytes, + >, + >, + >, L::Service: Transport, { - let transport = alloy_transport_http::Http::new(url); - let is_local = transport.guess_local(); + let _ = url; + todo!() + // let transport = alloy_transport_http::Http::new(url); + // let is_local = transport.guess_local(); - self.transport(transport, is_local) + // self.transport(transport, is_local) } #[cfg(feature = "pubsub")] diff --git a/crates/transport-http/Cargo.toml b/crates/transport-http/Cargo.toml index 0a03f2bdfab..ccd868a3ad2 100644 --- a/crates/transport-http/Cargo.toml +++ b/crates/transport-http/Cargo.toml @@ -22,9 +22,11 @@ tower.workspace = true reqwest = { workspace = true, features = ["serde_json", "json"], optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -hyper = { workspace = true, features = ["full"], optional = true } +http-body-util = { workspace = true, optional = true } +hyper = { workspace = true, default-features = false, optional = true } +hyper-util = { workspace = true, features = ["full"], optional = true } [features] default = ["reqwest"] reqwest = ["dep:reqwest"] -hyper = ["dep:hyper"] +hyper = ["dep:hyper", "dep:hyper-util"] diff --git a/crates/transport-http/src/hyper.rs b/crates/transport-http/src/hyper.rs index 6b51c94be9f..b634014110a 100644 --- a/crates/transport-http/src/hyper.rs +++ b/crates/transport-http/src/hyper.rs @@ -1,39 +1,40 @@ use crate::Http; use alloy_json_rpc::{RequestPacket, ResponsePacket}; use alloy_transport::{TransportError, TransportErrorKind, TransportFut}; +use http_body_util::{BodyExt, Full}; use hyper::{ - body::Bytes, - client::{connect::Connect, Client}, + body::{Buf, Bytes}, + header, }; +use hyper_util::client::legacy::{connect::Connect, Client}; use std::task; use tower::Service; -impl Http> +impl Http>> where C: Connect + Clone + Send + Sync + 'static, + B: From + Buf + Send + 'static, { /// Make a request. - fn request(&self, req: RequestPacket) -> TransportFut<'static> { + fn request_hyper(&self, req: RequestPacket) -> TransportFut<'static> { let this = self.clone(); Box::pin(async move { let ser = req.serialize().map_err(TransportError::ser_err)?; // convert the Box into a hyper request - let body: Box = ser.into(); - let body: Box<[u8]> = body.into(); + let body = Full::from(Bytes::from(>::from(>::from(ser)))); let req = hyper::Request::builder() .method(hyper::Method::POST) .uri(this.url.as_str()) - .header("content-type", "application/json") - .body(hyper::Body::from(Bytes::from(body))) + .header(header::CONTENT_TYPE, header::HeaderValue::from_static("application/json")) + .body(body) .expect("request parts are valid"); let resp = this.client.request(req).await.map_err(TransportErrorKind::custom)?; // unpack json from the response body - let body = hyper::body::to_bytes(resp.into_body()) - .await - .map_err(TransportErrorKind::custom)?; + let body = + resp.into_body().collect().await.map_err(TransportErrorKind::custom)?.to_bytes(); // Deser a Box from the body. If deser fails, return the // body as a string in the error. If the body is not UTF8, this will @@ -45,9 +46,10 @@ where } } -impl Service for &Http> +impl Service for &Http>> where C: Connect + Clone + Send + Sync + 'static, + B: From + Buf + Send + 'static, { type Response = ResponsePacket; type Error = TransportError; @@ -61,13 +63,14 @@ where #[inline] fn call(&mut self, req: RequestPacket) -> Self::Future { - self.request(req) + self.request_hyper(req) } } -impl Service for Http> +impl Service for Http>> where C: Connect + Clone + Send + Sync + 'static, + B: From + Buf + Send + 'static, { type Response = ResponsePacket; type Error = TransportError; @@ -81,6 +84,6 @@ where #[inline] fn call(&mut self, req: RequestPacket) -> Self::Future { - self.request(req) + self.request_hyper(req) } } diff --git a/crates/transport-http/src/reqwest.rs b/crates/transport-http/src/reqwest.rs index a5fbc3b484d..cb2844a9c27 100644 --- a/crates/transport-http/src/reqwest.rs +++ b/crates/transport-http/src/reqwest.rs @@ -6,7 +6,7 @@ use tower::Service; impl Http { /// Make a request. - fn request(&self, req: RequestPacket) -> TransportFut<'static> { + fn request_reqwest(&self, req: RequestPacket) -> TransportFut<'static> { let this = self.clone(); Box::pin(async move { let resp = this @@ -36,7 +36,7 @@ impl Service for Http { #[inline] fn call(&mut self, req: RequestPacket) -> Self::Future { - self.request(req) + self.request_reqwest(req) } } @@ -53,6 +53,6 @@ impl Service for &Http { #[inline] fn call(&mut self, req: RequestPacket) -> Self::Future { - self.request(req) + self.request_reqwest(req) } }