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

change visibility of request in Provider<JsonRpcClient> #919

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

ntrippar
Copy link
Contributor

Motivation

I want to implement a custom MIddleware to call otterscan RPC calls on the node and self implemented ones, currently the request function on Provider<JsonRpcClient> is private, changing the function to public will allow me to create implementations like this one.

#[async_trait]
pub trait OtterScanMiddleware: Middleware {
    async fn get_api_level(&self) -> Result<U64, ProviderError> {
        self.provider().get_api_level().await.map_err(FromErr::from)
    }
}

#[async_trait]
impl<P: JsonRpcClient> OtterScanMiddleware for Provider<P> {
    async fn get_api_level(&self) -> Result<U64, ProviderError> {
        self.request("ots_getApiLevel", []).await
    }
}

Solution

change request function to pub

…to public so one can implement Middleware's with custom call to the node
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can do that, even though this function is merely used as a wrapper around self.inner.request(method, params) with additional tracing.

However we're returning unreachable in Provider::inner 🤔

So I think we should make this change @gakonst

@gakonst gakonst merged commit f9f466e into gakonst:master Feb 17, 2022
@gakonst
Copy link
Owner

gakonst commented Feb 17, 2022

agreed - good one

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 this pull request may close these issues.

3 participants