1use serde::{Deserialize, Serialize};
2use solana_commitment_config::CommitmentConfig;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ProviderConfig {
7 pub name: String,
9 pub rpc_url: String,
11 pub rate_limit: u32,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct RpcClientConfig {
18 pub providers: Vec<ProviderConfig>,
20
21 #[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}