use serde::{Deserialize, Serialize};
pub const IRIS_API: &str = "https://iris-api.circle.com";
pub const IRIS_API_SANDBOX: &str = "https://iris-api-sandbox.circle.com";
pub const ATTESTATION_PATH_V1: &str = "/v1/attestations/";
pub const MESSAGES_PATH_V2: &str = "/v2/messages/";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct PollingConfig {
pub max_attempts: u32,
pub poll_interval_secs: u64,
}
impl Default for PollingConfig {
fn default() -> Self {
Self {
max_attempts: 30,
poll_interval_secs: 60,
}
}
}
impl PollingConfig {
pub fn fast_transfer() -> Self {
Self {
max_attempts: 30,
poll_interval_secs: 5,
}
}
pub fn with_max_attempts(mut self, attempts: u32) -> Self {
self.max_attempts = attempts;
self
}
pub fn with_poll_interval_secs(mut self, secs: u64) -> Self {
self.poll_interval_secs = secs;
self
}
pub fn total_timeout_secs(&self) -> u64 {
u64::from(self.max_attempts) * self.poll_interval_secs
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = PollingConfig::default();
assert_eq!(config.max_attempts, 30);
assert_eq!(config.poll_interval_secs, 60);
assert_eq!(config.total_timeout_secs(), 1800); }
#[test]
fn test_fast_transfer_config() {
let config = PollingConfig::fast_transfer();
assert_eq!(config.max_attempts, 30);
assert_eq!(config.poll_interval_secs, 5);
assert_eq!(config.total_timeout_secs(), 150); }
#[test]
fn test_builder_methods() {
let config = PollingConfig::default()
.with_max_attempts(20)
.with_poll_interval_secs(30);
assert_eq!(config.max_attempts, 20);
assert_eq!(config.poll_interval_secs, 30);
assert_eq!(config.total_timeout_secs(), 600); }
#[test]
fn test_config_is_copy() {
let config = PollingConfig::default();
let copied = config;
assert_eq!(config, copied);
}
}