blockfrost/
settings.rs

1use std::{collections::HashMap, time::Duration};
2
3#[derive(Debug, Clone)]
4#[non_exhaustive]
5pub struct BlockFrostSettings {
6    pub base_url: Option<String>,
7    pub retry_settings: RetrySettings,
8    pub headers: HashMap<String, String>,
9}
10
11impl BlockFrostSettings {
12    pub fn new() -> Self {
13        Self {
14            base_url: None,
15            retry_settings: RetrySettings::default(),
16            headers: HashMap::new(),
17        }
18    }
19}
20
21#[derive(Debug, Clone)]
22#[non_exhaustive]
23pub struct IpfsSettings {
24    pub retry_settings: RetrySettings,
25    pub headers: HashMap<String, String>,
26}
27
28impl IpfsSettings {
29    /// Create a customizable [`IpfsSettings`].
30    ///
31    /// # Default settings:
32    ///
33    /// - Network: [`IPFS_NETWORK`].
34    /// - Query parameters: empty.
35    /// - Retry settings: disabled.
36    pub fn new() -> Self {
37        Self {
38            retry_settings: RetrySettings::default(),
39            headers: HashMap::new(),
40        }
41    }
42}
43
44/// Uses the default network [`CARDANO_MAINNET_NETWORK`].
45impl Default for BlockFrostSettings {
46    fn default() -> Self {
47        Self::new()
48    }
49}
50
51/// Uses the default network [`IPFS_NETWORK`].
52impl Default for IpfsSettings {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58/// Settings for retrying when API rate limit is reached.
59///
60/// Amount and delay are set to zero by default, you will need to change both to enable retrying.
61///
62/// Check different BlockFrost plans and their limits at <https://blockfrost.io/#pricing>.
63///
64/// Note: You can disable delay between retries with [`Duration::ZERO`].
65#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
66pub struct RetrySettings {
67    pub amount: u64,
68    pub delay: Duration,
69}
70
71impl RetrySettings {
72    /// Create a new `RetrySettings`, with retry amount and delay.
73    pub fn new(amount: u64, delay: Duration) -> Self {
74        Self { amount, delay }
75    }
76}