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

Add possibility to include self-defined Jsonrpsee Client in Wrapper struct #714

Closed
haerdib opened this issue Feb 12, 2024 · 2 comments · Fixed by #735
Closed

Add possibility to include self-defined Jsonrpsee Client in Wrapper struct #714

haerdib opened this issue Feb 12, 2024 · 2 comments · Fixed by #735
Assignees
Labels
F7-enhancement Enhances an already existing functionality Q0-trivial

Comments

@haerdib
Copy link
Contributor

haerdib commented Feb 12, 2024

E.g. add new function to create a JsonrpseeClient wrapper but with a user defined client here:

impl JsonrpseeClient {
pub async fn with_default_url() -> Result<Self> {
Self::new("ws://127.0.0.1:9944").await
}
pub async fn new(url: &str) -> Result<Self> {
let uri: Uri = url.parse().map_err(|e| Error::Client(Box::new(e)))?;
let (tx, rx) = WsTransportClientBuilder::default()
.build(uri)
.await
.map_err(|e| Error::Client(Box::new(e)))?;
let client = ClientBuilder::default()
.max_notifs_per_subscription(4096)
.build_with_tokio(tx, rx);
Ok(Self { inner: Arc::new(client) })
}

Example:

pub async fn with_client(client: Arc<Client>) -> Self {
	Self { inner: client }
}

I'd also propose to make the inner client public - then the user may change settings any time.

@haerdib haerdib added F7-enhancement Enhances an already existing functionality Q0-trivial labels Feb 12, 2024
@masapr
Copy link
Collaborator

masapr commented Feb 12, 2024

I don't think we should make the inner client public. We don't want anyone to change the client during the running program (what happens e. g. with subscriptions, when I exchange the client? What happens with running processes? We would have to handle all these cases.).

But adding a constructor which takes a custom JsonrpseeClient is fine. I don't see any problem with that.

@haerdib
Copy link
Contributor Author

haerdib commented Feb 15, 2024

That is true, but this way no one can access the inner convenience functions, such as is_connected (see here: https://github.com/paritytech/jsonrpsee/blob/master/core/src/client/async_client/mod.rs#L458-L490). We could also forward them, but then we'd need to make sure that we stay up-to-date with these functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F7-enhancement Enhances an already existing functionality Q0-trivial
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants