magic_resolver/
config.rs

1//! Configuration used by various modules of router
2
3use std::time::Duration;
4
5use json::Deserialize;
6pub use sdk::commitment_config::CommitmentLevel;
7use serde::{de::Error, Deserializer};
8use url::Url;
9
10/// General router configuration
11#[derive(Deserialize)]
12pub struct Configuration {
13    /// configuration of client connections to base chain
14    pub chain: Url,
15    /// websocket connection pool configuration
16    pub websocket: WebsocketConf,
17    /// number of entries the delegations cache can hold
18    /// this can be used to restrict memory usage by resolver
19    /// so that it doesn't keep unecesary accounts around
20    pub cache_size: usize,
21    /// default commitment level to be used with rpc clients
22    pub commitment: CommitmentLevel,
23}
24
25/// Configuration for the WebSocket connection.
26#[derive(Deserialize)]
27#[serde(rename_all = "kebab-case")]
28pub struct WebsocketConf {
29    /// The WebSocket endpoint URL.
30    pub url: Url,
31    /// The interval at which ping messages are sent to keep the connection alive.
32    #[serde(deserialize_with = "deserialize_duration")]
33    pub ping_interval: Duration,
34}
35
36/// Deserialize std::time::Duration from human readable string
37pub fn deserialize_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>
38where
39    D: Deserializer<'de>,
40{
41    let string = String::deserialize(deserializer)?;
42    humantime::parse_duration(&string).map_err(D::Error::custom)
43}