Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Make ContractCall IntoFuture implement Send (#2083)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
gmalette and gakonst authored Jan 27, 2023
1 parent f86bc24 commit 83b12a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ethers-contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
21 changes: 21 additions & 0 deletions ethers-contract/tests/it/contract_call.rs
Original file line number Diff line number Diff line change
@@ -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()));
}
1 change: 1 addition & 0 deletions ethers-contract/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ pub(crate) mod common;
mod console;
#[cfg(feature = "abigen")]
mod contract;
mod contract_call;

fn main() {}

0 comments on commit 83b12a8

Please sign in to comment.