cat_gateway/service/common/objects/cardano/
slot_info.rs1use std::str::FromStr;
4
5use derive_more::{From, Into};
6use poem_openapi::{types::Example, NewType, Object};
7
8use crate::service::common::{
9 objects::cardano::hash::Hash256,
10 types::{cardano::slot_no::SlotNo, generic::date_time::DateTime},
11};
12
13#[derive(Object)]
15#[oai(example = true)]
16#[allow(clippy::struct_field_names)]
17pub(crate) struct Slot {
18 pub(crate) slot_number: SlotNo,
20
21 pub(crate) block_hash: Hash256,
23
24 pub(crate) block_time: DateTime,
26}
27
28impl Example for Slot {
29 fn example() -> Self {
30 Self {
31 slot_number: SlotNo::example(),
32 block_hash: Hash256::example(),
33 block_time: DateTime::example(),
34 }
35 }
36}
37
38#[derive(NewType, From, Into)]
40#[oai(
41 from_multipart = false,
42 from_parameter = false,
43 to_header = false,
44 example = true
45)]
46pub(crate) struct PreviousSlot(Slot);
47
48impl Example for PreviousSlot {
49 #[allow(clippy::expect_used)]
50 fn example() -> Self {
51 Self(Slot {
52 slot_number: 121_099_406u64.try_into().unwrap_or_default(),
53 block_hash: FromStr::from_str(
54 "0x162ae0e2d08dd238233308eef328bf39ba529b82bc0b87c4eeea3c1dae4fc877",
55 )
56 .expect("Invalid hex"),
57 block_time: chrono::DateTime::from_timestamp(1_712_676_497, 0)
58 .expect("Invalid timestamp")
59 .into(),
60 })
61 }
62}
63
64#[derive(NewType, From, Into)]
66#[oai(
67 from_multipart = false,
68 from_parameter = false,
69 to_header = false,
70 example = true
71)]
72pub(crate) struct CurrentSlot(Slot);
73
74impl Example for CurrentSlot {
75 #[allow(clippy::expect_used)]
76 fn example() -> Self {
77 Self(Slot {
78 slot_number: 121_099_409u64.try_into().unwrap_or_default(),
79 block_hash: FromStr::from_str(
80 "0xaa34657bf91e04eb5b506d76a66f688dbfbc509dbf70bc38124d4e8832fdd68a",
81 )
82 .expect("Invalid hex"),
83 block_time: chrono::DateTime::from_timestamp(1_712_676_501, 0)
84 .expect("Invalid timestamp")
85 .into(),
86 })
87 }
88}
89
90#[derive(NewType, From, Into)]
92#[oai(
93 from_multipart = false,
94 from_parameter = false,
95 to_header = false,
96 example = true
97)]
98pub(crate) struct NextSlot(Slot);
99
100impl Example for NextSlot {
101 #[allow(clippy::expect_used)]
102 fn example() -> Self {
103 Self(Slot {
104 slot_number: 121_099_422u64.try_into().unwrap_or_default(),
105 block_hash: FromStr::from_str(
106 "0x83ad63288ae14e75de1a1f794bda5d317fa59cbdbf1cc4dc83471d76555a5e89",
107 )
108 .expect("Invalid hex"),
109 block_time: chrono::DateTime::from_timestamp(1_712_676_513, 0)
110 .expect("Invalid timestamp")
111 .into(),
112 })
113 }
114}
115
116#[derive(Object)]
118#[oai(example = true)]
119pub(crate) struct SlotInfo {
120 #[oai(skip_serializing_if_is_none)]
122 pub(crate) previous: Option<PreviousSlot>,
123
124 #[oai(skip_serializing_if_is_none)]
126 pub(crate) current: Option<CurrentSlot>,
127
128 #[oai(skip_serializing_if_is_none)]
130 pub(crate) next: Option<NextSlot>,
131}
132
133impl Example for SlotInfo {
134 fn example() -> Self {
135 Self {
136 previous: Some(Example::example()),
137 current: Some(Example::example()),
138 next: Some(Example::example()),
139 }
140 }
141}