Skip to content

Commit

Permalink
Allow compiling with 170
Browse files Browse the repository at this point in the history
Mainly just reverts alloy-rs#218
  • Loading branch information
Brechtpd committed Mar 5, 2024
1 parent 975a52a commit 8ed5684
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub trait CallDecoder: private::Sealed {
#[doc(hidden)]
fn abi_decode_output(&self, data: Bytes, validate: bool) -> Result<Self::CallOutput>;

#[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 {
Expand All @@ -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<C: SolCall> CallDecoder for PhantomData<C> {
Expand All @@ -73,10 +73,10 @@ impl<C: SolCall> CallDecoder for PhantomData<C> {
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::<C>()
}
//#[inline]
//fn as_debug_field(&self) -> impl std::fmt::Debug {
// std::any::type_name::<C>()
//}
}

impl CallDecoder for () {
Expand All @@ -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
Expand Down Expand Up @@ -445,7 +445,7 @@ impl<P, D: CallDecoder> std::fmt::Debug for CallBuilder<P, D> {
.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()
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/pubsub/src/connect.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -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!(<Output = TransportResult<ConnectionHandle>>);
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!(<Output = TransportResult<ConnectionHandle>>) {
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!(<Output = TransportResult<PubSubFrontend>>) {
PubSubService::connect(self)
fn into_service(self) -> Pbf<'static, PubSubFrontend, TransportError> {
Box::pin(PubSubService::connect(self))
}
}
8 changes: 4 additions & 4 deletions crates/pubsub/src/frontend.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -31,7 +31,7 @@ impl PubSubFrontend {
pub fn get_subscription(
&self,
id: U256,
) -> impl Future<Output = TransportResult<RawSubscription>> + Send + 'static {
) -> impl Future<Output = Result<RawSubscription, TransportError>> + Send + 'static {
let backend_tx = self.tx.clone();
async move {
let (tx, rx) = oneshot::channel();
Expand All @@ -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())
Expand All @@ -53,7 +53,7 @@ impl PubSubFrontend {
pub fn send(
&self,
req: SerializedRequest,
) -> impl Future<Output = TransportResult<Response>> + Send + 'static {
) -> impl Future<Output = Result<Response, TransportError>> + Send + 'static {
let tx = self.tx.clone();
let channel_size = self.channel_size;

Expand Down
6 changes: 3 additions & 3 deletions crates/pubsub/src/managers/in_flight.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<TransportResult<Response>>,
pub(crate) tx: oneshot::Sender<Result<Response, TransportError>>,
}

impl fmt::Debug for InFlight {
Expand All @@ -34,7 +34,7 @@ impl InFlight {
pub(crate) fn new(
request: SerializedRequest,
channel_size: usize,
) -> (Self, oneshot::Receiver<TransportResult<Response>>) {
) -> (Self, oneshot::Receiver<Result<Response, TransportError>>) {
let (tx, rx) = oneshot::channel();

(Self { request, channel_size, tx }, rx)
Expand Down
6 changes: 3 additions & 3 deletions crates/pubsub/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -35,7 +35,7 @@ pub(crate) struct PubSubService<T> {

impl<T: PubSubConnect> PubSubService<T> {
/// Create a new service from a connector.
pub(crate) async fn connect(connector: T) -> TransportResult<PubSubFrontend> {
pub(crate) async fn connect(connector: T) -> Result<PubSubFrontend, TransportError> {
let handle = connector.connect().await?;

let (tx, reqs) = mpsc::unbounded_channel();
Expand All @@ -51,7 +51,7 @@ impl<T: PubSubConnect> PubSubService<T> {
}

/// Reconnect by dropping the backend and creating a new one.
async fn get_new_backend(&mut self) -> TransportResult<ConnectionHandle> {
async fn get_new_backend(&mut self) -> Result<ConnectionHandle, TransportError> {
let mut handle = self.connector.try_reconnect().await?;
std::mem::swap(&mut self.handle, &mut handle);
Ok(handle)
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc-client/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a, T> BatchRequest<'a, T> {
fn push<Params: RpcParam, Resp: RpcReturn>(
&mut self,
request: Request<Params>,
) -> TransportResult<Waiter<Resp>> {
) -> Result<Waiter<Resp>, TransportError> {
let ser = request.serialize().map_err(TransportError::ser_err)?;
Ok(self.push_raw(ser).into())
}
Expand All @@ -124,7 +124,7 @@ where
&mut self,
method: &'static str,
params: &Params,
) -> TransportResult<Waiter<Resp>> {
) -> Result<Waiter<Resp>, TransportError> {
let request = self.transport.make_request(method, Cow::Borrowed(params));
self.push(request)
}
Expand Down Expand Up @@ -242,7 +242,7 @@ impl<T> Future for BatchFuture<T>
where
T: Transport + Clone,
{
type Output = TransportResult<()>;
type Output = Result<(), TransportError>;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
if matches!(*self.as_mut(), BatchFuture::Prepared { .. }) {
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc-client/src/builder.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<L> ClientBuilder<L> {
/// Connect a pubsub transport, producing an [`RpcClient`] with the provided
/// connection.
#[cfg(feature = "pubsub")]
pub async fn pubsub<C>(self, pubsub_connect: C) -> TransportResult<RpcClient<L::Service>>
pub async fn pubsub<C>(self, pubsub_connect: C) -> Result<RpcClient<L::Service>, TransportError>
where
C: alloy_pubsub::PubSubConnect,
L: Layer<alloy_pubsub::PubSubFrontend>,
Expand All @@ -94,7 +94,7 @@ impl<L> ClientBuilder<L> {
pub async fn ws(
self,
ws_connect: alloy_transport_ws::WsConnect,
) -> TransportResult<RpcClient<L::Service>>
) -> Result<RpcClient<L::Service>, TransportError>
where
L: Layer<alloy_pubsub::PubSubFrontend>,
L::Service: Transport,
Expand All @@ -104,7 +104,7 @@ impl<L> ClientBuilder<L> {

/// Connect a transport, producing an [`RpcClient`] with the provided
/// connection.
pub async fn connect<C>(self, connect: C) -> TransportResult<RpcClient<L::Service>>
pub async fn connect<C>(self, connect: C) -> Result<RpcClient<L::Service>, TransportError>
where
C: TransportConnect,
L: Layer<C::Transport>,
Expand All @@ -116,7 +116,7 @@ impl<L> ClientBuilder<L> {

/// Connect a transport, producing an [`RpcClient`] with a [`BoxTransport`]
/// connection.
pub async fn connect_boxed<C>(self, connect: C) -> TransportResult<RpcClient<L::Service>>
pub async fn connect_boxed<C>(self, connect: C) -> Result<RpcClient<L::Service>, TransportError>
where
C: BoxTransportConnect,
L: Layer<BoxTransport>,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod pubsub_impl {

impl RpcClient<PubSubFrontend> {
/// Connect to a transport via a [`PubSubConnect`] implementor.
pub async fn connect_pubsub<C>(connect: C) -> TransportResult<RpcClient<PubSubFrontend>>
pub async fn connect_pubsub<C>(connect: C) -> Result<RpcClient<PubSubFrontend>, TransportError>
where
C: PubSubConnect,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl From<Option<Bytes>> 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;
Expand Down
18 changes: 12 additions & 6 deletions crates/transport-ipc/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ macro_rules! impl_connect {
true
}

async fn connect(
&self,
) -> Result<alloy_pubsub::ConnectionHandle, alloy_transport::TransportError> {
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)
})
}
}
};
Expand Down
20 changes: 11 additions & 9 deletions crates/transport-ws/src/native.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,18 +42,20 @@ impl PubSubConnect for WsConnect {
alloy_transport::utils::guess_local_url(&self.url)
}

async fn connect(&self) -> TransportResult<alloy_pubsub::ConnectionHandle> {
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)
})
}
}

Expand Down
21 changes: 13 additions & 8 deletions crates/transport-ws/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -20,16 +20,21 @@ impl PubSubConnect for WsConnect {
alloy_transport::utils::guess_local_url(&self.url)
}

async fn connect(&self) -> TransportResult<alloy_pubsub::ConnectionHandle> {
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)
})
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 8ed5684

Please sign in to comment.