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

Replace contract client references with Arc #35

Merged
merged 5 commits into from
Jun 22, 2020
Merged

Conversation

gakonst
Copy link
Owner

@gakonst gakonst commented Jun 22, 2020

Motivation

Currently, the Contract struct takes a reference to the Client (https://github.com/gakonst/ethers-rs/blob/master/ethers-contract/src/contract.rs#L166).

This is done in order to avoid cloning/moving the client everywhere which would be:

  1. inefficient: you should have 1 client which is responsible for creating your requests used by all contract instances!
  2. risky: Cloning the client might mean cloning the private key all over your memory. Bad.

This introduced a lifetime in the Contract struct which can be a huge pain, in particular if you want to put the contract struct inside another struct which you want to do a spawn call for (which requires static bounds).

Solution

Replacing the reference with Arc does the trick. We get some runtime overheads, but that's acceptable.

Drive-by changes

Add a default interval parameter to the client/provider/contract/factory, so that we can specify the polling interval for all calls once (previously we'd need to specify it on a per-call basis, which is annoying if you're on different networks with faster block times and want to do multiple calls)

This is a breaking change since it changes the interface of send_transaction, send_raw_transaction, and call

@gakonst gakonst force-pushed the feature/arc-contract branch from 8166c32 to e89bf90 Compare June 22, 2020 07:14
…ission

Returning a PendingTransaction allowed us to have nice ethers.js-like syntax where you submit
a transaction and then can immediately await it. Unfortunately, now that we use Arcs and not lifetimes
this meant that we would need to bind the function call in a variable, and then await on it, which is pretty
bad UX.

To fix this, we revert back to returning a TxHash and introduce a convenience method on the provider and the
contract which takes a tx_hash and returns a PendingTransaction object. The syntax ends up being slightly
more verbose (although more explicit), but the issue is fixed.
@gakonst gakonst merged commit 1cfbc7b into master Jun 22, 2020
@gakonst gakonst deleted the feature/arc-contract branch June 22, 2020 08:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant