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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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
, andcall