Skip to main content

subscribe_account_diffs

Function subscribe_account_diffs 

Source
pub async fn subscribe_account_diffs<F, Fut>(
    rpc_endpoint: &str,
    account: &str,
    on_notification: F,
) -> Result<AccountDiffSubscriptionHandle, SubscriptionError>
where F: Fn(AccountDiffNotification) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,
Expand description

Subscribe to account diff notifications and invoke a callback for each one.

Spawns a background task that:

  1. Connects to the WebSocket endpoint derived from rpc_endpoint.
  2. Subscribes to account diffs for the given filter (account or program).
  3. For each notification, spawns on_notification(notification) as a Tokio task.
  4. When handle.stop.send(true) is called, drains remaining buffered notifications (up to 1s), waits for all spawned tasks, then returns.

ยงExample

use simulator_client::subscribe_account_diffs;

let handle = subscribe_account_diffs(
    "http://localhost:8900/session/abc",
    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    |notification| async move {
        println!("slot={} sig={:?}", notification.context.slot, notification.signature);
    },
)
.await?;

handle.stop.send(true).ok();
handle.join_handle.await.ok();