iota_indexer/models/
network_metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use diesel::{
6    prelude::*,
7    sql_types::{BigInt, Double, Float8},
8};
9use iota_json_rpc_types::NetworkMetrics;
10
11use crate::schema::epoch_peak_tps;
12
13#[derive(Clone, Debug, Queryable, Insertable)]
14#[diesel(table_name = epoch_peak_tps)]
15pub struct StoredEpochPeakTps {
16    pub epoch: i64,
17    pub peak_tps: f64,
18    pub peak_tps_30d: f64,
19}
20
21impl Default for StoredEpochPeakTps {
22    fn default() -> Self {
23        Self {
24            epoch: -1,
25            peak_tps: 0.0,
26            peak_tps_30d: 0.0,
27        }
28    }
29}
30
31#[derive(QueryableByName, Debug, Clone, Default)]
32pub struct StoredNetworkMetrics {
33    #[diesel(sql_type = Double)]
34    pub current_tps: f64,
35    #[diesel(sql_type = Double)]
36    pub tps_30_days: f64,
37    #[diesel(sql_type = BigInt)]
38    pub total_packages: i64,
39    #[diesel(sql_type = BigInt)]
40    pub total_addresses: i64,
41    #[diesel(sql_type = BigInt)]
42    pub total_objects: i64,
43    #[diesel(sql_type = BigInt)]
44    pub current_epoch: i64,
45    #[diesel(sql_type = BigInt)]
46    pub current_checkpoint: i64,
47}
48
49impl From<StoredNetworkMetrics> for NetworkMetrics {
50    fn from(db: StoredNetworkMetrics) -> Self {
51        Self {
52            current_tps: db.current_tps,
53            tps_30_days: db.tps_30_days,
54            total_packages: db.total_packages as u64,
55            total_addresses: db.total_addresses as u64,
56            total_objects: db.total_objects as u64,
57            current_epoch: db.current_epoch as u64,
58            current_checkpoint: db.current_checkpoint as u64,
59        }
60    }
61}
62
63#[derive(Debug, QueryableByName)]
64pub struct Tps {
65    #[diesel(sql_type = Float8)]
66    pub peak_tps: f64,
67}