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

Allow generalising over RPC implementation #634

Merged
merged 31 commits into from Aug 31, 2022
Merged

Allow generalising over RPC implementation #634

merged 31 commits into from Aug 31, 2022

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Aug 24, 2022

Make jsonrpsee optional, and generalise the underlying RPC mechanism over any clients that implement the new RpcClientT trait we expose.

The RpcClientT trait has been made to be "low level", as in order to be object-safe it cannot have generic parameters and such. We want it to be object-safe to avoid the proliferation of some Rpc trait bound everywhere (it turns out that even things like OfflineClientT, which should not care at all, would need it, because it can consturct other types which would need it).

jsonrpsee is still used by default (unless the feature is disabled). Currently it's impl of this trait is somewhat clunky, but paritytech/jsonrpsee#862 should resolve that.

Closes #596

fn request_raw<'a>(
&'a self,
method: &'a str,
params: Box<RawValue>,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we also receive no parameters here?

Copy link
Member

@niklasad1 niklasad1 Aug 25, 2022

Choose a reason for hiding this comment

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

I think the intention is that you are supposed to use the rpc_params macro that James wrote which takes care of that for you or provide your own customized impl that serializes the result to RawValue

However, I agree that creating a RawValue from the an empty JSON String is quite awkward because you need to allocate a String for it but as this is a lower-level interface I guess that is ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have just tweaked these things to accept Option<Box<RawValue>>, to allow subxt to avoid the unnecessary allocations when there are no params :)

/// to talk to a node.
///
/// This is a low level interface which expects an already-serialized set of params,
/// and returns an owned but still-serialized [`RawValue`], deferring deserialization to
Copy link
Member

Choose a reason for hiding this comment

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

RawValue is quite hard to deal with in general and it would be good if you could point to RpcParams for an example implementation of this.

My noob eyes find it hard to look at this trait along with the docs of RawValue to understand how to do it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense; I'll add some more examples to show how these methods can be called manually!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(I just ended up pointing to RpcParams in the docs to show examples of building params)

@jsdw jsdw merged commit 599107b into master Aug 31, 2022
@jsdw jsdw deleted the jsdw-generic-rpc branch August 31, 2022 09:00
@sander2 sander2 mentioned this pull request Nov 21, 2022
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.

Light client support / generalizing over RPC provider
3 participants