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

WIP: feat: client rpc middleware #1521

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Jan 22, 2025

This PR/PoC tries to unify the RpcServiceT such that it can be used by both the client and servers and to provide a uniform API such as re-use middleware etc between client/servers and so on.

However, because the client needs to handle batch requests etc, I propose to change the API from:

/// Similar to the [`tower::Service`] but specific for jsonrpsee and
/// doesn't requires `&mut self` for performance reasons.
pub trait RpcServiceT<'a> {
	/// The future response value.
	type Future: Future<Output = MethodResponse> + Send;

	/// Process a single JSON-RPC call it may be a subscription or regular call.
	///
	/// In this interface both are treated in the same way but it's possible to
	/// distinguish those based on the `MethodResponse`.
	fn call(&self, request: Request<'a>) -> Self::Future;
}

To this instead:

/// Similar to the [`tower::Service`] but specific for jsonrpsee and
/// doesn't requires `&mut self` for performance reasons.
pub trait RpcServiceT<'a> {
	/// The future response value.
	type Future: Future<Output = Result<MethodResponse, Error>> + Send;
        type Error;
 
	/// Process a single JSON-RPC call it may be a subscription or regular call.
	///
	/// In this interface both are treated in the same way but it's possible to
	/// distinguish those based on the `MethodResponse`.
	fn call(&self, request: Request<'a>) -> Self::Future;

	/// Similar to `RpcServiceT::call` but process multiple JSON-RPC calls at once in a batch.
	fn batch(&self, _requests: Vec<Request<'a>>) -> Self::Future;

	/// Similar to `RpcServiceT::call` but process a JSON-RPC notification.
	fn notification(&self, _request: Notification<'a, Option<Box<RawValue>>>);
}

The reason is that the underlying client service will serialize the request which won't support Batches unless we add with a dedicate API i.e, we would need to send them one-by-one.

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.

1 participant