diff --git a/Cargo.toml b/Cargo.toml index 389e9f600ee..3e7cbe391f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] version = "0.1.0" edition = "2021" -rust-version = "1.75" +rust-version = "1.70" authors = ["Alloy Contributors"] license = "MIT OR Apache-2.0" homepage = "https://github.com/alloy-rs/next" diff --git a/crates/contract/src/call.rs b/crates/contract/src/call.rs index ef5e1b6ac0b..1028a77e21c 100644 --- a/crates/contract/src/call.rs +++ b/crates/contract/src/call.rs @@ -47,8 +47,8 @@ pub trait CallDecoder: private::Sealed { #[doc(hidden)] fn abi_decode_output(&self, data: Bytes, validate: bool) -> Result; - #[doc(hidden)] - fn as_debug_field(&self) -> impl std::fmt::Debug; + //#[doc(hidden)] + //fn as_debug_field(&self) -> impl std::fmt::Debug; } impl CallDecoder for Function { @@ -59,10 +59,10 @@ impl CallDecoder for Function { FunctionExt::abi_decode_output(self, &data, validate).map_err(Error::AbiError) } - #[inline] - fn as_debug_field(&self) -> impl std::fmt::Debug { - self - } + //#[inline] + //fn as_debug_field(&self) -> impl std::fmt::Debug { + // self + //} } impl CallDecoder for PhantomData { @@ -73,10 +73,10 @@ impl CallDecoder for PhantomData { C::abi_decode_returns(&data, validate).map_err(|e| Error::AbiError(e.into())) } - #[inline] - fn as_debug_field(&self) -> impl std::fmt::Debug { - std::any::type_name::() - } + //#[inline] + //fn as_debug_field(&self) -> impl std::fmt::Debug { + // std::any::type_name::() + //} } impl CallDecoder for () { @@ -87,10 +87,10 @@ impl CallDecoder for () { Ok(data) } - #[inline] - fn as_debug_field(&self) -> impl std::fmt::Debug { - format_args!("()") - } + //#[inline] + //fn as_debug_field(&self) -> impl std::fmt::Debug { + // format_args!("()") + //} } /// A builder for sending a transaction via `eth_sendTransaction`, or calling a contract via @@ -445,7 +445,7 @@ impl std::fmt::Debug for CallBuilder { .field("request", &self.request) .field("block", &self.block) .field("state", &self.state) - .field("decoder", &self.decoder.as_debug_field()) + //.field("decoder", &self.decoder.as_debug_field()) .finish() } } diff --git a/crates/pubsub/src/connect.rs b/crates/pubsub/src/connect.rs index 7c26355d604..5e74f08d9e0 100644 --- a/crates/pubsub/src/connect.rs +++ b/crates/pubsub/src/connect.rs @@ -1,5 +1,5 @@ use crate::{handle::ConnectionHandle, service::PubSubService, PubSubFrontend}; -use alloy_transport::{impl_future, TransportResult}; +use alloy_transport::{Pbf, TransportError}; /// Configuration objects that contain connection details for a backend. /// @@ -15,19 +15,19 @@ pub trait PubSubConnect: Sized + Send + Sync + 'static { /// [`ConnectionInterface`], and return the corresponding handle. /// /// [`ConnectionInterface`]: crate::ConnectionInterface - fn connect(&self) -> impl_future!(>); + fn connect<'a: 'b, 'b>(&'a self) -> Pbf<'b, ConnectionHandle, TransportError>; /// Attempt to reconnect the transport. /// /// Override this to add custom reconnection logic to your connector. This /// will be used by the internal pubsub connection managers in the event the /// connection fails. - fn try_reconnect(&self) -> impl_future!(>) { + fn try_reconnect<'a: 'b, 'b>(&'a self) -> Pbf<'b, ConnectionHandle, TransportError> { self.connect() } /// Convert the configuration object into a service with a running backend. - fn into_service(self) -> impl_future!(>) { - PubSubService::connect(self) + fn into_service(self) -> Pbf<'static, PubSubFrontend, TransportError> { + Box::pin(PubSubService::connect(self)) } } diff --git a/crates/pubsub/src/frontend.rs b/crates/pubsub/src/frontend.rs index 870cd1c7a1a..06477611404 100644 --- a/crates/pubsub/src/frontend.rs +++ b/crates/pubsub/src/frontend.rs @@ -1,7 +1,7 @@ use crate::{ix::PubSubInstruction, managers::InFlight, RawSubscription}; use alloy_json_rpc::{RequestPacket, Response, ResponsePacket, SerializedRequest}; use alloy_primitives::U256; -use alloy_transport::{TransportError, TransportErrorKind, TransportFut, TransportResult}; +use alloy_transport::{TransportError, TransportErrorKind, TransportFut}; use futures::{future::try_join_all, FutureExt, TryFutureExt}; use std::{ future::Future, @@ -31,7 +31,7 @@ impl PubSubFrontend { pub fn get_subscription( &self, id: U256, - ) -> impl Future> + Send + 'static { + ) -> impl Future> + Send + 'static { let backend_tx = self.tx.clone(); async move { let (tx, rx) = oneshot::channel(); @@ -43,7 +43,7 @@ impl PubSubFrontend { } /// Unsubscribe from a subscription. - pub fn unsubscribe(&self, id: U256) -> TransportResult<()> { + pub fn unsubscribe(&self, id: U256) -> Result<(), TransportError> { self.tx .send(PubSubInstruction::Unsubscribe(id)) .map_err(|_| TransportErrorKind::backend_gone()) @@ -53,7 +53,7 @@ impl PubSubFrontend { pub fn send( &self, req: SerializedRequest, - ) -> impl Future> + Send + 'static { + ) -> impl Future> + Send + 'static { let tx = self.tx.clone(); let channel_size = self.channel_size; diff --git a/crates/pubsub/src/managers/in_flight.rs b/crates/pubsub/src/managers/in_flight.rs index fe466f91ba2..6b405b35bc9 100644 --- a/crates/pubsub/src/managers/in_flight.rs +++ b/crates/pubsub/src/managers/in_flight.rs @@ -1,6 +1,6 @@ use alloy_json_rpc::{Response, ResponsePayload, SerializedRequest}; use alloy_primitives::U256; -use alloy_transport::{TransportError, TransportResult}; +use alloy_transport::TransportError; use std::fmt; use tokio::sync::oneshot; @@ -16,7 +16,7 @@ pub(crate) struct InFlight { pub(crate) channel_size: usize, /// The channel to send the response on. - pub(crate) tx: oneshot::Sender>, + pub(crate) tx: oneshot::Sender>, } impl fmt::Debug for InFlight { @@ -34,7 +34,7 @@ impl InFlight { pub(crate) fn new( request: SerializedRequest, channel_size: usize, - ) -> (Self, oneshot::Receiver>) { + ) -> (Self, oneshot::Receiver>) { let (tx, rx) = oneshot::channel(); (Self { request, channel_size, tx }, rx) diff --git a/crates/pubsub/src/service.rs b/crates/pubsub/src/service.rs index 84ae35b966b..96689a3bbcd 100644 --- a/crates/pubsub/src/service.rs +++ b/crates/pubsub/src/service.rs @@ -8,7 +8,7 @@ use alloy_json_rpc::{Id, PubSubItem, Request, Response, ResponsePayload}; use alloy_primitives::U256; use alloy_transport::{ utils::{to_json_raw_value, Spawnable}, - TransportErrorKind, TransportResult, + TransportError, TransportErrorKind, TransportResult, }; use serde_json::value::RawValue; use tokio::sync::{mpsc, oneshot}; @@ -35,7 +35,7 @@ pub(crate) struct PubSubService { impl PubSubService { /// Create a new service from a connector. - pub(crate) async fn connect(connector: T) -> TransportResult { + pub(crate) async fn connect(connector: T) -> Result { let handle = connector.connect().await?; let (tx, reqs) = mpsc::unbounded_channel(); @@ -51,7 +51,7 @@ impl PubSubService { } /// Reconnect by dropping the backend and creating a new one. - async fn get_new_backend(&mut self) -> TransportResult { + async fn get_new_backend(&mut self) -> Result { let mut handle = self.connector.try_reconnect().await?; std::mem::swap(&mut self.handle, &mut handle); Ok(handle) diff --git a/crates/rpc-client/src/batch.rs b/crates/rpc-client/src/batch.rs index 1f208266a9d..b9e6496de5f 100644 --- a/crates/rpc-client/src/batch.rs +++ b/crates/rpc-client/src/batch.rs @@ -104,7 +104,7 @@ impl<'a, T> BatchRequest<'a, T> { fn push( &mut self, request: Request, - ) -> TransportResult> { + ) -> Result, TransportError> { let ser = request.serialize().map_err(TransportError::ser_err)?; Ok(self.push_raw(ser).into()) } @@ -124,7 +124,7 @@ where &mut self, method: &'static str, params: &Params, - ) -> TransportResult> { + ) -> Result, TransportError> { let request = self.transport.make_request(method, Cow::Borrowed(params)); self.push(request) } @@ -242,7 +242,7 @@ impl Future for BatchFuture where T: Transport + Clone, { - type Output = TransportResult<()>; + type Output = Result<(), TransportError>; fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { if matches!(*self.as_mut(), BatchFuture::Prepared { .. }) { diff --git a/crates/rpc-client/src/builder.rs b/crates/rpc-client/src/builder.rs index 212915c7b18..0c5d962906c 100644 --- a/crates/rpc-client/src/builder.rs +++ b/crates/rpc-client/src/builder.rs @@ -1,6 +1,6 @@ use crate::RpcClient; use alloy_transport::{ - BoxTransport, BoxTransportConnect, Transport, TransportConnect, TransportResult, + BoxTransport, BoxTransportConnect, Transport, TransportConnect, TransportError, }; use tower::{ layer::util::{Identity, Stack}, @@ -77,7 +77,7 @@ impl ClientBuilder { /// Connect a pubsub transport, producing an [`RpcClient`] with the provided /// connection. #[cfg(feature = "pubsub")] - pub async fn pubsub(self, pubsub_connect: C) -> TransportResult> + pub async fn pubsub(self, pubsub_connect: C) -> Result, TransportError> where C: alloy_pubsub::PubSubConnect, L: Layer, @@ -94,7 +94,7 @@ impl ClientBuilder { pub async fn ws( self, ws_connect: alloy_transport_ws::WsConnect, - ) -> TransportResult> + ) -> Result, TransportError> where L: Layer, L::Service: Transport, @@ -104,7 +104,7 @@ impl ClientBuilder { /// Connect a transport, producing an [`RpcClient`] with the provided /// connection. - pub async fn connect(self, connect: C) -> TransportResult> + pub async fn connect(self, connect: C) -> Result, TransportError> where C: TransportConnect, L: Layer, @@ -116,7 +116,7 @@ impl ClientBuilder { /// Connect a transport, producing an [`RpcClient`] with a [`BoxTransport`] /// connection. - pub async fn connect_boxed(self, connect: C) -> TransportResult> + pub async fn connect_boxed(self, connect: C) -> Result, TransportError> where C: BoxTransportConnect, L: Layer, diff --git a/crates/rpc-client/src/client.rs b/crates/rpc-client/src/client.rs index be17d740a3b..14490f2fed1 100644 --- a/crates/rpc-client/src/client.rs +++ b/crates/rpc-client/src/client.rs @@ -220,7 +220,7 @@ mod pubsub_impl { impl RpcClient { /// Connect to a transport via a [`PubSubConnect`] implementor. - pub async fn connect_pubsub(connect: C) -> TransportResult> + pub async fn connect_pubsub(connect: C) -> Result, TransportError> where C: PubSubConnect, { diff --git a/crates/rpc-types/src/eth/transaction/request.rs b/crates/rpc-types/src/eth/transaction/request.rs index a15f125e548..fb1d81dec66 100644 --- a/crates/rpc-types/src/eth/transaction/request.rs +++ b/crates/rpc-types/src/eth/transaction/request.rs @@ -251,7 +251,7 @@ impl From> for TransactionInput { } /// Error thrown when both `data` and `input` fields are set and not equal. -#[derive(Debug, Default, thiserror::Error)] +#[derive(Clone, Copy, Debug, Default, thiserror::Error)] #[error("both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")] #[non_exhaustive] pub struct TransactionInputError; diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index 1371aa64dcf..69cb5cab11b 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -28,12 +28,18 @@ macro_rules! impl_connect { true } - async fn connect( - &self, - ) -> Result { - crate::IpcBackend::connect(&self.inner) - .await - .map_err(alloy_transport::TransportErrorKind::custom) + fn connect<'a: 'b, 'b>( + &'a self, + ) -> alloy_transport::Pbf< + 'b, + alloy_pubsub::ConnectionHandle, + alloy_transport::TransportError, + > { + Box::pin(async move { + crate::IpcBackend::connect(&self.inner) + .await + .map_err(alloy_transport::TransportErrorKind::custom) + }) } } }; diff --git a/crates/transport-ws/src/native.rs b/crates/transport-ws/src/native.rs index 8a71032245e..2e76396f4be 100644 --- a/crates/transport-ws/src/native.rs +++ b/crates/transport-ws/src/native.rs @@ -1,6 +1,6 @@ use crate::WsBackend; use alloy_pubsub::PubSubConnect; -use alloy_transport::{utils::Spawnable, Authorization, TransportErrorKind, TransportResult}; +use alloy_transport::{utils::Spawnable, Authorization, Pbf, TransportError, TransportErrorKind}; use futures::{SinkExt, StreamExt}; use serde_json::value::RawValue; use std::time::Duration; @@ -42,18 +42,20 @@ impl PubSubConnect for WsConnect { alloy_transport::utils::guess_local_url(&self.url) } - async fn connect(&self) -> TransportResult { + fn connect<'a: 'b, 'b>(&'a self) -> Pbf<'b, alloy_pubsub::ConnectionHandle, TransportError> { let request = self.clone().into_client_request(); - let req = request.map_err(TransportErrorKind::custom)?; - let (socket, _) = - tokio_tungstenite::connect_async(req).await.map_err(TransportErrorKind::custom)?; + Box::pin(async move { + let req = request.map_err(TransportErrorKind::custom)?; + let (socket, _) = + tokio_tungstenite::connect_async(req).await.map_err(TransportErrorKind::custom)?; - let (handle, interface) = alloy_pubsub::ConnectionHandle::new(); - let backend = WsBackend { socket, interface }; + let (handle, interface) = alloy_pubsub::ConnectionHandle::new(); + let backend = WsBackend { socket, interface }; - backend.spawn(); + backend.spawn(); - Ok(handle) + Ok(handle) + }) } } diff --git a/crates/transport-ws/src/wasm.rs b/crates/transport-ws/src/wasm.rs index 3789bbc7c97..964953d2159 100644 --- a/crates/transport-ws/src/wasm.rs +++ b/crates/transport-ws/src/wasm.rs @@ -1,6 +1,6 @@ use super::WsBackend; use alloy_pubsub::PubSubConnect; -use alloy_transport::{utils::Spawnable, TransportErrorKind, TransportResult}; +use alloy_transport::{utils::Spawnable, Pbf, TransportError, TransportErrorKind}; use futures::{ sink::SinkExt, stream::{Fuse, StreamExt}, @@ -20,16 +20,21 @@ impl PubSubConnect for WsConnect { alloy_transport::utils::guess_local_url(&self.url) } - async fn connect(&self) -> TransportResult { - let socket = - WsMeta::connect(&self.url, None).await.map_err(TransportErrorKind::custom)?.1.fuse(); + fn connect<'a: 'b, 'b>(&'a self) -> Pbf<'b, alloy_pubsub::ConnectionHandle, TransportError> { + Box::pin(async move { + let socket = WsMeta::connect(&self.url, None) + .await + .map_err(TransportErrorKind::custom)? + .1 + .fuse(); - let (handle, interface) = alloy_pubsub::ConnectionHandle::new(); - let backend = WsBackend { socket, interface }; + let (handle, interface) = alloy_pubsub::ConnectionHandle::new(); + let backend = WsBackend { socket, interface }; - backend.spawn(); + backend.spawn(); - Ok(handle) + Ok(handle) + }) } } diff --git a/crates/transport/Cargo.toml b/crates/transport/Cargo.toml index 2ace36ba033..85a06b3e992 100644 --- a/crates/transport/Cargo.toml +++ b/crates/transport/Cargo.toml @@ -15,7 +15,6 @@ exclude.workspace = true alloy-json-rpc.workspace = true base64.workspace = true -futures-util.workspace = true serde_json = { workspace = true, features = ["raw_value"] } serde.workspace = true thiserror.workspace = true diff --git a/crates/transport/src/connect.rs b/crates/transport/src/connect.rs index cbf761c0f53..fc4f8fdc281 100644 --- a/crates/transport/src/connect.rs +++ b/crates/transport/src/connect.rs @@ -1,5 +1,4 @@ use crate::{BoxTransport, Pbf, Transport, TransportError}; -use futures_util::TryFutureExt; /// Connection details for a transport. /// @@ -42,15 +41,23 @@ pub trait BoxTransportConnect { fn get_boxed_transport<'a: 'b, 'b>(&'a self) -> Pbf<'b, BoxTransport, TransportError>; } -impl BoxTransportConnect for T { +impl BoxTransportConnect for T +where + T: TransportConnect, +{ fn is_local(&self) -> bool { TransportConnect::is_local(self) } fn get_boxed_transport<'a: 'b, 'b>(&'a self) -> Pbf<'b, BoxTransport, TransportError> { - Box::pin(self.get_transport().map_ok(Transport::boxed)) + Box::pin(async move { self.get_transport().await.map(Transport::boxed) }) } } #[cfg(test)] -fn _object_safe(_: Box) {} +mod test { + use super::*; + fn __compile_check(_: Box) { + todo!() + } +} diff --git a/crates/transport/src/lib.rs b/crates/transport/src/lib.rs index 9db9bed1a62..b57c1c21477 100644 --- a/crates/transport/src/lib.rs +++ b/crates/transport/src/lib.rs @@ -55,14 +55,6 @@ mod type_aliases { /// Future for RPC-level requests. pub type RpcFut<'a, T> = std::pin::Pin> + Send + 'a>>; - - /// `impl Future` with a `Send` bound. - #[macro_export] - macro_rules! impl_future { - (<$($t:tt)+) => { - impl (::core::future::Future<$($t)+) + Send - }; - } } #[cfg(target_arch = "wasm32")] @@ -81,12 +73,4 @@ mod type_aliases { /// Future for RPC-level requests. pub type RpcFut<'a, T> = std::pin::Pin> + 'a>>; - - /// `impl Future` without a `Send` bound. - #[macro_export] - macro_rules! impl_future { - (<$($t:tt)+) => { - impl ::core::future::Future<$($t)+ - }; - } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000000..7793bb30229 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "1.70" +components = ["clippy", "rustfmt", "rust-src"] +targets = ["wasm32-unknown-unknown"] +profile = "minimal"