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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Defines API schemas of stake amount type.

use poem_openapi::{types::Example, Object};

use crate::service::{
    api::cardano::types::{SlotNumber, StakeAmount},
    common::types::cardano::{
        asset_name::AssetName, asset_value::AssetValue, hash28::HexEncodedHash28,
    },
};

/// User's staked native token info.
#[derive(Object)]
pub(crate) struct StakedNativeTokenInfo {
    /// Token policy hash.
    pub(crate) policy_hash: HexEncodedHash28,
    /// Token policies Asset Name.
    pub(crate) asset_name: AssetName,
    /// Token Asset Value.
    pub(crate) amount: AssetValue,
}

/// User's cardano stake info.
#[derive(Object, Default)]
#[oai(example = true)]
pub(crate) struct StakeInfo {
    /// Total stake amount.
    // TODO(bkioshn): https://github.com/input-output-hk/catalyst-voices/issues/239
    #[oai(validator(minimum(value = "0"), maximum(value = "9223372036854775807")))]
    pub(crate) ada_amount: StakeAmount,

    /// Block's slot number which contains the latest unspent UTXO.
    // TODO(bkioshn): https://github.com/input-output-hk/catalyst-voices/issues/239
    #[oai(validator(minimum(value = "0"), maximum(value = "9223372036854775807")))]
    pub(crate) slot_number: SlotNumber,

    /// Native token infos.
    #[oai(validator(max_items = "1000"))]
    pub(crate) native_tokens: Vec<StakedNativeTokenInfo>,
}

impl Example for StakeInfo {
    fn example() -> Self {
        Self {
            slot_number: 5,
            ada_amount: 1,
            native_tokens: Vec::new(),
        }
    }
}

/// Full user's cardano stake info.
#[derive(Object, Default)]
#[oai(example = true)]
pub(crate) struct FullStakeInfo {
    /// Volatile stake information.
    pub(crate) volatile: StakeInfo,
    /// Persistent stake information.
    pub(crate) persistent: StakeInfo,
}

impl Example for FullStakeInfo {
    fn example() -> Self {
        Self {
            volatile: StakeInfo::example(),
            persistent: StakeInfo::example(),
        }
    }
}