Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/examples/rpc_call_subscribe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api =
OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?;

// For non-finalised blocks use `.subscribe_blocks()`
// For non-finalised blocks use `.subscribe_new_blocks()`
let mut blocks: Subscription<Header<u32, BlakeTwo256>> =
api.rpc().subscribe_finalized_blocks().await?;

Expand Down
2 changes: 1 addition & 1 deletion subxt/src/events/events_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
T: Config,
Client: OnlineClientT<T>,
{
let block_subscription = client.rpc().subscribe_blocks().await?;
let block_subscription = client.rpc().subscribe_new_blocks().await?;
Ok(EventSubscription::new(client, block_subscription))
}

Expand Down
18 changes: 16 additions & 2 deletions subxt/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,22 @@ impl<T: Config> Rpc<T> {
Ok(version)
}

/// Subscribe to blocks.
pub async fn subscribe_blocks(&self) -> Result<Subscription<T::Header>, Error> {
/// Subscribe to all blocks.
pub async fn subscribe_all_blocks(&self) -> Result<Subscription<T::Header>, Error> {
let subscription = self
.client
.subscribe(
"chain_subscribeAllHeads",
rpc_params![],
"chain_unsubscribeAllHeads",
)
.await?;

Ok(subscription)
}

/// Subscribe to new blocks.
pub async fn subscribe_new_blocks(&self) -> Result<Subscription<T::Header>, Error> {
let subscription = self
.client
.subscribe(
Expand Down
13 changes: 11 additions & 2 deletions testing/integration-tests/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,20 @@ async fn fetch_read_proof() {
}

#[tokio::test]
async fn chain_subscribe_blocks() {
async fn subscribe_all_blocks() {
let ctx = test_context().await;
let api = ctx.client();

let mut blocks = api.rpc().subscribe_blocks().await.unwrap();
let mut blocks = api.rpc().subscribe_all_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}

#[tokio::test]
async fn subscribe_new_blocks() {
let ctx = test_context().await;
let api = ctx.client();

let mut blocks = api.rpc().subscribe_new_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion testing/integration-tests/src/utils/wait_for_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use subxt::{
/// (the genesis block and another one) seems to be enough to allow tests
/// like `dry_run_passes` to work properly.
pub async fn wait_for_blocks<C: Config>(api: &impl OnlineClientT<C>) {
let mut sub = api.rpc().subscribe_blocks().await.unwrap();
let mut sub = api.rpc().subscribe_new_blocks().await.unwrap();
sub.next().await;
sub.next().await;
}