Make ContractCall IntoFuture implement Send (#2083)

* fix(contracts): Add a failing test showing that ContractCall IntoFuture is not Send

* fix(contracts): Add Send bound for IntoFuture implementation of ContractCall

* chore: update CHAGELOG

* chore: fmt

---------

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Guillaume Malette 2023-01-27 14:54:49 -05:00 committed by GitHub
parent f86bc2483f
commit 83b12a80e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,7 @@
### Unreleased
- Add a `Send` bound to the `IntoFuture` implementation of `ContractCall` [#2083](https://github.com/gakonst/ethers-rs/pull/2083)
- Bump [`svm-rs`](https://github.com/roynalnaruto/svm-rs) dependency to fix conflicts with Rust Crytpo packages [#2051](https://github.com/gakonst/ethers-rs/pull/2051)
- Avoid unnecessary allocations in `utils` [#2046](https://github.com/gakonst/ethers-rs/pull/2046)
- Add abigen support for hardhat generated bytecode json format [#2012](https://github.com/gakonst/ethers-rs/pull/2012)

View File

@ -225,10 +225,10 @@ impl<M, D> IntoFuture for ContractCall<M, D>
where
Self: 'static,
M: Middleware,
D: Detokenize,
D: Detokenize + Send + Sync,
{
type Output = Result<D, ContractError<M>>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output>>>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.call().await })

View File

@ -0,0 +1,21 @@
use ethers_contract_derive::abigen;
use ethers_core::abi::Address;
use ethers_providers::Provider;
use std::{
future::{Future, IntoFuture},
sync::Arc,
};
#[tokio::test]
async fn contract_call_into_future_is_send() {
abigen!(DsProxyFactory, "ethers-middleware/contracts/DsProxyFactory.json");
let (provider, _) = Provider::mocked();
let client = Arc::new(provider);
let contract = DsProxyFactory::new(Address::zero(), client);
fn is_send<T: Future + Send + 'static>(future: T) -> bool {
true
}
assert!(is_send(contract.cache().into_future()));
}

View File

@ -6,5 +6,6 @@ pub(crate) mod common;
mod console;
#[cfg(feature = "abigen")]
mod contract;
mod contract_call;
fn main() {}