nym_api_requests/models/
api_status.rs

1// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5use std::time::Duration;
6use utoipa::ToSchema;
7
8#[derive(Clone, Copy, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
9pub struct ApiHealthResponse {
10    pub status: ApiStatus,
11    #[serde(default)]
12    pub chain_status: ChainStatus,
13    pub uptime: u64,
14}
15
16#[derive(Clone, Copy, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
17#[serde(rename_all = "lowercase")]
18pub enum ApiStatus {
19    Up,
20}
21
22#[derive(Clone, Copy, Debug, Serialize, Deserialize, Default, schemars::JsonSchema, ToSchema)]
23#[serde(rename_all = "snake_case")]
24pub enum ChainStatus {
25    Synced,
26    #[default]
27    Unknown,
28    Stalled {
29        #[serde(
30            serialize_with = "humantime_serde::serialize",
31            deserialize_with = "humantime_serde::deserialize"
32        )]
33        approximate_amount: Duration,
34    },
35}
36
37impl ChainStatus {
38    pub fn is_synced(&self) -> bool {
39        matches!(self, ChainStatus::Synced)
40    }
41}
42
43impl ApiHealthResponse {
44    pub fn new_healthy(uptime: Duration) -> Self {
45        ApiHealthResponse {
46            status: ApiStatus::Up,
47            chain_status: ChainStatus::Synced,
48            uptime: uptime.as_secs(),
49        }
50    }
51}
52
53impl ApiStatus {
54    pub fn is_up(&self) -> bool {
55        matches!(self, ApiStatus::Up)
56    }
57}
58
59#[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema, ToSchema)]
60pub struct SignerInformationResponse {
61    pub cosmos_address: String,
62
63    pub identity: String,
64
65    pub announce_address: String,
66
67    pub verification_key: Option<String>,
68}