sol-rpc-router 0.2.0

Solana RPC Router that splits requests across multiple providers
Documentation
use serde::{Deserialize, Serialize};
use solana_commitment_config::CommitmentConfig;

/// Configuration for an individual RPC provider
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProviderConfig {
    /// Name of the provider
    pub name: String,
    /// URL of the RPC endpoint
    pub rpc_url: String,
    /// Rate limit (requests per second)
    pub rate_limit: u32,
}

/// Configuration for the RPC client
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RpcClientConfig {
    /// List of available providers
    pub providers: Vec<ProviderConfig>,

    /// Commitment configuration for the RPC client
    #[serde(flatten)]
    pub commitment: CommitmentConfig,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_config_loading() {
        let config_str = r#"
        {
            "commitment": "confirmed",
            "providers": [
                {
                    "name": "provider1",
                    "rpc_url": "https://provider1.com",
                    "rate_limit": 1000
                },
                {
                    "name": "provider2",
                    "rpc_url": "https://provider2.com",
                    "rate_limit": 500
                }
            ]
        }"#;

        let config: RpcClientConfig = serde_json::de::from_str(config_str).unwrap();
        assert_eq!(config.providers.len(), 2);
        assert_eq!(config.providers[0].name, "provider1");
        assert_eq!(config.providers[1].rate_limit, 500);
    }
}