Impl `IntoFuture` for `ContractCall`
@@ -14,7 +14,14 @@ use ethers_providers::{
Middleware, PendingTransaction, ProviderError,
};
-use std::{borrow::Cow, fmt::Debug, future::Future, marker::PhantomData, sync::Arc};
+use std::{
+ borrow::Cow,
+ fmt::Debug,
+ future::{Future, IntoFuture},
+ marker::PhantomData,
+ pin::Pin,
+ sync::Arc,
+};
use thiserror::Error as ThisError;
@@ -211,3 +218,19 @@ where
.map_err(ContractError::MiddlewareError)
}
}
+
+/// [`ContractCall`] can be turned into [`Future`] automatically with `.await`.
+/// Defaults to calling [`ContractCall::call`].
+impl<M, D> IntoFuture for ContractCall<M, D>
+where
+ Self: 'static,
+ M: Middleware,
+ D: Detokenize,
+{
+ type Output = Result<D, ContractError<M>>;
+ type IntoFuture = Pin<Box<dyn Future<Output = Self::Output>>>;
+
+ fn into_future(self) -> Self::IntoFuture {
+ Box::pin(async move { self.call().await })
+ }
+}
