Skip to content

Commit

Permalink
refactor(gsdk): Remove abiguity in Api::blocks() functions (#3456)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Novikov <[email protected]>
  • Loading branch information
mqxf and breathx authored Oct 29, 2023
1 parent 8f781af commit a34fcfc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gclient/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl GearApi {
/// Create an [`EventListener`] to subscribe and handle continuously
/// incoming events.
pub async fn subscribe(&self) -> Result<EventListener> {
let events = self.0.api().finalized_blocks().await?;
let events = self.0.api().subscribe_finalized_blocks().await?;
Ok(EventListener(events))
}

Expand Down
8 changes: 4 additions & 4 deletions gsdk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ impl Api {
///
/// ```ignore
/// let api = Api::new(None).await?;
/// let blocks = api.blocks().await?;
/// let blocks = api.subscribe_blocks().await?;
///
/// while let Ok(block) = blocks.next().await {
/// // ...
/// }
/// ```
pub async fn blocks(&self) -> Result<Blocks> {
pub async fn subscribe_blocks(&self) -> Result<Blocks> {
Ok(self.client.blocks().subscribe_all().await?.into())
}

/// Subscribe finalized blocks
///
/// Same as `blocks` but only finalized blocks.
pub async fn finalized_blocks(&self) -> Result<Blocks> {
/// Same as `subscribe_blocks` but only finalized blocks.
pub async fn subscribe_finalized_blocks(&self) -> Result<Blocks> {
Ok(self.client.blocks().subscribe_finalized().await?.into())
}

Expand Down
2 changes: 1 addition & 1 deletion gsdk/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async fn test_runtime_wasm_blob_version() -> Result<()> {

let node = dev_node();
let api = Api::new(Some(&node_uri(&node))).await?;
let mut finalized_blocks = api.finalized_blocks().await?;
let mut finalized_blocks = api.subscribe_finalized_blocks().await?;

let wasm_blob_version_1 = api.runtime_wasm_blob_version(None).await?;
assert!(
Expand Down
2 changes: 1 addition & 1 deletion utils/node-loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn run(params: Params) -> Result<()> {
/// Broadcast new events to receivers.
async fn listen_events(tx: Sender<subxt::events::Events<GearConfig>>, node: String) -> Result<()> {
let api = gsdk::Api::new(Some(&node)).await?;
let mut event_listener = api.finalized_blocks().await?;
let mut event_listener = api.subscribe_finalized_blocks().await?;

while let Some(events) = event_listener.next_events().await {
tx.send(events?)?;
Expand Down
5 changes: 4 additions & 1 deletion utils/validator-checks/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ impl Listener {

/// Listen to finalized blocks.
pub async fn listen_finalized(&self) -> Result<Blocks> {
self.api.finalized_blocks().await.map_err(Into::into)
self.api
.subscribe_finalized_blocks()
.await
.map_err(Into::into)
}

/// Run validator checks.
Expand Down

0 comments on commit a34fcfc

Please sign in to comment.