alloy
alloy copied to clipboard
[Suggestion] Expose methods from `ClientBuilder` on `ProviderBuilder` (`on_http`, etc..)
Component
provider, pubsub
Describe the feature you would like
Currently we require RpcClient to be imported, it would be ideal to have the on_http method available on the ProviderBuilder directly.
It is likely best to generalize this more and have the ProviderBuilder wrap a ClientBuilder and pass through a number of methods, one of which is the on_http method.
Additional context
See: https://github.com/alloy-rs/examples/pull/2/files#r1530234063
add a reqwest_http method to the provider builder. Average users should never instantiate a RootProvider
follow pattern in
crates/rpc-client/src/builder.rs
saying a little more now that i've had coffee:
RpcClient and the Transport implementors (Http/Ws/Ipc) are not intended to be instantiated by users. they should be entirely hidden behind the ProviderBuilder. They are exposed ONLY for power-users, and examples should not cover direct usage at all.
Closing this as you can achieve it using the current abstractions, without requiring the importing of reqwest:
let http = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
the new scope here should be to avoid the RpcClient import as well. make a on_http method on ProviderBuilder
the new scope here should be to avoid the
RpcClientimport as well. make aon_httpmethod onProviderBuilder
Reopening with this as context of the ticket
we could probably expand scope a little here by having the provider builder wrap a client builder and pass through a bunch of methods?
Going through this issue, it seems like this;
pub fn new_http(url: reqwest::Url) -> Self;
is the only function that needs to be exposed directly on ProviderBuilder, which other function do you have in mind?
@zerosnacks @prestwich
@developeruche I think the ones that are most important are the ClientBuilder methods for layer'ing transports, so you can do ProviderBuilder::new().layer(...).on_http(...)
Closing as resolved we have the .on_http method on ProviderBuilder now