alloy icon indicating copy to clipboard operation
alloy copied to clipboard

[Suggestion] Expose methods from `ClientBuilder` on `ProviderBuilder` (`on_http`, etc..)

Open zerosnacks opened this issue 1 year ago • 9 comments

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

zerosnacks avatar Mar 19 '24 12:03 zerosnacks

add a reqwest_http method to the provider builder. Average users should never instantiate a RootProvider

prestwich avatar Mar 19 '24 13:03 prestwich

follow pattern in

crates/rpc-client/src/builder.rs

prestwich avatar Mar 19 '24 13:03 prestwich

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.

prestwich avatar Mar 19 '24 15:03 prestwich

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));

zerosnacks avatar Mar 19 '24 16:03 zerosnacks

the new scope here should be to avoid the RpcClient import as well. make a on_http method on ProviderBuilder

prestwich avatar Mar 19 '24 17:03 prestwich

the new scope here should be to avoid the RpcClient import as well. make a on_http method on ProviderBuilder

Reopening with this as context of the ticket

zerosnacks avatar Mar 19 '24 17:03 zerosnacks

we could probably expand scope a little here by having the provider builder wrap a client builder and pass through a bunch of methods?

prestwich avatar Mar 19 '24 17:03 prestwich

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 avatar Mar 24 '24 09:03 developeruche

@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(...)

gakonst avatar Jun 11 '24 22:06 gakonst

Closing as resolved we have the .on_http method on ProviderBuilder now

yash-atreya avatar Feb 20 '25 12:02 yash-atreya