Skip to main content

subscribe_program_diffs

Function subscribe_program_diffs 

Source
pub async fn subscribe_program_diffs<F, Fut>(
    rpc_endpoint: &str,
    program_id: &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 for all accounts owned by a program.

Uses the server-side program filter ({"address_type": "program"}), so no RPC prefetch of program accounts is required. The callback receives one AccountDiffNotification per changed account.

A websocket disconnect is treated as a fatal error — the handle’s join_handle resolves with a SubscriptionRuntimeError.

§Example

use simulator_client::subscribe_program_diffs;

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

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