cat_gateway/service/common/objects/cardano/
stake_info.rs

1//! Defines API schemas of stake amount type.
2
3use derive_more::{From, Into};
4use poem_openapi::{
5    types::{Example, ToJSON},
6    NewType, Object,
7};
8
9use crate::service::common::types::{
10    array_types::impl_array_types,
11    cardano::{
12        ada_value::AdaValue, asset_name::AssetName, asset_value::AssetValue,
13        hash28::HexEncodedHash28, slot_no::SlotNo,
14    },
15};
16
17/// User's staked native token info.
18#[derive(Object, Debug, Clone)]
19#[oai(example)]
20pub(crate) struct StakedNativeTokenInfo {
21    /// Token policy hash.
22    pub(crate) policy_hash: HexEncodedHash28,
23    /// Token policies Asset Name.
24    pub(crate) asset_name: AssetName,
25    /// Token Asset Value.
26    pub(crate) amount: AssetValue,
27}
28
29impl Example for StakedNativeTokenInfo {
30    fn example() -> Self {
31        Self {
32            policy_hash: Example::example(),
33            asset_name: Example::example(),
34            amount: Example::example(),
35        }
36    }
37}
38
39// List of User's Staked Native Token Info
40impl_array_types!(
41    StakedNativeTokenInfoList,
42    StakedNativeTokenInfo,
43    Some(poem_openapi::registry::MetaSchema {
44        example: Self::example().to_json(),
45        max_items: Some(1000),
46        items: Some(Box::new(StakedNativeTokenInfo::schema_ref())),
47        ..poem_openapi::registry::MetaSchema::ANY
48    })
49);
50
51impl Example for StakedNativeTokenInfoList {
52    fn example() -> Self {
53        Self(vec![Example::example()])
54    }
55}
56
57/// User's cardano stake info.
58#[derive(Object, Default)]
59#[oai(example = true)]
60pub(crate) struct StakeInfo {
61    /// Total stake amount.
62    pub(crate) ada_amount: AdaValue,
63
64    /// Block's slot number which contains the latest unspent UTXO.
65    pub(crate) slot_number: SlotNo,
66
67    /// Native token infos.
68    pub(crate) native_tokens: StakedNativeTokenInfoList,
69}
70
71impl Example for StakeInfo {
72    fn example() -> Self {
73        Self {
74            slot_number: SlotNo::example(),
75            ada_amount: AdaValue::example(),
76            native_tokens: Vec::new().into(),
77        }
78    }
79}
80
81/// Volatile stake information.
82#[derive(NewType, Default, From, Into)]
83#[oai(
84    from_multipart = false,
85    from_parameter = false,
86    to_header = false,
87    example = true
88)]
89pub(crate) struct VolatileStakeInfo(StakeInfo);
90
91impl Example for VolatileStakeInfo {
92    fn example() -> Self {
93        Self(Example::example())
94    }
95}
96
97/// Persistent stake information.
98#[derive(NewType, Default, From, Into)]
99#[oai(
100    from_multipart = false,
101    from_parameter = false,
102    to_header = false,
103    example = true
104)]
105pub(crate) struct PersistentStakeInfo(StakeInfo);
106
107impl Example for PersistentStakeInfo {
108    fn example() -> Self {
109        Self(Example::example())
110    }
111}
112
113/// Full user's cardano stake info.
114#[derive(Object, Default)]
115#[oai(example = true)]
116pub(crate) struct FullStakeInfo {
117    /// Volatile stake information.
118    pub(crate) volatile: VolatileStakeInfo,
119    /// Persistent stake information.
120    pub(crate) persistent: PersistentStakeInfo,
121}
122
123impl Example for FullStakeInfo {
124    fn example() -> Self {
125        Self {
126            volatile: Example::example(),
127            persistent: Example::example(),
128        }
129    }
130}