koios_sdk/models/
account.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct AccountList {
5    pub stake_address: String,
6    pub stake_address_hex: String,
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub script_hash: Option<String>,
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct AccountInfo {
13    pub stake_address: String,
14    pub status: AccountStatus,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub delegated_drep: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub delegated_pool: Option<String>,
19    pub total_balance: String,
20    pub utxo: String,
21    pub rewards: String,
22    pub withdrawals: String,
23    pub rewards_available: String,
24    pub deposit: String,
25    pub reserves: String,
26    pub treasury: String,
27}
28
29#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
30#[serde(rename_all = "snake_case")]
31pub enum AccountStatus {
32    Registered,
33    NotRegistered,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct AccountRewards {
38    pub stake_address: String,
39    pub rewards: Vec<RewardInfo>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct RewardInfo {
44    pub earned_epoch: u64,
45    pub spendable_epoch: u64,
46    pub amount: String,
47    #[serde(rename = "type")]
48    pub reward_type: RewardType,
49    pub pool_id: Option<String>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
53#[serde(rename_all = "lowercase")]
54pub enum RewardType {
55    Member,
56    Leader,
57    Treasury,
58    Reserves,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct AccountUpdates {
63    pub stake_address: String,
64    pub updates: Vec<AccountUpdate>,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct AccountUpdate {
69    pub action_type: AccountActionType,
70    pub tx_hash: String,
71    pub epoch_no: u64,
72    pub epoch_slot: u64,
73    pub absolute_slot: u64,
74    pub block_time: u64,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
78#[serde(rename_all = "lowercase")]
79pub enum AccountActionType {
80    Registration,
81    Delegation,
82    Withdrawal,
83    Deregistration,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct AccountAddresses {
88    pub stake_address: String,
89    pub addresses: Vec<String>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct AccountAssets {
94    pub stake_address: String,
95    pub policy_id: String,
96    pub asset_name: String,
97    pub fingerprint: String,
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub decimals: Option<u64>,
100    pub quantity: String,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct AccountHistory {
105    pub stake_address: String,
106    pub history: Vec<AccountHistoryEntry>,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct AccountHistoryEntry {
111    pub pool_id: String,
112    pub epoch_no: u64,
113    pub active_stake: String,
114}
115
116// Implementation blocks
117impl AccountInfo {
118    pub fn new(
119        stake_address: String,
120        status: AccountStatus,
121        total_balance: String,
122        utxo: String,
123        rewards: String,
124        withdrawals: String,
125        rewards_available: String,
126        deposit: String,
127        reserves: String,
128        treasury: String,
129    ) -> Self {
130        Self {
131            stake_address,
132            status,
133            delegated_drep: None,
134            delegated_pool: None,
135            total_balance,
136            utxo,
137            rewards,
138            withdrawals,
139            rewards_available,
140            deposit,
141            reserves,
142            treasury,
143        }
144    }
145}