switchboard-on-demand 0.9.3

A Rust library to interact with the Switchboard Solana program.
Documentation
/// Example demonstrating the new Queue wrapper struct
///
/// This example shows how to use the ergonomic Queue wrapper that was
/// ported from switchboard-on-demand-client

#[cfg(feature = "client")]
use switchboard_on_demand::client::{CrossbarClient, Queue};
#[cfg(feature = "client")]
use switchboard_on_demand::RpcClient;

#[cfg(feature = "client")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create RPC client
    let rpc_url = std::env::var("RPC_URL")
        .unwrap_or_else(|_| "https://api.mainnet-beta.solana.com".to_string());
    let client = RpcClient::new(rpc_url.clone());

    // Example 1: Use default mainnet queue
    let queue = Queue::default_mainnet(RpcClient::new(rpc_url.clone()))?;
    println!("Mainnet Queue: {}", queue.pubkey);

    // Example 2: Load queue data
    match queue.load_data().await {
        Ok(data) => {
            println!("Queue has {} oracles", data.oracle_keys_len);
            println!("Queue authority: {}", data.authority);
        }
        Err(e) => {
            eprintln!("Failed to load queue data: {}", e);
        }
    }

    // Example 3: Fetch gateway from crossbar (with automatic network detection)
    let crossbar = CrossbarClient::default();
    match queue.fetch_gateway_from_crossbar(&crossbar).await {
        Ok(gateway) => {
            println!("Fetched gateway from crossbar");

            // Test the gateway
            if gateway.test_gateway().await {
                println!("Gateway is reachable!");
            } else {
                println!("Gateway is not reachable");
            }
        }
        Err(e) => {
            eprintln!("Failed to fetch gateway: {}", e);
        }
    }

    // Example 4: Use QueueAccountData methods directly
    if let Ok(queue_data) = queue.load_data().await {
        // Fetch all gateways and test them
        match queue_data.fetch_gateways(&client).await {
            Ok(gateways) => {
                println!("Found {} reachable gateways", gateways.len());
            }
            Err(e) => {
                eprintln!("Failed to fetch gateways: {}", e);
            }
        }
    }

    Ok(())
}

#[cfg(not(feature = "client"))]
fn main() {
    eprintln!("This example requires the 'client' feature to be enabled.");
    eprintln!("Run with: cargo run --example queue_wrapper --features client");
}