Skip to main content

ogmios_client/schema/
network.rs

1//! Network types for Cardano.
2
3use serde::{Deserialize, Serialize};
4use super::primitives::*;
5use super::era::Era;
6
7/// Cardano network names.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub enum Network {
11    Mainnet,
12    Preview,
13    Preprod,
14    #[serde(other)]
15    Other,
16}
17
18impl Network {
19    /// Get the network as a string.
20    pub fn as_str(&self) -> &'static str {
21        match self {
22            Network::Mainnet => "mainnet",
23            Network::Preview => "preview",
24            Network::Preprod => "preprod",
25            Network::Other => "unknown",
26        }
27    }
28}
29
30impl std::fmt::Display for Network {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "{}", self.as_str())
33    }
34}
35
36/// Server health information.
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct ServerHealth {
40    /// Current era.
41    pub current_era: Era,
42    /// Last known tip.
43    pub last_known_tip: Tip,
44    /// Last tip update time.
45    #[serde(default)]
46    pub last_tip_update: Option<UtcTime>,
47    /// Server metrics.
48    pub metrics: ServerMetrics,
49    /// Server start time.
50    pub start_time: UtcTime,
51    /// Network name.
52    pub network: Network,
53    /// Network synchronization percentage (0.0 to 1.0).
54    pub network_synchronization: f64,
55    /// Server version.
56    pub version: String,
57}
58
59/// Server metrics.
60#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
61#[serde(rename_all = "camelCase")]
62pub struct ServerMetrics {
63    /// Runtime statistics (optional).
64    #[serde(default)]
65    pub runtime_stats: Option<RuntimeStats>,
66    /// Session durations.
67    pub session_durations: SessionDurations,
68    /// Total connections since start.
69    pub total_connections: u64,
70    /// Total messages processed.
71    pub total_messages: u64,
72    /// Total unrouted messages.
73    pub total_unrouted: u64,
74    /// Currently active connections.
75    pub active_connections: u64,
76}
77
78/// Runtime statistics.
79#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct RuntimeStats {
82    /// GC CPU time in seconds.
83    #[serde(default)]
84    pub gc_cpu_time: Option<f64>,
85    /// CPU time in seconds.
86    #[serde(default)]
87    pub cpu_time: Option<f64>,
88    /// Maximum heap size in bytes.
89    #[serde(default)]
90    pub max_heap_size: Option<u64>,
91    /// Current heap size in bytes.
92    #[serde(default)]
93    pub current_heap_size: Option<u64>,
94}
95
96/// Session duration statistics.
97#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
98#[serde(rename_all = "camelCase")]
99pub struct SessionDurations {
100    /// Maximum session duration.
101    pub max: f64,
102    /// Mean session duration.
103    pub mean: f64,
104    /// Minimum session duration.
105    pub min: f64,
106}
107
108/// Mempool size and capacity.
109#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
110#[serde(rename_all = "camelCase")]
111pub struct MempoolSizeAndCapacity {
112    /// Current number of bytes in the mempool.
113    pub bytes: NumberOfBytes,
114    /// Current number of transactions in the mempool.
115    pub transactions: u64,
116    /// Maximum capacity in bytes.
117    pub max_bytes: NumberOfBytes,
118    /// Maximum number of transactions.
119    pub max_transactions: u64,
120}
121
122/// Reward account summaries.
123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
124#[serde(rename_all = "camelCase")]
125pub struct RewardAccountSummary {
126    /// Reward account address.
127    pub address: RewardAccount,
128    /// Delegated stake pool (if any).
129    #[serde(default)]
130    pub delegate: Option<StakePoolId>,
131    /// Current rewards balance.
132    pub rewards: AdaValue,
133    /// Deposit amount.
134    pub deposit: AdaValue,
135}
136
137/// Live stake distribution entry.
138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
139#[serde(rename_all = "camelCase")]
140pub struct LiveStakeDistributionEntry {
141    /// Stake pool ID.
142    pub stake_pool: StakePoolId,
143    /// Total stake delegated.
144    pub stake: AdaValue,
145}
146
147/// Projected rewards.
148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct ProjectedRewards {
151    /// Stake address.
152    pub address: StakeAddress,
153    /// Projected rewards.
154    pub rewards: AdaValue,
155}