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

Contract::connect should be able to connect to different middleware types #1158

Closed
prestwich opened this issue Apr 21, 2022 · 4 comments · Fixed by #1159
Closed

Contract::connect should be able to connect to different middleware types #1158

prestwich opened this issue Apr 21, 2022 · 4 comments · Fixed by #1159

Comments

@prestwich
Copy link
Collaborator

Contract::<M>::connect has this following signature pub fn connect(&self, client: Arc<M>) -> Self

This allows the contract to connect to different instances of the same provider. Instead it should have signature:

pub fn connect<N>(&self, client: Arc<N>) -> Contract<N>
    where
        N: Middleware + Clone

This would allow contracts to change provider types when calling connect.

proposed impl:

#[must_use]
    pub fn connect(&self, client: Arc<M>) -> Contract<N>
    where
        M: Clone,
    {
        Contract::<N>::new(self.address, self.base_contract.clone(), client)
    }
@mattsse
Copy link
Collaborator

mattsse commented Apr 21, 2022

nice catch!
can add this in a bit

@prestwich
Copy link
Collaborator Author

another easy change might be adding connect to the output of abigen so that it doesn't erase the specialized type of the abigen contract and give you a generic Contract

@prestwich
Copy link
Collaborator Author

(that's not a big deal as there's a From impl but it'd be nice to drop the into)

// current:
let b: AbigenContract = AbigenContract.connect(new_provider).into();

// desired
let b: AbigenContract = AbigenContract.connect(new_provider);

@mattsse
Copy link
Collaborator

mattsse commented Apr 21, 2022

yeh the connect is acutally the Contract::connect function (because of the deref impl) since the generated type is just a wrapper type.

I guess we can just generate another connect function?

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 a pull request may close this issue.

2 participants