-
Notifications
You must be signed in to change notification settings - Fork 254
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
Conversation
subxt/src/rpc/rpc_client_t.rs
Outdated
fn request_raw<'a>( | ||
&'a self, | ||
method: &'a str, | ||
params: Box<RawValue>, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
subxt/src/rpc/rpc_client_t.rs
Outdated
/// 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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)
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 someRpc
trait bound everywhere (it turns out that even things likeOfflineClientT
, 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