1use serde::{Deserialize, Serialize};
2
3use crate::Currency;
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
8pub enum SyncStatus {
9 Connecting,
10 Listening,
11 Offline,
12 Bootstrap,
13 Synced,
14 Catchup,
15}
16
17impl std::fmt::Display for SyncStatus {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Self::Connecting => write!(f, "CONNECTING"),
21 Self::Listening => write!(f, "LISTENING"),
22 Self::Offline => write!(f, "OFFLINE"),
23 Self::Bootstrap => write!(f, "BOOTSTRAP"),
24 Self::Synced => write!(f, "SYNCED"),
25 Self::Catchup => write!(f, "CATCHUP"),
26 }
27 }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct PeerInfo {
33 pub peer_id: String,
34 pub host: String,
35 pub port: i64,
36}
37
38#[derive(Debug, Clone)]
40pub struct DaemonStatus {
41 pub sync_status: SyncStatus,
42 pub blockchain_length: Option<i64>,
43 pub highest_block_length_received: Option<i64>,
44 pub uptime_secs: Option<i64>,
45 pub state_hash: Option<String>,
46 pub commit_id: Option<String>,
47 pub peers: Option<Vec<PeerInfo>>,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct AccountBalance {
53 pub total: Currency,
54 pub liquid: Option<Currency>,
55 pub locked: Option<Currency>,
56}
57
58#[derive(Debug, Clone)]
60pub struct AccountData {
61 pub public_key: String,
62 pub nonce: u64,
63 pub balance: AccountBalance,
64 pub delegate: Option<String>,
65 pub token_id: Option<String>,
66}
67
68#[derive(Debug, Clone)]
70pub struct BlockInfo {
71 pub state_hash: String,
72 pub height: u64,
73 pub global_slot_since_hard_fork: u64,
74 pub global_slot_since_genesis: u64,
75 pub creator_pk: String,
76 pub command_transaction_count: i64,
77}
78
79#[derive(Debug, Clone, PartialEq, Eq)]
81pub struct SendPaymentResult {
82 pub id: String,
83 pub hash: String,
84 pub nonce: u64,
85}
86
87#[derive(Debug, Clone, PartialEq, Eq)]
89pub struct SendDelegationResult {
90 pub id: String,
91 pub hash: String,
92 pub nonce: u64,
93}
94
95#[derive(Debug, Clone)]
110pub struct Payment {
111 pub sender: String,
112 pub receiver: String,
113 pub amount: Currency,
114 pub fee: Currency,
115 pub memo: Option<String>,
116 pub nonce: Option<u64>,
117}
118
119impl Payment {
120 pub fn sender(sender: &str) -> Self {
122 Self {
123 sender: sender.to_string(),
124 receiver: String::new(),
125 amount: Currency::from_nanomina(0),
126 fee: Currency::from_nanomina(0),
127 memo: None,
128 nonce: None,
129 }
130 }
131
132 pub fn to(mut self, receiver: &str) -> Self {
134 self.receiver = receiver.to_string();
135 self
136 }
137
138 pub fn amount(mut self, amount: Currency) -> Self {
140 self.amount = amount;
141 self
142 }
143
144 pub fn fee(mut self, fee: Currency) -> Self {
146 self.fee = fee;
147 self
148 }
149
150 pub fn memo(mut self, memo: &str) -> Self {
152 self.memo = Some(memo.to_string());
153 self
154 }
155
156 pub fn nonce(mut self, nonce: u64) -> Self {
158 self.nonce = Some(nonce);
159 self
160 }
161}
162
163#[derive(Debug, Clone)]
174pub struct Delegation {
175 pub sender: String,
176 pub delegate_to: String,
177 pub fee: Currency,
178 pub memo: Option<String>,
179 pub nonce: Option<u64>,
180}
181
182impl Delegation {
183 pub fn sender(sender: &str) -> Self {
185 Self {
186 sender: sender.to_string(),
187 delegate_to: String::new(),
188 fee: Currency::from_nanomina(0),
189 memo: None,
190 nonce: None,
191 }
192 }
193
194 pub fn to(mut self, delegate_to: &str) -> Self {
196 self.delegate_to = delegate_to.to_string();
197 self
198 }
199
200 pub fn fee(mut self, fee: Currency) -> Self {
202 self.fee = fee;
203 self
204 }
205
206 pub fn memo(mut self, memo: &str) -> Self {
208 self.memo = Some(memo.to_string());
209 self
210 }
211
212 pub fn nonce(mut self, nonce: u64) -> Self {
214 self.nonce = Some(nonce);
215 self
216 }
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct PooledUserCommand {
222 pub id: String,
223 pub hash: String,
224 pub kind: String,
225 pub nonce: String,
226 pub amount: String,
227 pub fee: String,
228 pub from: String,
229 pub to: String,
230}