Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider): use BoxTransport in on_anvil_* #1693

Merged
merged 3 commits into from
Nov 26, 2024
Merged

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Nov 26, 2024

Motivation

Currently, the on_anvil_* methods on the provider builder return a provider based on Http<Client> transport client.

Since, the default transport in Provider is BoxTransport, there exists friction when working with types that wrap a Provider. It becomes necessary to add the T: Transport generic to `Foo<P: Provider, T: Transport + Clone>>.

The following (cleaner) way isn't possible:

struct Foo<P: Provider> {
    provider: P,
}

impl<P: Provider> Foo<P> { // default transport is BoxTransport
    pub fn new(provider: P) -> Self {
        Self { provider }
    }

    pub async fn get_block_number(&self) -> TransportResult<u64> {
        self.provider.get_block_number().await
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let provider = ProviderBuilder::new().on_anvil(); // provider based on Http<Client>

    let foo = Foo::new(provider); // Won't compile

}

Solution

Box the transport after instantiating RpcClient using .boxed

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya changed the title Yash/on anvil boxed fix(provider): use BoxTransport in on_anvil_* Nov 26, 2024
@mattsse mattsse merged commit 36fd778 into main Nov 26, 2024
26 checks passed
@mattsse mattsse deleted the yash/on-anvil-boxed branch November 26, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants