Skip to main content

subscribe_program_logs

Function subscribe_program_logs 

Source
pub async fn subscribe_program_logs<F, Fut>(
    rpc_endpoint: &str,
    program_id: &str,
    commitment: CommitmentConfig,
    on_notification: F,
) -> Result<LogSubscriptionHandle, SubscriptionError>
where F: Fn(Response<RpcLogsResponse>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,
Expand description

Subscribe to the logs of every transaction that mentions program_id.

rpc_endpoint is the session’s RPC endpoint. Each notification runs on_notification as its own Tokio task, so callbacks can run concurrently and out of order. Returns once the server confirms the subscription. Never reconnects; see the module docs.

On a ManagedBacktestSession, you can instead read logs from meta.log_messages of the transactions its subscribe_transactions delivers, which survives reconnects.

§Errors

SubscriptionError if the subscription cannot be started.

§Example

use simulator_client::{ManagedBacktestSession, subscribe_program_logs};
use solana_commitment_config::CommitmentConfig;

let handle = subscribe_program_logs(
    &session.session_info().rpc_endpoint,
    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    CommitmentConfig::confirmed(),
    |notification| async move {
        println!("sig: {}", notification.value.signature);
    },
)
.await?;

// ... do other work ...

handle.shutdown().await?;