Skip to main content

sol_rpc_router/
config.rs

1use serde::{Deserialize, Serialize};
2use solana_commitment_config::CommitmentConfig;
3
4/// Configuration for an individual RPC provider
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ProviderConfig {
7    /// Name of the provider
8    pub name: String,
9    /// URL of the RPC endpoint
10    pub rpc_url: String,
11    /// Rate limit (requests per second)
12    pub rate_limit: u32,
13}
14
15/// Configuration for the RPC client
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct RpcClientConfig {
18    /// List of available providers
19    pub providers: Vec<ProviderConfig>,
20
21    /// Commitment configuration for the RPC client
22    #[serde(flatten)]
23    pub commitment: CommitmentConfig,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[tokio::test]
31    async fn test_config_loading() {
32        let config_str = r#"
33        {
34            "commitment": "confirmed",
35            "providers": [
36                {
37                    "name": "provider1",
38                    "rpc_url": "https://provider1.com",
39                    "rate_limit": 1000
40                },
41                {
42                    "name": "provider2",
43                    "rpc_url": "https://provider2.com",
44                    "rate_limit": 500
45                }
46            ]
47        }"#;
48
49        let config: RpcClientConfig = serde_json::de::from_str(config_str).unwrap();
50        assert_eq!(config.providers.len(), 2);
51        assert_eq!(config.providers[0].name, "provider1");
52        assert_eq!(config.providers[1].rate_limit, 500);
53    }
54}