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

abstract provider and transport for ScrollAuthEngineProvider #149

Open
greged93 opened this issue Jan 29, 2025 · 0 comments
Open

abstract provider and transport for ScrollAuthEngineProvider #149

greged93 opened this issue Jan 29, 2025 · 0 comments

Comments

@greged93
Copy link
Collaborator

greged93 commented Jan 29, 2025

This would allow for any transport to be used (ws, ipc, http), instead of currently being constrained to http.

          I wonder if it's possible to make this generic over the `Provider` and `Transport` (the `Network` should be hard coded to `Scroll`). This would allow us to use different providers/transport protocols to interact with the node (ws / HTTP). I think it should be possible something like this but I haven't got it working yet:
/// An authenticated [`alloy_provider::Provider`] to the [`super::ScrollEngineApi`].
#[derive(Debug, Clone, Deref)]
pub struct ScrollAuthEngineApiProvider<ProviderT, TransportT> {
    #[deref]
    provider: ProviderT,
    _marker: std::marker::PhantomData<TransportT>,
}

impl<ProviderT, TransportT> ScrollAuthEngineApiProvider<ProviderT, TransportT>
where
    ProviderT: Provider<TransportT, Scroll>,
    TransportT: Transport + Clone,
{
    /// Returns a new [`ScrollAuthEngineApiProvider`], authenticated for interfacing with the Engine
    /// API server at the provided URL using the passed JWT secret.
    pub fn new(jwt_secret: JwtSecret, url: Url) -> Self {
        let auth_layer = AuthLayer::new(jwt_secret);
        let hyper_client = hyper_util::client::legacy::Client::builder(TokioExecutor::new())
            .build_http::<Full<Bytes>>();

        let service = tower::ServiceBuilder::new().layer(auth_layer).service(hyper_client);
        let transport = HyperClient::<Full<Bytes>, _>::with_service(service);

        let is_url_local = guess_local_url(&url);
        let http = Http::with_client(transport, url);
        let client = RpcClient::new(http, is_url_local);
        let provider = ProviderBuilder::new().network::<Scroll>().on_client(client);

        Self { provider, _marker: Default::default() }
    }
}
          I suggest you timebox this to an hour to see if you can get it working. If not then we will merge as is.

Originally posted by @frisitano in #147 (comment)

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

No branches or pull requests

1 participant