Skip to content

Commit 20bc4b8

Browse files
jsdwniklasad1
andauthored
Add docs for subxt-rpcs and fix example (#1954)
* Add docs for subxt-rpcs and fix example * Add docs bits in Cargo.toml * add missing docsrs cfg_attr --------- Co-authored-by: Niklas Adolfsson <[email protected]>
1 parent 4c32ee1 commit 20bc4b8

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Example usage via `jsonrpsee` feature:
2727
use subxt_rpcs::{RpcClient, ChainHeadRpcMethods};
2828

2929
// Connect to a local node:
30-
let client = RpcClient::("ws://127.0.0.1:9944").await?;
30+
let client = RpcClient::from_url("ws://127.0.0.1:9944").await?;
3131
// Use chainHead/archive V2 methods:
3232
let methods = ChainHeadRpcMethods::new(client);
3333

rpcs/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,9 @@ tower = { workspace = true }
9494
hyper = { workspace = true }
9595
http-body = { workspace = true }
9696

97+
[package.metadata.docs.rs]
98+
default-features = true
99+
rustdoc-args = ["--cfg", "docsrs"]
100+
97101
[lints]
98102
workspace = true

rpcs/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# subxt-rpcs
2+
3+
This crate provides an interface for interacting with Substrate nodes via the available RPC methods.
4+
5+
```rust
6+
use subxt_rpcs::{RpcClient, ChainHeadRpcMethods};
7+
8+
// Connect to a local node:
9+
let client = RpcClient::from_url("ws://127.0.0.1:9944").await?;
10+
// Use a set of methods, here the V2 "chainHead" ones:
11+
let methods = ChainHeadRpcMethods::new(client);
12+
13+
// Call some RPC methods (in this case a subscription):
14+
let mut follow_subscription = methods.chainhead_v1_follow(false).await.unwrap();
15+
while let Some(follow_event) = follow_subscription.next().await {
16+
// do something with events..
17+
}
18+
```

rpcs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
//! The provided RPC client implementations can be used natively (with the default `native` feature
1717
//! flag) or in WASM based web apps (with the `web` feature flag).
1818
19+
#![cfg_attr(docsrs, feature(doc_cfg))]
20+
1921
#[cfg(any(
2022
all(feature = "web", feature = "native"),
2123
not(any(feature = "web", feature = "native"))

utils/fetch-metadata/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//! Subxt utils fetch metadata.
66
7+
#![cfg_attr(docsrs, feature(doc_cfg))]
8+
79
// Internal helper macros
810
#[macro_use]
911
mod macros;

0 commit comments

Comments
 (0)